MCPcopy Create free account
hub / github.com/EasyIME/PIME / _ApplicationRouter

Class _ApplicationRouter

python/python3/tornado/web.py:1922–1958  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1920
1921
1922class _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
1961class Application(ReversibleRouter):

Callers 3

process_ruleMethod · 0.85
__init__Method · 0.85
add_handlersMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected