Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def dispatch(self):
request, response = current.request, current.response
route, reqargs = self.match(request)
if not route:
raise HTTP(404, body="Resource not found\n")
request.name = route.name
http_cls, output = await route.dispatch(request, reqargs)
return http_cls(
response.status, output, response.headers, response.cookies)
async def dynamic_handler(self, scope, receive, send):
await self.app._router_ws.dispatch()
if current.websocket._accepted:
await send({'type': 'websocket.close', 'code': 1000})
except KeyError:
raise RuntimeError(f'invalid url("{path}",...)')
# handle classic urls
else:
builder = UrlBuilder([path])
# add language
lang = None
if current.app.language_force_on_url:
if language:
#: use the given language if is enabled in application
if language in current.app.languages:
lang = language
else:
#: try to use the request language if context exists
if hasattr(current, 'request'):
lang = current.request.language
if lang == current.app.language_default:
lang = None
# scheme=True means to use current scheme
if scheme is True:
if not hasattr(current, 'request'):
raise RuntimeError(
f'cannot build url("{path}",...) without current request'
)
scheme = self.http_to_ws_schemes[current.request.scheme]
# add scheme and host
if scheme:
if host is None:
if not hasattr(current, 'request'):
raise RuntimeError(
f'cannot build url("{path}",...) '
'without current request'
def redirect(location, status_code=303):
current.response.status = status_code
raise HTTPRedirect(status_code, location)