Router Python Module

Router module.

This module contains classes to handle routing of events to event handlers.

class pacifica.dispatcher.router.Route(path: jsonpath2.path.Path, event_handler: pacifica.dispatcher.event_handlers.EventHandler)[source]

Route class.

This class routes an event to an event handler.

__init__(path: jsonpath2.path.Path, event_handler: pacifica.dispatcher.event_handlers.EventHandler) → None[source]

Save the path and event handler in the route.

match(event_data: Dict[str, Any]) → bool[source]

Determine if the event matches the route.

class pacifica.dispatcher.router.Router[source]

Router handles a list of routes.

__init__() → None[source]

Initialize the internal list of routes.

add_route(*args, **kwargs) → None[source]

Append new route objects based on keywords and args.

match(event_data: Dict[str, Any]) → Generator[[pacifica.dispatcher.router.Route, None], None][source]

Yield all route objects that match the event.

match_first_or_raise(event_data: Dict[str, Any]) → pacifica.dispatcher.router.Route[source]

Return the first route that matches the event.

exception pacifica.dispatcher.router.RouterError(router: pacifica.dispatcher.router.Router)[source]

Router base exception class.

__init__(router: pacifica.dispatcher.router.Router) → None[source]

Save the router as a part of the class.

exception pacifica.dispatcher.router.RouteNotFoundRouterError(router: pacifica.dispatcher.router.Router, event_data: Dict[str, Any])[source]

No route found exception.

__init__(router: pacifica.dispatcher.router.Router, event_data: Dict[str, Any]) → None[source]

Save the event as well as the router.