Skip to content

Commit f0beb66

Browse files
committed
Move Windows constants to module scope.
1 parent 4e918e4 commit f0beb66

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Lib/pathlib.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
_WINERROR_INVALID_NAME,
3636
_WINERROR_CANT_RESOLVE_FILENAME)
3737

38+
_win_drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
39+
_win_ext_namespace_prefix = '\\\\?\\'
40+
_win_reserved_names = (
41+
{'CON', 'PRN', 'AUX', 'NUL'} |
42+
{'COM%d' % i for i in range(1, 10)} |
43+
{'LPT%d' % i for i in range(1, 10)}
44+
)
45+
3846
def _ignore_error(exception):
3947
return (getattr(exception, 'errno', None) in _IGNORED_ERROS or
4048
getattr(exception, 'winerror', None) in _IGNORED_WINERRORS)
@@ -807,13 +815,6 @@ class PureWindowsPath(PurePath):
807815
_pathmod = ntpath
808816
_supported = (os.name == 'nt')
809817
_case_insensitive = True
810-
_drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
811-
_ext_namespace_prefix = '\\\\?\\'
812-
_reserved_names = (
813-
{'CON', 'PRN', 'AUX', 'NUL'} |
814-
{'COM%d' % i for i in range(1, 10)} |
815-
{'LPT%d' % i for i in range(1, 10)}
816-
)
817818
__slots__ = ()
818819

819820
# Interesting findings about extended paths:
@@ -854,7 +855,7 @@ def _splitroot(cls, part):
854855
else:
855856
return part[:index2], sep, part[index2+1:]
856857
drv = root = ''
857-
if second == ':' and first in cls._drive_letters:
858+
if second == ':' and first in _win_drive_letters:
858859
drv = part[:2]
859860
part = part[2:]
860861
first = third
@@ -864,7 +865,7 @@ def _splitroot(cls, part):
864865
return prefix + drv, root, part
865866

866867
@classmethod
867-
def _split_extended_path(cls, s, ext_prefix=_ext_namespace_prefix):
868+
def _split_extended_path(cls, s, ext_prefix=_win_ext_namespace_prefix):
868869
prefix = ''
869870
if s.startswith(ext_prefix):
870871
prefix = s[:4]
@@ -887,7 +888,7 @@ def is_reserved(self):
887888
if self._parts[0].startswith('\\\\'):
888889
# UNC paths are never reserved
889890
return False
890-
return self._parts[-1].partition('.')[0].upper() in self._reserved_names
891+
return self._parts[-1].partition('.')[0].upper() in _win_reserved_names
891892

892893
def as_uri(self):
893894
if not self.is_absolute():

0 commit comments

Comments
 (0)