A blueprint is a container - a collection of routes.
Kyoukai uses Blueprints to create a routing tree - a tree of blueprints that are used to collect routes together and match routes easily.
Functions
get_rg_bp(group) |
Gets the Blueprint created from a RouteGroup. |
Classes
Blueprint(name[, parent, prefix, ...]) |
A Blueprint class contains a Map of URL rules, which is checked and ran for every |
Map([rules, default_subdomain, charset, ...]) |
The map class stores all the URL rules and some configuration parameters. |
Response([response, status, headers, ...]) |
Full featured response object implementing the following mixins: |
Route(function[, reverse_hooks, ...]) |
A route object is a wrapped function. |
RouteGroup |
A route group is a class that contains multiple methods that are decorated with the route decorator. |
Rule(string[, defaults, subdomain, methods, ...]) |
A Rule represents one URL pattern. |
Exceptions
HTTPException([description, response]) |
Baseclass for all HTTP exceptions. |
kyoukai.blueprint.Blueprint(name, parent=None, prefix='', *, host_matching=False, host=None)[source]¶Bases: object
A Blueprint class contains a Map of URL rules, which is checked and ran for every
| Parameters: |
|
|---|
name = None¶The name of this Blueprint.
finalized = None¶If this Blueprint is finalized or not. Finalization of a blueprint means gathering all of the Maps, and compiling a routing table which stores the endpoints.
routes = None¶The list of routes. This is used in finalization.
errorhandlers = None¶The error handler dictionary.
tree_routes¶| Return type: | Generator[Route, None, None] |
|---|---|
| Returns: | A generator that yields all routes from the tree, from parent to children. |
traverse_tree()[source]¶Traverses the tree for children Blueprints.
| Return type: | Generator[Blueprint, None, None] |
|---|
finalize(**map_options)[source]¶Called on the root Blueprint when all Blueprints have been registered and the app is starting.
This will automatically build a werkzeug.routing.Map of
werkzeug.routing.Rule objects for each Blueprint.
Note
Calling this on sub-blueprints will have no effect, apart from generating a Map. It is recommended to only call this on the root Blueprint.
| Parameters: | map_options – The options to pass to the created Map. |
|---|---|
| Return type: | Map |
| Returns: | The werkzeug.routing.Map created from the routing tree. |
add_child(blueprint)[source]¶Adds a Blueprint as a child of this one. This is automatically called when using another Blueprint as a parent.
| Parameters: | blueprint (Blueprint) – The blueprint to add as a child. |
|---|---|
| Return type: | Blueprint |
route(routing_url, methods=('GET', ), **kwargs)[source]¶Convenience decorator for adding a route.
This is equivalent to:
route = bp.wrap_route(func, **kwargs)
bp.add_route(route, routing_url, methods)
errorhandler(code)[source]¶Helper decorator for adding an error handler.
This is equivalent to:
route = bp.add_errorhandler(cbl, code)
| Parameters: | code (int) – The error handler code to use. |
|---|
wrap_route(cbl, *args, **kwargs)[source]¶Wraps a callable in a Route.
This is required for routes to be added.
:param cbl: The callable to wrap.
:rtype: Route
:return: A new Route object.
add_errorhandler(cbl, errorcode)[source]¶Adds an error handler to the table of error handlers.
A blueprint can only have one error handler per code. If it doesn’t have an error handler for that code, it will try to fetch recursively the parent’s error handler.
| Parameters: |
|
|---|
get_errorhandler(exc)[source]¶Recursively acquires the error handler for the specified error.
| Parameters: | exc (Union[HTTPException, int]) – The exception to get the error handler for.
This can either be a HTTPException object, or an integer. |
|---|---|
| Return type: | Union[None, Route] |
| Returns: | The Route object that corresponds to the error handler,
or None if no error handler could be found. |
get_hooks(type_)[source]¶Gets a list of hooks that match the current type.
These are ordered from parent to child.
| Parameters: | type (str) – The type of hooks to get (currently “pre” or “post”). |
|---|---|
| Returns: | An iterable of hooks to run. |
add_hook(type_, hook)[source]¶Adds a hook to the current Blueprint.
| Parameters: |
|
|---|
add_route(route, routing_url, methods=('GET', ))[source]¶Adds a route to the routing table and map.
| Parameters: |
|
|---|---|
| Returns: | The unmodified |
get_route(endpoint)[source]¶Gets the route associated with an endpoint.
| Return type: | Optional[Route] |
|---|
add_route_group(group)[source]¶Adds a route group to the current Blueprint.
| Parameters: | group (RouteGroup) – The RouteGroup to add. |
|---|
url_for(environment, endpoint, *, method=None, **kwargs)[source]¶Gets the URL for a specified endpoint using the arguments of the route.
This works very similarly to Flask’s url_for.
It is not recommended to invoke this method directly - instead, url_for is set on the
context object that is provided to your user function. This will allow you to invoke it
with the correct environment already set.
| Parameters: | |
|---|---|
| Return type: | |
| Returns: | The built URL for this endpoint. |
match(environment)[source]¶Matches with the WSGI environment.
| Parameters: | environment (dict) – The environment dict to perform matching with. You can use the |
|---|---|
| Return type: | Tuple[Route, Container[Any]] |
| Returns: | A Route object, which can be invoked to return the right response, and the parameters to invoke it with. |