Module spangle.blueprint¶
Application blueprint and router.
Classes¶
Blueprint¶
class Blueprint(self)
Application component contains child paths with views.
Attributes
- views (
dict[str, tuple[type[AnyRequestHandlerProtocol], Converters, Optional[RoutingStrategy]]]
): Collected view classes. - events (
LifespanHandlers
): Registered lifespan handlers. - request_hooks (
dict["before" | "after", list[type[RequestHandlerProtocol]]]
): Called against every request.
Initialize self.
Methods¶
def add_blueprint(self, path: str, bp: Blueprint) -> None
Nest a Blueprint
in another one.
Args
- path (
str
): Prefix for the blueprint. - bp (
Blueprint
): Another instance to mount.
def after_request(
self, handler: type[RequestHandlerProtocol]
) -> type[RequestHandlerProtocol]
Decorator to add a class called after each request processed.
def before_request(
self, handler: type[RequestHandlerProtocol]
) -> type[RequestHandlerProtocol]
Decorator to add a class called before each request processed.
def handle(
self, e: type[Exception]
) -> Callable[[type[ErrorHandlerProtocol]], type[ErrorHandlerProtocol]]
Bind Exception
to the decorated view.
Args
- e (
type[Exception]
): Subclass ofException
you want to handle.
def on_start(self, f: LifespanFunction) -> LifespanFunction
Decorator for startup events.
def on_stop(self, f: LifespanFunction) -> LifespanFunction
Decorator for shutdown events.
def route(
self,
path: str,
*,
converters: Optional[Converters] = None,
routing: Optional[RoutingStrategy] = None,
) -> Callable[[type[AnyRequestHandlerProtocol]], type[AnyRequestHandlerProtocol]]
Bind a path to the decorated view. The path will be fixed by routing mode.
Args
- path (
str
): The location of your view. - converters (
Optional[Converters]
): Params converters for dynamic routing. - routing (
Optional[RoutingStrategy]
): Routing strategy.