Skip to content

bpo-31202: Windows pathlib.Path.glob(pattern) fixed part of the pattern changed to lowercase whereas it should be unchanged. #3087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def readlink(self, path):
# Globbing helpers
#

def _make_selector(pattern_parts):
def _make_selector(pattern_parts, flavour):
pat = pattern_parts[0]
child_parts = pattern_parts[1:]
if pat == '**':
Expand All @@ -458,7 +458,7 @@ def _make_selector(pattern_parts):
cls = _WildcardSelector
else:
cls = _PreciseSelector
return cls(pat, child_parts)
return cls(pat, child_parts, flavour)

if hasattr(functools, "lru_cache"):
_make_selector = functools.lru_cache()(_make_selector)
Expand All @@ -468,10 +468,10 @@ class _Selector:
"""A selector matches a specific glob pattern part against the children
of a given path."""

def __init__(self, child_parts):
def __init__(self, child_parts, flavour):
self.child_parts = child_parts
if child_parts:
self.successor = _make_selector(child_parts)
self.successor = _make_selector(child_parts, flavour)
self.dironly = True
else:
self.successor = _TerminatingSelector()
Expand All @@ -497,9 +497,9 @@ def _select_from(self, parent_path, is_dir, exists, scandir):

class _PreciseSelector(_Selector):

def __init__(self, name, child_parts):
def __init__(self, name, child_parts, flavour):
self.name = name
_Selector.__init__(self, child_parts)
_Selector.__init__(self, child_parts, flavour)

def _select_from(self, parent_path, is_dir, exists, scandir):
try:
Expand All @@ -513,9 +513,9 @@ def _select_from(self, parent_path, is_dir, exists, scandir):

class _WildcardSelector(_Selector):

def __init__(self, pat, child_parts):
self.pat = re.compile(fnmatch.translate(pat))
_Selector.__init__(self, child_parts)
def __init__(self, pat, child_parts, flavour):
self.pat = re.compile(fnmatch.translate(flavour.casefold(pat)))
_Selector.__init__(self, child_parts, flavour)

def _select_from(self, parent_path, is_dir, exists, scandir):
try:
Expand All @@ -536,8 +536,8 @@ def _select_from(self, parent_path, is_dir, exists, scandir):

class _RecursiveWildcardSelector(_Selector):

def __init__(self, pat, child_parts):
_Selector.__init__(self, child_parts)
def __init__(self, pat, child_parts, flavour):
_Selector.__init__(self, child_parts, flavour)

def _iterate_directories(self, parent_path, is_dir, scandir):
yield parent_path
Expand Down Expand Up @@ -1070,23 +1070,21 @@ def glob(self, pattern):
"""
if not pattern:
raise ValueError("Unacceptable pattern: {!r}".format(pattern))
pattern = self._flavour.casefold(pattern)
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
if drv or root:
raise NotImplementedError("Non-relative patterns are unsupported")
selector = _make_selector(tuple(pattern_parts))
selector = _make_selector(tuple(pattern_parts), self._flavour)
for p in selector.select_from(self):
yield p

def rglob(self, pattern):
"""Recursively yield all existing files (of any kind, including
directories) matching the given pattern, anywhere in this subtree.
"""
pattern = self._flavour.casefold(pattern)
drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
if drv or root:
raise NotImplementedError("Non-relative patterns are unsupported")
selector = _make_selector(("**",) + tuple(pattern_parts))
selector = _make_selector(("**",) + tuple(pattern_parts), self._flavour)
for p in selector.select_from(self):
yield p

Expand Down