MCPcopy Index your code
hub / github.com/python/cpython / match

Method match

Lib/pathlib/__init__.py:563–587  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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!

Callers 6

_parse_sampling_rateFunction · 0.45
d3.min.jsFile · 0.45
SFunction · 0.45
PFunction · 0.45
updateSearchHighlightFunction · 0.45
collectFunctionsFunction · 0.45

Calls 4

with_segmentsMethod · 0.95
_StringGlobberClass · 0.90
matchFunction · 0.85
compileMethod · 0.45

Tested by

no test coverage detected