Skip to content

bpo-44136: remove pathlib._Flavour #26141

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
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove flavour.casefold() and flavour.casefold_parts()
  • Loading branch information
barneygale committed May 15, 2021
commit 3cf15c68acba6683a9052736d1f4d8c05db1b7db
33 changes: 18 additions & 15 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,11 @@ class _Flavour(object):
class _WindowsFlavour(_Flavour):
# Reference for Windows paths can be found at
# http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx

def casefold(self, s):
return s.lower()

def casefold_parts(self, parts):
return [p.lower() for p in parts]
pass


class _PosixFlavour(_Flavour):
def casefold(self, s):
return s

def casefold_parts(self, parts):
return parts
pass


_windows_flavour = _WindowsFlavour()
Expand Down Expand Up @@ -465,14 +456,26 @@ def _join_parsed_parts(self, drv, root, parts, drv2, root2, parts2):
if not drv2 and drv:
return drv, root2, [drv + root2] + parts2[1:]
elif drv2:
if drv2 == drv or self._flavour.casefold(drv2) == self._flavour.casefold(drv):
if drv2 == drv or self._casefold(drv2) == self._casefold(drv):
# Same drive => second path is relative to the first
return drv, root, parts + parts2[1:]
else:
# Second path is non-anchored (common case)
return drv, root, parts + parts2
return drv2, root2, parts2

@classmethod
def _casefold(cls, s):
if cls._case_insensitive:
return s.lower()
return s

@classmethod
def _casefold_parts(cls, parts):
if cls._case_insensitive:
return [p.lower() for p in parts]
return parts

def __str__(self):
"""Return the string representation of the path, suitable for
passing to system calls."""
Expand Down Expand Up @@ -509,7 +512,7 @@ def _cparts(self):
try:
return self._cached_cparts
except AttributeError:
self._cached_cparts = self._flavour.casefold_parts(self._parts)
self._cached_cparts = self._casefold_parts(self._parts)
return self._cached_cparts

def __eq__(self, other):
Expand Down Expand Up @@ -665,7 +668,7 @@ def relative_to(self, *other):
else:
to_abs_parts = to_parts
n = len(to_abs_parts)
cf = self._flavour.casefold_parts
cf = self._casefold_parts
if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
raise ValueError("{!r} is not in the subpath of {!r}"
Expand Down Expand Up @@ -744,7 +747,7 @@ def match(self, path_pattern):
"""
Return True if this path matches the given pattern.
"""
cf = self._flavour.casefold
cf = self._casefold
path_pattern = cf(path_pattern)
drv, root, pat_parts = self._parse_parts((path_pattern,))
if not pat_parts:
Expand Down