diff --git a/aiohttp_cors/cors_config.py b/aiohttp_cors/cors_config.py index 0e811ff..1aed1e8 100644 --- a/aiohttp_cors/cors_config.py +++ b/aiohttp_cors/cors_config.py @@ -164,11 +164,16 @@ def add(self, :return: ``route``. """ - if _AIOHTTP_0_21 and isinstance(route, web.AbstractResource): - # TODO: Resources should be supported. - raise RuntimeError( - "You need to pass Route to the CORS config, and you passed " - "Resource.") + if _AIOHTTP_0_21: + # TODO: Use web.AbstractResource when this issue will be fixed: + # + from aiohttp.web_urldispatcher import AbstractResource + + if isinstance(route, AbstractResource): + # TODO: Resources should be supported. + raise RuntimeError( + "You need to pass Route to the CORS config, and you " + "passed Resource.") if route in self._preflight_route_settings: _logger.warning( diff --git a/aiohttp_cors/urldispatcher_router_adapter.py b/aiohttp_cors/urldispatcher_router_adapter.py index 229b004..5cca64a 100644 --- a/aiohttp_cors/urldispatcher_router_adapter.py +++ b/aiohttp_cors/urldispatcher_router_adapter.py @@ -70,14 +70,18 @@ class _UrlDispatcherRouterAdapter_v21(AbstractRouterAdapter): def __init__(self, router: web.UrlDispatcher): self._router = router - def route_methods(self, route: web.AbstractRoute): + def route_methods(self, route): """Returns list of HTTP methods that route handles""" return [route.method] - def add_options_method_handler(self, route: web.AbstractRoute, handler): + def add_options_method_handler(self, route, handler): method = "OPTIONS" - if isinstance(route, web.ResourceRoute): + # TODO: Use web.ResourceRoute when this issue will be fixed: + # + from aiohttp.web_urldispatcher import ResourceRoute + + if isinstance(route, ResourceRoute): # Route added through Resource API. new_route = route.resource.add_route(method, handler)