Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
penn5 committed Oct 1, 2020
1 parent 5928c50 commit 85c4ea9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
10 changes: 2 additions & 8 deletions sanic/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def register(self, app, options):

# Routes
for future in self.routes:
# attach the blueprint name to the handler so that it can be
# prefixed properly in the router
future.handler.__blueprintname__ = self.name
# Prepend the blueprint URI prefix if available
uri = url_prefix + future.uri if url_prefix else future.uri

Expand All @@ -123,22 +120,19 @@ def register(self, app, options):
strict_slashes=future.strict_slashes,
stream=future.stream,
version=version,
name=future.name,
name=future.name or f"{self.name}.{future.handler.__name__}",
)(future.handler)
if _routes:
routes += _routes

for future in self.websocket_routes:
# attach the blueprint name to the handler so that it can be
# prefixed properly in the router
future.handler.__blueprintname__ = self.name
# Prepend the blueprint URI prefix if available
uri = url_prefix + future.uri if url_prefix else future.uri
_routes, _ = app.websocket(
uri=uri,
host=future.host or self.host,
strict_slashes=future.strict_slashes,
name=future.name,
name=future.name or f"{self.name}.{future.handler.__name__}",
)(future.handler)
if _routes:
routes += _routes
Expand Down
11 changes: 7 additions & 4 deletions sanic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,15 @@ def merge_route(route, methods, handler):
is_static = True
name = name.split("_static_", 1)[-1]

if hasattr(handler, "__blueprintname__"):
bp_name = handler.__blueprintname__
if not name:
if hasattr(handler, "__blueprintname__"):
bp_name = handler.__blueprintname__

handler_name = f"{bp_name}.{name or handler.__name__}"
handler_name = f"{bp_name}.{name or handler.__name__}"
else:
handler_name = getattr(handler, "__name__", None)
else:
handler_name = name or getattr(handler, "__name__", None)
handler_name = name

if route:
route = merge_route(route, methods, handler)
Expand Down

0 comments on commit 85c4ea9

Please sign in to comment.