From c689f3b7c6624f07343e4243082ed3895a6546e4 Mon Sep 17 00:00:00 2001 From: Vladimir Rutsky Date: Fri, 5 Feb 2016 05:04:46 +0300 Subject: [PATCH] fix work with 0.21 without patching aiohttp Dependent aiohttp changes are here: . --- aiohttp_cors/cors_config.py | 15 ++++++++++----- aiohttp_cors/urldispatcher_router_adapter.py | 10 +++++++--- 2 files changed, 17 insertions(+), 8 deletions(-) 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)