kyoukai.route

Routes are wrapped function objects that are called upon a HTTP request.

Functions

wrap_response(args[, response_class]) Wrap up a response, if applicable.

Classes

Response([response, status, headers, ...]) Full featured response object implementing the following mixins:
Route(function[, reverse_hooks, ...]) A route object is a wrapped function.
Rule(string[, defaults, subdomain, methods, ...]) A Rule represents one URL pattern.

Exceptions

HTTPException([description, response]) Baseclass for all HTTP exceptions.
InternalServerError([description, response]) 500 Internal Server Error
class kyoukai.route.Route(function, reverse_hooks=False, should_invoke_hooks=True, do_argument_checking=True)[source]

Bases: object

A route object is a wrapped function. They invoke this function when invoked on routing and calling.

Parameters:
  • function – The underlying callable. This can be a function, or any other callable.
  • reverse_hooks (bool) – If the request hooks should be reversed for this request (i.e child to parent.)
  • should_invoke_hooks (bool) – If request hooks should be invoked. This is automatically False for error handlers.
  • do_argument_checking (bool) – If argument type and name checking is enabled for this route.
do_argument_checking = None

If this route should do argument checking.

bp = None

The Blueprint this route is associated with.

rule = None

The Rule associated with this route.

methods = None

A list of methods associated with this rule.

hooks = None

Our own specific hooks.

create_rule()[source]

Creates the rule object used by this route.

Return type:Rule
Returns:A new werkzeug.routing.Rule that is to be used for this route.
get_endpoint_name(bp=None)[source]

Gets the endpoint name for this route.

coroutine invoke_function(self, ctx, pre_hooks, post_hooks, params)[source]

Invokes the underlying callable.

This is for use in chaining routes. :param ctx: The HTTPRequestContext to use for this route. :type pre_hooks: list :param pre_hooks: A list of hooks to call before the route is invoked. :type post_hooks: list :param post_hooks: A list of hooks to call after the route is invoked. :param params: The parameters to pass to the function. :return: The result of the invoked function.

check_route_args(params=None)[source]

Checks the arguments for a route.

Parameters:params (Optional[dict]) – The parameters passed in, as a dict.
Raises:TypeError – If the arguments passed in were not correct.
add_hook(type_, hook)[source]

Adds a hook to the current Route.

Parameters:
  • type (str) – The type of hook to add (currently “pre” or “post”).
  • hook – The callable function to add as a hook.
get_hooks(type_)[source]

Gets the hooks for the current Route for the type.

Parameters:type (str) – The type to get.
Returns:A list of callables.
before_request(func)[source]

Convenience decorator to add a post-request hook.

after_request(func)[source]

Convenience decorator to add a pre-request hook.

coroutine invoke(self, ctx, params=None)[source]

Invokes a route. This will run the underlying function.

Parameters:
Return type:

Response

Returns:

The result of the route’s function.