Here are the examples of the python api aiohttp.web.AbstractRoute taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
0
Example 1
def add_preflight_handler(
self,
route: web.AbstractRoute,
handler):
"""Add OPTIONS handler for same paths that `route` handles."""
assert isinstance(route, web.AbstractRoute)
if isinstance(route, web.ResourceRoute):
# New-style route (which Resource is not used explicitly,
# otherwise it would be handled by other adapter).
preflight_route = route.resource.add_route(
hdrs.METH_OPTIONS, handler)
elif isinstance(route, web.Route):
# Old-style route.
if isinstance(route, web.StaticRoute):
# TODO: Use custom matches that uses `str.startswith()`
# if regexp performance is not enough.
pattern = re.compile("^" + re.escape(route._prefix))
preflight_route = web.DynamicRoute(
hdrs.METH_OPTIONS, handler, None, pattern, "")
self._router.register_route(preflight_route)
elif isinstance(route, web.PlainRoute):
# May occur only if user manually creates PlainRoute.
preflight_route = self._router.add_route(
hdrs.METH_OPTIONS, route._path, handler)
elif isinstance(route, web.DynamicRoute):
# May occur only if user manually creates DynamicRoute.
preflight_route = web.DynamicRoute(
hdrs.METH_OPTIONS, handler, None,
route._pattern, route._formatter)
self._router.register_route(preflight_route)
else:
raise RuntimeError(
"Unhandled deprecated route type {!r}".format(route))
else:
raise RuntimeError("Unhandled route type {!r}".format(route))
self._preflight_routes.add(preflight_route)
-1
Example 2
Project: aiohttp-cors Source File: urldispatcher_router_adapter.py
Function: set_config_for_routing_entity
Function: set_config_for_routing_entity
def set_config_for_routing_entity(
self,
route: web.AbstractRoute,
config):
"""Record CORS configuration for route."""
assert isinstance(route, web.AbstractRoute)
if any(options.allow_methods is not None
for options in config.values()):
raise ValueError(
"'allow_methods' parameter is not supported on old-style "
"routes. You specified {!r} for {!r}. "
"Use Resources to configure CORS.".format(
config, route))
if route in self._route_config:
raise ValueError(
"CORS is already configured for {!r} route.".format(
route))
self._route_config[route] = config