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
Move Windows constants to module scope.
  • Loading branch information
barneygale committed May 15, 2021
commit f0beb661aea0bb0e9464f741409a77c4acb256cf
21 changes: 11 additions & 10 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
_WINERROR_INVALID_NAME,
_WINERROR_CANT_RESOLVE_FILENAME)

_win_drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
_win_ext_namespace_prefix = '\\\\?\\'
_win_reserved_names = (
{'CON', 'PRN', 'AUX', 'NUL'} |
{'COM%d' % i for i in range(1, 10)} |
{'LPT%d' % i for i in range(1, 10)}
)

def _ignore_error(exception):
return (getattr(exception, 'errno', None) in _IGNORED_ERROS or
getattr(exception, 'winerror', None) in _IGNORED_WINERRORS)
Expand Down Expand Up @@ -807,13 +815,6 @@ class PureWindowsPath(PurePath):
_pathmod = ntpath
_supported = (os.name == 'nt')
_case_insensitive = True
_drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
_ext_namespace_prefix = '\\\\?\\'
_reserved_names = (
{'CON', 'PRN', 'AUX', 'NUL'} |
{'COM%d' % i for i in range(1, 10)} |
{'LPT%d' % i for i in range(1, 10)}
)
__slots__ = ()

# Interesting findings about extended paths:
Expand Down Expand Up @@ -854,7 +855,7 @@ def _splitroot(cls, part):
else:
return part[:index2], sep, part[index2+1:]
drv = root = ''
if second == ':' and first in cls._drive_letters:
if second == ':' and first in _win_drive_letters:
drv = part[:2]
part = part[2:]
first = third
Expand All @@ -864,7 +865,7 @@ def _splitroot(cls, part):
return prefix + drv, root, part

@classmethod
def _split_extended_path(cls, s, ext_prefix=_ext_namespace_prefix):
def _split_extended_path(cls, s, ext_prefix=_win_ext_namespace_prefix):
prefix = ''
if s.startswith(ext_prefix):
prefix = s[:4]
Expand All @@ -887,7 +888,7 @@ def is_reserved(self):
if self._parts[0].startswith('\\\\'):
# UNC paths are never reserved
return False
return self._parts[-1].partition('.')[0].upper() in self._reserved_names
return self._parts[-1].partition('.')[0].upper() in _win_reserved_names

def as_uri(self):
if not self.is_absolute():
Expand Down