示例#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)