Пример #1
0
async def wait_for_body_middleware(environ, start_response=None):
    '''Use this middleware to wait for the full body.

    This middleware wait for the full body to be received before letting
    other middleware to be processed.

    Useful when using synchronous web-frameworks such as :django:`django <>`.
    '''
    if environ['wsgi.input']:
        chunk = await as_coroutine(environ['wsgi.input'].read())
        environ['wsgi.input'] = BytesIO(chunk)
Пример #2
0
def wait_for_body_middleware(environ, start_response=None):
    '''Use this middleware to wait for the full body.

    This middleware wait for the full body to be received before letting
    other middleware to be processed.

    Useful when using synchronous web-frameworks such as :django:`django <>`.
    '''
    if environ['wsgi.input']:
        stream = environ['wsgi.input']
        chunk = stream.read()
        if is_async(chunk):
            chunk = yield from chunk
        environ['wsgi.input'] = BytesIO(chunk)
Пример #3
0
 def compress_string(self, s):
     zbuf = BytesIO()
     zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
     zfile.write(s)
     zfile.close()
     return zbuf.getvalue()
Пример #4
0
 def compress_string(self, s):
     zbuf = BytesIO()
     zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
     zfile.write(s)
     zfile.close()
     return zbuf.getvalue()
Пример #5
0
 def _wsgi_input(value):
     environ['wsgi.input'] = BytesIO(value)
Пример #6
0
def _wait_for_body_middleware(environ, start_response):
    stream = environ['wsgi.input']
    chunk = yield stream.read()
    environ['wsgi.input'] = BytesIO(chunk)
    coroutine_return(None)