Return True if this path matches the given pattern.
(self, path_pattern)
| 1139 | return self._flavour.is_reserved(self._parts) |
| 1140 | |
| 1141 | def match(self, path_pattern): |
| 1142 | """ |
| 1143 | Return True if this path matches the given pattern. |
| 1144 | """ |
| 1145 | cf = self._flavour.casefold |
| 1146 | path_pattern = cf(path_pattern) |
| 1147 | drv, root, pat_parts = self._flavour.parse_parts((path_pattern,)) |
| 1148 | if not pat_parts: |
| 1149 | raise ValueError("empty pattern") |
| 1150 | if drv and drv != cf(self._drv): |
| 1151 | return False |
| 1152 | if root and root != cf(self._root): |
| 1153 | return False |
| 1154 | parts = self._cparts |
| 1155 | if drv or root: |
| 1156 | if len(pat_parts) != len(parts): |
| 1157 | return False |
| 1158 | pat_parts = pat_parts[1:] |
| 1159 | elif len(pat_parts) > len(parts): |
| 1160 | return False |
| 1161 | for part, pat in zip(reversed(parts), reversed(pat_parts)): |
| 1162 | if not fnmatch.fnmatchcase(part, pat): |
| 1163 | return False |
| 1164 | return True |
| 1165 | |
| 1166 | |
| 1167 | # Can't subclass os.PathLike from PurePath and keep the constructor |