Return True if this path matches the given pattern.
(self, path_pattern)
| 802 | return self._flavour.is_reserved(self._parts) |
| 803 | |
| 804 | def match(self, path_pattern): |
| 805 | """ |
| 806 | Return True if this path matches the given pattern. |
| 807 | """ |
| 808 | cf = self._flavour.casefold |
| 809 | path_pattern = cf(path_pattern) |
| 810 | drv, root, pat_parts = self._flavour.parse_parts((path_pattern,)) |
| 811 | if not pat_parts: |
| 812 | raise ValueError("empty pattern") |
| 813 | if drv and drv != cf(self._drv): |
| 814 | return False |
| 815 | if root and root != cf(self._root): |
| 816 | return False |
| 817 | parts = self._cparts |
| 818 | if drv or root: |
| 819 | if len(pat_parts) != len(parts): |
| 820 | return False |
| 821 | pat_parts = pat_parts[1:] |
| 822 | elif len(pat_parts) > len(parts): |
| 823 | return False |
| 824 | for part, pat in zip(reversed(parts), reversed(pat_parts)): |
| 825 | if not fnmatch.fnmatchcase(part, pat): |
| 826 | return False |
| 827 | return True |
| 828 | |
| 829 | # Can't subclass os.PathLike from PurePath and keep the constructor |
| 830 | # optimizations in PurePath._parse_args(). |