Skip to content

Commit

Permalink
Refactor the app.route decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
krigar1184 committed Apr 6, 2019
1 parent 653ac7e commit de582d2
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions sanic/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,28 @@ def route(
strict_slashes = self.strict_slashes

def response(handler):
args = [key for key in signature(handler).parameters.keys()]
if args:
if stream:
handler.is_stream = stream

self.router.add(
uri=uri,
methods=methods,
handler=handler,
host=host,
strict_slashes=strict_slashes,
version=version,
name=name,
)
return handler
else:
args = list(signature(handler).parameters.keys())

if not args:
raise ValueError(
"Required parameter `request` missing "
"in the {0}() route?".format(handler.__name__)
)

if stream:
handler.is_stream = stream

self.router.add(
uri=uri,
methods=methods,
handler=handler,
host=host,
strict_slashes=strict_slashes,
version=version,
name=name,
)
return handler

return response

# Shorthand method decorators
Expand Down

0 comments on commit de582d2

Please sign in to comment.