Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:return: raw response
:rtype: response.RawResponse
"""
rs = app(context, data=data, loop=loop)
if isinstance(rs, response.RawResponse):
return rs
elif isinstance(rs, types.CoroutineType):
return loop.run_until_complete(rs)
elif isinstance(rs, str):
hs = headers.GoLikeHeaders({})
hs.set('content-type', 'text/plain')
return response.RawResponse(context, response_data=rs)
elif isinstance(rs, bytes):
hs = headers.GoLikeHeaders({})
hs.set('content-type', 'application/octet-stream')
return response.RawResponse(
context,
response_data=rs.decode("utf8"),
headers=hs,
status_code=200
)
else:
hs = headers.GoLikeHeaders({})
hs.set('content-type', 'application/json')
return response.RawResponse(
context,
response_data=ujson.dumps(rs),
headers=hs,
status_code=200,
)
def normal_dispatch(app, context, data=None, loop=None):
"""
Request handler app dispatcher
:param app: request handler app
:type app: types.Callable
:param context: request context
:type context: request.RequestContext
:param data: request body
:type data: io.BufferedIOBase
:param loop: asyncio event loop
:type loop: asyncio.AbstractEventLoop
:return: raw response
:rtype: response.RawResponse
"""
rs = app(context, data=data, loop=loop)
if isinstance(rs, response.RawResponse):
return rs
elif isinstance(rs, types.CoroutineType):
return loop.run_until_complete(rs)
elif isinstance(rs, str):
return response.RawResponse(
context,
status_code=200,
headers={},
response_data=rs)
elif isinstance(rs, bytes):
return response.RawResponse(
context,
status_code=200,
headers={'content-type': 'application/octet-stream'},
response_data=rs.decode("utf8"))
else:
@response.safe
def normal_dispatch(app, context, data=None, loop=None):
"""
Request handler app dispatcher
:param app: request handler app
:type app: types.Callable
:param context: request context
:type context: request.RequestContext
:param data: request body
:type data: io.BufferedIOBase
:param loop: asyncio event loop
:type loop: asyncio.AbstractEventLoop
:return: raw response
:rtype: response.RawResponse
"""
rs = app(context, data=data, loop=loop)
if isinstance(rs, response.RawResponse):
:return: raw response
:rtype: response.RawResponse
"""
rs = app(context, data=data, loop=loop)
if isinstance(rs, response.RawResponse):
return rs
elif isinstance(rs, types.CoroutineType):
return loop.run_until_complete(rs)
elif isinstance(rs, str):
return response.RawResponse(
context,
status_code=200,
headers={},
response_data=rs)
elif isinstance(rs, bytes):
return response.RawResponse(
context,
status_code=200,
headers={'content-type': 'application/octet-stream'},
response_data=rs.decode("utf8"))
else:
return response.RawResponse(
context,
status_code=200,
headers={'content-type': 'application/json'},
response_data=ujson.dumps(rs))