Return True if this path matches the given pattern. If the pattern is relative, matching is done from the right; otherwise, the entire path is matched. The recursive wildcard '**' is *not* supported by this method.
(self, path_pattern, *, case_sensitive=None)
| 561 | return globber.compile(pattern)(path) is not None |
| 562 | |
| 563 | def match(self, path_pattern, *, case_sensitive=None): |
| 564 | """ |
| 565 | Return True if this path matches the given pattern. If the pattern is |
| 566 | relative, matching is done from the right; otherwise, the entire path |
| 567 | is matched. The recursive wildcard '**' is *not* supported by this |
| 568 | method. |
| 569 | """ |
| 570 | if not hasattr(path_pattern, 'with_segments'): |
| 571 | path_pattern = self.with_segments(path_pattern) |
| 572 | if case_sensitive is None: |
| 573 | case_sensitive = self.parser is posixpath |
| 574 | path_parts = self.parts[::-1] |
| 575 | pattern_parts = path_pattern.parts[::-1] |
| 576 | if not pattern_parts: |
| 577 | raise ValueError("empty pattern") |
| 578 | if len(path_parts) < len(pattern_parts): |
| 579 | return False |
| 580 | if len(path_parts) > len(pattern_parts) and path_pattern.anchor: |
| 581 | return False |
| 582 | globber = _StringGlobber(self.parser.sep, case_sensitive) |
| 583 | for path_part, pattern_part in zip(path_parts, pattern_parts): |
| 584 | match = globber.compile(pattern_part) |
| 585 | if match(path_part) is None: |
| 586 | return False |
| 587 | return True |
| 588 | |
| 589 | # Subclassing os.PathLike makes isinstance() checks slower, |
| 590 | # which in turn makes Path construction slower. Register instead! |
no test coverage detected