Matches requests from hosts specified by ``host_pattern`` regex.
| 515 | |
| 516 | |
| 517 | class HostMatches(Matcher): |
| 518 | """Matches requests from hosts specified by ``host_pattern`` regex.""" |
| 519 | |
| 520 | def __init__(self, host_pattern: Union[str, Pattern]) -> None: |
| 521 | if isinstance(host_pattern, basestring_type): |
| 522 | if not host_pattern.endswith("$"): |
| 523 | host_pattern += "$" |
| 524 | self.host_pattern = re.compile(host_pattern) |
| 525 | else: |
| 526 | self.host_pattern = host_pattern |
| 527 | |
| 528 | def match(self, request: httputil.HTTPServerRequest) -> Optional[Dict[str, Any]]: |
| 529 | if self.host_pattern.match(request.host_name): |
| 530 | return {} |
| 531 | |
| 532 | return None |
| 533 | |
| 534 | |
| 535 | class DefaultHostMatches(Matcher): |
no outgoing calls