aiohttp.web.UrlDispatcher

Here are the examples of the python api aiohttp.web.UrlDispatcher taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: aiohttp-cors Source File: cors_config.py
Function: init
    def __init__(self, app: web.Application, *,
                 defaults: _ConfigType=None,
                 router_adapter: AbstractRouterAdapter=None):
        """Construct CORS configuration.

        :param app:
            Application for which CORS configuration is built.
        :param defaults:
            Default CORS settings for origins.
        :param router_adapter:
            Router adapter. Required if application uses non-default router.
        """

        defaults = _parse_config_options(defaults)

        self._cors_impl = None

        self._resources_router_adapter = None
        self._resources_cors_impl = None

        self._old_routes_cors_impl = None

        if router_adapter is not None:
            self._cors_impl = _CorsConfigImpl(app, router_adapter)

        elif isinstance(app.router, web.UrlDispatcher):
            self._resources_router_adapter = \
                ResourcesUrlDispatcherRouterAdapter(app.router, defaults)
            self._resources_cors_impl = _CorsConfigImpl(
                app,
                self._resources_router_adapter)
            self._old_routes_cors_impl = _CorsConfigImpl(
                app,
                OldRoutesUrlDispatcherRouterAdapter(app.router, defaults))
        else:
            raise RuntimeError(
                "Router adapter is not specified. "
                "Routers other than aiohttp.web.UrlDispatcher requires"
                "custom router adapter.")

Example 2

Project: muffin Source File: urls.py
Function: init
    def __init__(self, path, *, name=None):
        super().__init__(name=name)
        self._path = path.rstrip('/')
        self.router = UrlDispatcher()