mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-130614: pathlib ABCs: support alternate separator in full_match()
(#130991)
In `pathlib.types._JoinablePath.full_match()`, treat alternate path separators in the path and pattern as if they were primary separators. e.g. if the parser is `ntpath`, then `P(r'foo/bar\baz').full_match(r'*\*/*')` is true.
This commit is contained in:
parent
ba64cc5db4
commit
bbd6d17ef8
2 changed files with 8 additions and 6 deletions
|
@ -320,11 +320,11 @@ def translate(pat, *, recursive=False, include_hidden=False, seps=None):
|
|||
|
||||
|
||||
@functools.lru_cache(maxsize=512)
|
||||
def _compile_pattern(pat, sep, case_sensitive, recursive=True):
|
||||
def _compile_pattern(pat, seps, case_sensitive, recursive=True):
|
||||
"""Compile given glob pattern to a re.Pattern object (observing case
|
||||
sensitivity)."""
|
||||
flags = re.NOFLAG if case_sensitive else re.IGNORECASE
|
||||
regex = translate(pat, recursive=recursive, include_hidden=True, seps=sep)
|
||||
regex = translate(pat, recursive=recursive, include_hidden=True, seps=seps)
|
||||
return re.compile(regex, flags=flags).match
|
||||
|
||||
|
||||
|
@ -360,8 +360,9 @@ class _GlobberBase:
|
|||
|
||||
# High-level methods
|
||||
|
||||
def compile(self, pat):
|
||||
return _compile_pattern(pat, self.sep, self.case_sensitive, self.recursive)
|
||||
def compile(self, pat, altsep=None):
|
||||
seps = (self.sep, altsep) if altsep else self.sep
|
||||
return _compile_pattern(pat, seps, self.case_sensitive, self.recursive)
|
||||
|
||||
def selector(self, parts):
|
||||
"""Returns a function that selects from a given path, walking and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue