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
| 1920 | |
| 1921 | |
| 1922 | class _ApplicationRouter(ReversibleRuleRouter): |
| 1923 | """Routing implementation used internally by `Application`. |
| 1924 | |
| 1925 | Provides a binding between `Application` and `RequestHandler`. |
| 1926 | This implementation extends `~.routing.ReversibleRuleRouter` in a couple of ways: |
| 1927 | * it allows to use `RequestHandler` subclasses as `~.routing.Rule` target and |
| 1928 | * it allows to use a list/tuple of rules as `~.routing.Rule` target. |
| 1929 | ``process_rule`` implementation will substitute this list with an appropriate |
| 1930 | `_ApplicationRouter` instance. |
| 1931 | """ |
| 1932 | |
| 1933 | def __init__( |
| 1934 | self, application: "Application", rules: Optional[_RuleList] = None |
| 1935 | ) -> None: |
| 1936 | assert isinstance(application, Application) |
| 1937 | self.application = application |
| 1938 | super().__init__(rules) |
| 1939 | |
| 1940 | def process_rule(self, rule: Rule) -> Rule: |
| 1941 | rule = super().process_rule(rule) |
| 1942 | |
| 1943 | if isinstance(rule.target, (list, tuple)): |
| 1944 | rule.target = _ApplicationRouter( |
| 1945 | self.application, rule.target # type: ignore |
| 1946 | ) |
| 1947 | |
| 1948 | return rule |
| 1949 | |
| 1950 | def get_target_delegate( |
| 1951 | self, target: Any, request: httputil.HTTPServerRequest, **target_params: Any |
| 1952 | ) -> Optional[httputil.HTTPMessageDelegate]: |
| 1953 | if isclass(target) and issubclass(target, RequestHandler): |
| 1954 | return self.application.get_handler_delegate( |
| 1955 | request, target, **target_params |
| 1956 | ) |
| 1957 | |
| 1958 | return super().get_target_delegate(target, request, **target_params) |
| 1959 | |
| 1960 | |
| 1961 | class Application(ReversibleRouter): |
no outgoing calls
no test coverage detected