futurefinity.routing – FutureFinity Path Routing

class futurefinity.routing.RoutingLocator(default_handler: object=None)[source]

A Routing Locator.

Parameters:default_handler – should be a futurefinity.web.RequestHandler object, which will be returned if a handler cannot be found during the path matching.
add(path: str, handler: object, *args, name: str=None, **kwargs)[source]

Add a routing rule to the locator.

Parameters:
  • path – is a regular expression of the path that will be matched.
  • handler – should be a futurefinity.web.RequestHandler.
  • *args – all the other positional arguments will be come the path_args of the routing rule. The arguments passed here always have a higher priority in the matched routing rule, which means that all the positional arguments passed here will be the first part of the matched object.
  • name – the name of the routing rule.
  • **kwargs – all the other keyword arguments will be come the path_kwargs of the routing rule. The arguments passed here always have a higher priority in the matched routing rule, which means that if the same key also exsits in the regular expression, this one will override the one in the path.
find(path: str) → futurefinity.routing.RoutingRule[source]

Find a handler that matches the path.

If a handler that matches the path cannot be found, the handler will be the default_handler.

It returns a RoutingRule.

For the path_args and path_kwargs, the one passes though add method will have a higher priority.

class futurefinity.routing.RoutingRule[source]

Basic Routing Rule for Routing, which contains a handler, path_args, and a path_kwargs. It can be either a stored rule in a routing locator, or a matched rule that will be returned to the application.

Parameters:
  • handler – should be a futurefinity.web.RequestHandler object.
  • path_args – is a tuple or list that contains the positional arguments.
  • path_kwargs – is a dict that contains the keyword arguments.