MCPcopy Index your code
hub / github.com/RustPython/RustPython / match

Method match

Lib/pathlib/__init__.py:570–594  ·  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

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected