Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #714 #717

Merged
merged 1 commit into from
Jan 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aiohttp/abc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import asyncio
import sys
from abc import ABCMeta, abstractmethod


PY_35 = sys.version_info >= (3, 5)


class AbstractRouter(metaclass=ABCMeta):

@asyncio.coroutine # pragma: no branch
Expand Down Expand Up @@ -37,3 +41,8 @@ def request(self):
def __iter__(self):
while False: # pragma: no cover
yield None

if PY_35:
@abstractmethod
def __await__(self):
return
8 changes: 8 additions & 0 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mimetypes
import re
import os
import sys
import inspect

from collections.abc import Sized, Iterable, Container
Expand All @@ -24,6 +25,9 @@
'Route', 'PlainRoute', 'DynamicRoute', 'StaticRoute', 'View')


PY_35 = sys.version_info >= (3, 5)


class UrlMappingMatchInfo(dict, AbstractMatchInfo):

def __init__(self, match_dict, route):
Expand Down Expand Up @@ -386,6 +390,10 @@ def __iter__(self):
resp = yield from method()
return resp

if PY_35:
def __await__(self):
return (yield from self.__iter__())

def _raise_allowed_methods(self):
allowed_methods = {m for m in hdrs.METH_ALL if hasattr(self, m)}
raise HTTPMethodNotAllowed(self.request.method, allowed_methods)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_py35/test_cbv35.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from aiohttp import web
from aiohttp.web_urldispatcher import View
from unittest import mock


@pytest.mark.run_loop
async def test_render_ok():
resp = web.Response(text='OK')

class MyView(View):
async def get(self):
return resp

request = mock.Mock()
request.method = 'GET'
resp2 = await MyView(request)
assert resp is resp2