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

Route definitions #2004

Merged
merged 31 commits into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a2fbd23
First scratches
asvetlov May 24, 2017
62f653a
Work on
asvetlov Jun 1, 2017
2ce063f
Work on decorators
asvetlov Jun 4, 2017
727ea50
Merge branch 'master' into route_deco
asvetlov Jun 14, 2017
daa31ec
Merge branch 'master' into route_deco
asvetlov Jun 20, 2017
0c23ebf
Make examples work
asvetlov Jun 20, 2017
6cab8b8
Refactor
asvetlov Jun 20, 2017
8b44cde
sort modules for scanning
asvetlov Jun 20, 2017
1d5492c
Go forward
asvetlov Jun 20, 2017
3eb5137
Add tests
asvetlov Jun 20, 2017
a5c24a0
Add test for decoration methods
asvetlov Jun 21, 2017
910cf1c
Add missing file
asvetlov Jun 21, 2017
36d4fc0
Fix python 3.4, add test
asvetlov Jun 22, 2017
de48fda
Fix typo
asvetlov Jun 22, 2017
234ed0e
Implement RouteDef
asvetlov Jun 22, 2017
2f5bb08
Merge branch 'master' into route_deco2
asvetlov Jun 22, 2017
d158513
Test cover
asvetlov Jun 22, 2017
b8ad2f4
RouteDef -> RoutesDef
asvetlov Jun 22, 2017
7391a69
RouteInfo -> RouteDef
asvetlov Jun 22, 2017
341da53
Add couple TODOs, drop RouteDef from exported names
asvetlov Jun 22, 2017
ec0630a
Fix flake8 blame
asvetlov Jun 23, 2017
9c1845c
RoutesDef -> RouteTableDef
asvetlov Aug 2, 2017
a9cbbb4
Merge remote-tracking branch 'origin/master' into route_deco2
asvetlov Aug 2, 2017
e2bc869
Add reprs
asvetlov Aug 2, 2017
58686cb
Add changes record
asvetlov Aug 2, 2017
875ae8e
Test cover missed case
asvetlov Aug 2, 2017
7c54e36
Add documentation for new route definitions API in web reference
asvetlov Aug 2, 2017
48203d3
Fix typo
asvetlov Aug 2, 2017
68f7225
Mention route tables and route decorators in web usage
asvetlov Aug 2, 2017
aaab3ed
Text flow polishing
asvetlov Aug 2, 2017
c10f4e0
Fix typo
asvetlov Aug 3, 2017
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
11 changes: 9 additions & 2 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@


class RouteDef(namedtuple('_RouteDef', 'method, path, handler, kwargs')):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not only Route?
What's the meaning of Def?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we already use Route name for routes added by app.router.add_route() call.
RouteDef is a scratch for non-added-yet route definition

# TODO: add __repr__
def __repr__(self):
info = []
for name, value in sorted(self.kwargs.items()):
info += ", {}={}".format(name, value)
return ("<RouteDef {method} {path} -> {handler.__name__!r}"
"{info}>".format(method=self.method, path=self.path,
handler=self.handler, info=''.join(info)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think will be better if info will be string
then you can delete ''.join(info)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style is used by asyncio in many places, I like to keep it in aiohttp too


def register(self, router):
if self.method in hdrs.METH_ALL:
Expand Down Expand Up @@ -956,7 +962,8 @@ class RouteTableDef(Sequence):
def __init__(self):
self._items = []

# TODO: add __repr__
def __repr__(self):
return "<RouteTableDef count={}>".format(len(self._items))

def __getitem__(self, index):
return self._items[index]
Expand Down
23 changes: 23 additions & 0 deletions tests/test_route_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,26 @@ def handler(request):
assert isinstance(info, web.RouteDef)
assert info in routes
assert list(routes)[0] is info


def test_repr_route_def():
routes = web.RouteTableDef()

@routes.get('/path')
@asyncio.coroutine
def handler(request):
pass

rd = routes[0]
assert repr(rd) == "<RouteDef GET /path -> 'handler'>"


def test_repr_route_table_def():
routes = web.RouteTableDef()

@routes.get('/path')
@asyncio.coroutine
def handler(request):
pass

assert repr(routes) == "<RouteTableDef count=1>"