Skip to content

Commit

Permalink
Use functools.wraps when wrapping synchronous handlers (#1953)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio authored and asvetlov committed Jun 5, 2017
1 parent 1e59d63 commit 9904f82
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Changes

- Add doc for add_head, update doc for add_get. #1944

-
- Retain method attributes (e.g. :code:`__doc__`) when registering synchronous
handlers for resources. #1953

-

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Contributors
------------
A. Jesse Jiryu Davis
Adam Mills
Adrián Chaves
Alec Hanefeld
Alejandro Gómez
Aleksandr Danshyn
Expand Down
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
25 changes: 25 additions & 0 deletions tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ 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()

@asyncio.coroutine
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 9904f82

Please sign in to comment.