recovery the format
This commit is contained in:
parent
28bdac46f6
commit
6265ef31bf
|
@ -95,7 +95,6 @@ class Blueprint:
|
||||||
:param uri: endpoint at which the route will be accessible.
|
:param uri: endpoint at which the route will be accessible.
|
||||||
:param methods: list of acceptable HTTP methods.
|
:param methods: list of acceptable HTTP methods.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def decorator(handler):
|
def decorator(handler):
|
||||||
if isinstance(handler, MethodType):
|
if isinstance(handler, MethodType):
|
||||||
raise SanicTypeException("You can`t add a instance "
|
raise SanicTypeException("You can`t add a instance "
|
||||||
|
@ -104,7 +103,6 @@ class Blueprint:
|
||||||
route = FutureRoute(handler, uri, methods, host, strict_slashes)
|
route = FutureRoute(handler, uri, methods, host, strict_slashes)
|
||||||
self.routes.append(route)
|
self.routes.append(route)
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def add_route(self, handler, uri, methods=frozenset({'GET'}), host=None,
|
def add_route(self, handler, uri, methods=frozenset({'GET'}), host=None,
|
||||||
|
@ -142,12 +140,10 @@ class Blueprint:
|
||||||
|
|
||||||
:param uri: endpoint at which the route will be accessible.
|
:param uri: endpoint at which the route will be accessible.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def decorator(handler):
|
def decorator(handler):
|
||||||
route = FutureRoute(handler, uri, [], host, strict_slashes)
|
route = FutureRoute(handler, uri, [], host, strict_slashes)
|
||||||
self.websocket_routes.append(route)
|
self.websocket_routes.append(route)
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def add_websocket_route(self, handler, uri, host=None):
|
def add_websocket_route(self, handler, uri, host=None):
|
||||||
|
@ -166,21 +162,17 @@ class Blueprint:
|
||||||
|
|
||||||
:param event: Event to listen to.
|
:param event: Event to listen to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def decorator(listener):
|
def decorator(listener):
|
||||||
self.listeners[event].append(listener)
|
self.listeners[event].append(listener)
|
||||||
return listener
|
return listener
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def middleware(self, *args, **kwargs):
|
def middleware(self, *args, **kwargs):
|
||||||
"""Create a blueprint middleware from a decorated function."""
|
"""Create a blueprint middleware from a decorated function."""
|
||||||
|
|
||||||
def register_middleware(_middleware):
|
def register_middleware(_middleware):
|
||||||
future_middleware = FutureMiddleware(_middleware, args, kwargs)
|
future_middleware = FutureMiddleware(_middleware, args, kwargs)
|
||||||
self.middlewares.append(future_middleware)
|
self.middlewares.append(future_middleware)
|
||||||
return _middleware
|
return _middleware
|
||||||
|
|
||||||
# Detect which way this was called, @middleware or @middleware('AT')
|
# Detect which way this was called, @middleware or @middleware('AT')
|
||||||
if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
|
if len(args) == 1 and len(kwargs) == 0 and callable(args[0]):
|
||||||
middleware = args[0]
|
middleware = args[0]
|
||||||
|
@ -191,12 +183,10 @@ class Blueprint:
|
||||||
|
|
||||||
def exception(self, *args, **kwargs):
|
def exception(self, *args, **kwargs):
|
||||||
"""Create a blueprint exception from a decorated function."""
|
"""Create a blueprint exception from a decorated function."""
|
||||||
|
|
||||||
def decorator(handler):
|
def decorator(handler):
|
||||||
exception = FutureException(handler, args, kwargs)
|
exception = FutureException(handler, args, kwargs)
|
||||||
self.exceptions.append(exception)
|
self.exceptions.append(exception)
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
def static(self, uri, file_or_directory, *args, **kwargs):
|
def static(self, uri, file_or_directory, *args, **kwargs):
|
||||||
|
|
|
@ -106,8 +106,6 @@ class SanicException(Exception):
|
||||||
|
|
||||||
class SanicTypeException(Exception):
|
class SanicTypeException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NotFound(SanicException):
|
class NotFound(SanicException):
|
||||||
status_code = 404
|
status_code = 404
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user