Skip to content

Commit

Permalink
Use functools.wraps when wrapping synchronous handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Chaves committed Jun 5, 2017
1 parent 1e59d63 commit 290ac8b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import warnings
from collections.abc import Container, Iterable, Sized
from functools import wraps
from pathlib import Path
from types import MappingProxyType

Expand Down Expand Up @@ -106,6 +107,7 @@ def __init__(self, method, handler, *,
issubclass(handler, AbstractView)):
pass
else:
@wraps(handler)
@asyncio.coroutine
def handler_wrapper(*args, **kwargs):
result = old_handler(*args, **kwargs)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,30 @@ def handler(_):
assert r.status == 200


@asyncio.coroutine
def test_handler_metadata_persistence():
"""
Tests accessing metadata of a handler after registering it on the app
router.
"""
app = web.Application()

async def async_handler(_):
"""Doc"""
return web.Response()

def sync_handler(_):
"""Doc"""
return web.Response()

app.router.add_get('/async', async_handler)
app.router.add_get('/sync', sync_handler)

for resource in app.router.resources():
for route in resource:
assert route.handler.__doc__ == 'Doc'


@asyncio.coroutine
def test_unauthorized_folder_access(tmp_dir_path, loop, test_client):
"""
Expand Down

0 comments on commit 290ac8b

Please sign in to comment.