Routing implementation used internally by `Application`. Provides a binding between `Application` and `RequestHandler`. This implementation extends `~.routing.ReversibleRuleRouter` in a couple of ways: * it allows to use `RequestHandler` subclasses as `~.routing.Rule` target and
| 2088 | |
| 2089 | |
| 2090 | class _ApplicationRouter(ReversibleRuleRouter): |
| 2091 | """Routing implementation used internally by `Application`. |
| 2092 | |
| 2093 | Provides a binding between `Application` and `RequestHandler`. |
| 2094 | This implementation extends `~.routing.ReversibleRuleRouter` in a couple of ways: |
| 2095 | * it allows to use `RequestHandler` subclasses as `~.routing.Rule` target and |
| 2096 | * it allows to use a list/tuple of rules as `~.routing.Rule` target. |
| 2097 | ``process_rule`` implementation will substitute this list with an appropriate |
| 2098 | `_ApplicationRouter` instance. |
| 2099 | """ |
| 2100 | |
| 2101 | def __init__( |
| 2102 | self, application: "Application", rules: Optional[_RuleList] = None |
| 2103 | ) -> None: |
| 2104 | assert isinstance(application, Application) |
| 2105 | self.application = application |
| 2106 | super().__init__(rules) |
| 2107 | |
| 2108 | def process_rule(self, rule: Rule) -> Rule: |
| 2109 | rule = super().process_rule(rule) |
| 2110 | |
| 2111 | if isinstance(rule.target, (list, tuple)): |
| 2112 | rule.target = _ApplicationRouter( |
| 2113 | self.application, rule.target # type: ignore |
| 2114 | ) |
| 2115 | |
| 2116 | return rule |
| 2117 | |
| 2118 | def get_target_delegate( |
| 2119 | self, target: Any, request: httputil.HTTPServerRequest, **target_params: Any |
| 2120 | ) -> Optional[httputil.HTTPMessageDelegate]: |
| 2121 | if isclass(target) and issubclass(target, RequestHandler): |
| 2122 | return self.application.get_handler_delegate( |
| 2123 | request, target, **target_params |
| 2124 | ) |
| 2125 | |
| 2126 | return super().get_target_delegate(target, request, **target_params) |
| 2127 | |
| 2128 | |
| 2129 | class Application(ReversibleRouter): |
no outgoing calls
no test coverage detected