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

Use functools.wraps when wrapping synchronous handlers #1953

Merged
merged 1 commit into from
Jun 5, 2017
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
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