Skip to content

Commit

Permalink
fix work with 0.21 without patching aiohttp
Browse files Browse the repository at this point in the history
Dependent aiohttp changes are here:
<aio-libs/aiohttp#767>.
  • Loading branch information
rutsky committed Mar 28, 2016
1 parent c05f131 commit c689f3b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 10 additions & 5 deletions aiohttp_cors/cors_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# <https://github.com/KeepSafe/aiohttp/pull/767>
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(
Expand Down
10 changes: 7 additions & 3 deletions aiohttp_cors/urldispatcher_router_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# <https://github.com/KeepSafe/aiohttp/pull/767>
from aiohttp.web_urldispatcher import ResourceRoute

if isinstance(route, ResourceRoute):
# Route added through Resource API.
new_route = route.resource.add_route(method, handler)

Expand Down

0 comments on commit c689f3b

Please sign in to comment.