mirror of
https://github.com/python/cpython.git
synced 2025-08-28 20:56:54 +00:00
bpo-22276: Change pathlib.Path.glob not to ignore trailing path separator (GH-10349)
Now pathlib.Path.glob() **only** matches directories when the pattern ends in a path separator. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
0ef8d921f5
commit
ea2f5bcda1
5 changed files with 42 additions and 0 deletions
|
@ -281,6 +281,8 @@ _posix_flavour = _PosixFlavour()
|
|||
def _make_selector(pattern_parts, flavour):
|
||||
pat = pattern_parts[0]
|
||||
child_parts = pattern_parts[1:]
|
||||
if not pat:
|
||||
return _TerminatingSelector()
|
||||
if pat == '**':
|
||||
cls = _RecursiveWildcardSelector
|
||||
elif '**' in pat:
|
||||
|
@ -943,6 +945,8 @@ class Path(PurePath):
|
|||
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
|
||||
if drv or root:
|
||||
raise NotImplementedError("Non-relative patterns are unsupported")
|
||||
if pattern[-1] in (self._flavour.sep, self._flavour.altsep):
|
||||
pattern_parts.append('')
|
||||
selector = _make_selector(tuple(pattern_parts), self._flavour)
|
||||
for p in selector.select_from(self):
|
||||
yield p
|
||||
|
@ -956,6 +960,8 @@ class Path(PurePath):
|
|||
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
|
||||
if drv or root:
|
||||
raise NotImplementedError("Non-relative patterns are unsupported")
|
||||
if pattern[-1] in (self._flavour.sep, self._flavour.altsep):
|
||||
pattern_parts.append('')
|
||||
selector = _make_selector(("**",) + tuple(pattern_parts), self._flavour)
|
||||
for p in selector.select_from(self):
|
||||
yield p
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue