Constructs a Rule instance. :arg Matcher matcher: a `Matcher` instance used for determining whether the rule should be considered a match for a specific request. :arg target: a Rule's target (typically a ``RequestHandler`` or `~.httputil.HTTPServe
(
self,
matcher: "Matcher",
target: Any,
target_kwargs: Optional[Dict[str, Any]] = None,
name: Optional[str] = None,
)
| 442 | """A routing rule.""" |
| 443 | |
| 444 | def __init__( |
| 445 | self, |
| 446 | matcher: "Matcher", |
| 447 | target: Any, |
| 448 | target_kwargs: Optional[Dict[str, Any]] = None, |
| 449 | name: Optional[str] = None, |
| 450 | ) -> None: |
| 451 | """Constructs a Rule instance. |
| 452 | |
| 453 | :arg Matcher matcher: a `Matcher` instance used for determining |
| 454 | whether the rule should be considered a match for a specific |
| 455 | request. |
| 456 | :arg target: a Rule's target (typically a ``RequestHandler`` or |
| 457 | `~.httputil.HTTPServerConnectionDelegate` subclass or even a nested `Router`, |
| 458 | depending on routing implementation). |
| 459 | :arg dict target_kwargs: a dict of parameters that can be useful |
| 460 | at the moment of target instantiation (for example, ``status_code`` |
| 461 | for a ``RequestHandler`` subclass). They end up in |
| 462 | ``target_params['target_kwargs']`` of `RuleRouter.get_target_delegate` |
| 463 | method. |
| 464 | :arg str name: the name of the rule that can be used to find it |
| 465 | in `ReversibleRouter.reverse_url` implementation. |
| 466 | """ |
| 467 | if isinstance(target, str): |
| 468 | # import the Module and instantiate the class |
| 469 | # Must be a fully qualified name (module.ClassName) |
| 470 | target = import_object(target) |
| 471 | |
| 472 | self.matcher = matcher # type: Matcher |
| 473 | self.target = target |
| 474 | self.target_kwargs = target_kwargs if target_kwargs else {} |
| 475 | self.name = name |
| 476 | |
| 477 | def reverse(self, *args: Any) -> Optional[str]: |
| 478 | return self.matcher.reverse(*args) |
no test coverage detected