Skip to content

Commit

Permalink
Removed pre-converter fallback in URLRouter. (#1894)
Browse files Browse the repository at this point in the history
Thanks to Matthias Kestenholz for review.
  • Loading branch information
carltongibson committed Aug 7, 2022
1 parent 4c60cc5 commit 1b17b23
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions channels/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,6 @@ async def __call__(self, scope, receive, send):
)


def route_pattern_match(route, path):
"""
Backport of RegexPattern.match for Django versions before 2.0. Returns
the remaining path and positional and keyword arguments matched.
"""
if hasattr(route, "pattern"):
match = route.pattern.match(path)
if match:
path, args, kwargs = match
kwargs.update(route.default_args)
return path, args, kwargs
return match

# Django<2.0. No converters... :-(
match = route.regex.search(path)
if match:
# If there are any named groups, use those as kwargs, ignoring
# non-named groups. Otherwise, pass all non-named arguments as
# positional arguments.
kwargs = match.groupdict()
args = () if kwargs else match.groups()
if kwargs is not None:
kwargs.update(route.default_args)
return path[match.end() :], args, kwargs
return None


class URLRouter:
"""
Routes to different applications/consumers based on the URL path.
Expand Down Expand Up @@ -135,9 +108,11 @@ async def __call__(self, scope, receive, send):
# Run through the routes we have until one matches
for route in self.routes:
try:
match = route_pattern_match(route, path)
match = route.pattern.match(path)
if match:
new_path, args, kwargs = match
# Add defaults to kwargs from the URL pattern.
kwargs.update(route.default_args)
# Add args or kwargs into the scope
outer = scope.get("url_route", {})
application = guarantee_single_callable(route.callback)
Expand Down

0 comments on commit 1b17b23

Please sign in to comment.