Skip to content

Commit

Permalink
Support named groups in url pattern regexes. Note that either all or …
Browse files Browse the repository at this point in the history
…none

of the groups to be passed to the handler must be named.
  • Loading branch information
Ben Darnell committed Mar 18, 2010
1 parent fca7c83 commit 8359c05
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tornado/web.py
Expand Up @@ -995,6 +995,7 @@ def __call__(self, request):
transforms = [t(request) for t in self.transforms]
handler = None
args = []
kwargs = {}
handlers = self._get_host_handlers(request)
if not handlers:
handler = RedirectHandler(
Expand All @@ -1004,7 +1005,14 @@ def __call__(self, request):
match = spec.regex.match(request.path)
if match:
handler = spec.handler_class(self, request, **spec.kwargs)
args = match.groups()
# Pass matched groups to the handler. Since
# match.groups() includes both named and unnamed groups,
# we want to use either groups or groupdict but not both.
kwargs = match.groupdict()
if kwargs:
args = []
else:
args = match.groups()
break
if not handler:
handler = ErrorHandler(self, request, 404)
Expand All @@ -1015,7 +1023,7 @@ def __call__(self, request):
RequestHandler._templates = None
RequestHandler._static_hashes = {}

handler._execute(transforms, *args)
handler._execute(transforms, *args, **kwargs)
return handler

def reverse_url(self, name, *args):
Expand Down

0 comments on commit 8359c05

Please sign in to comment.