mirror of
https://github.com/python/cpython.git
synced 2025-11-11 02:52:04 +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
|
|
@ -14,7 +14,7 @@
|
|||
from glob import _PathGlobber, _no_recurse_symlinks
|
||||
from pathlib import PurePath, Path
|
||||
from pathlib._os import magic_open, ensure_distinct_paths, copy_file
|
||||
from typing import Protocol, runtime_checkable
|
||||
from typing import Optional, Protocol, runtime_checkable
|
||||
|
||||
|
||||
def _explode_path(path):
|
||||
|
|
@ -44,6 +44,7 @@ class _PathParser(Protocol):
|
|||
"""
|
||||
|
||||
sep: str
|
||||
altsep: Optional[str]
|
||||
def split(self, path: str) -> tuple[str, str]: ...
|
||||
def splitext(self, path: str) -> tuple[str, str]: ...
|
||||
def normcase(self, path: str) -> str: ...
|
||||
|
|
@ -225,7 +226,7 @@ def full_match(self, pattern, *, case_sensitive=None):
|
|||
if case_sensitive is None:
|
||||
case_sensitive = self.parser.normcase('Aa') == 'Aa'
|
||||
globber = _PathGlobber(pattern.parser.sep, case_sensitive, recursive=True)
|
||||
match = globber.compile(str(pattern))
|
||||
match = globber.compile(str(pattern), altsep=pattern.parser.altsep)
|
||||
return match(str(self)) is not None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue