Skip to content

Commit 3655d5e

Browse files
committed
Remove flavour.is_reserved()
1 parent ec7c09b commit 3655d5e

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

Lib/pathlib.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ class _WindowsFlavour(_Flavour):
123123
drive_letters = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
124124
ext_namespace_prefix = '\\\\?\\'
125125

126-
reserved_names = (
127-
{'CON', 'PRN', 'AUX', 'NUL'} |
128-
{'COM%d' % i for i in range(1, 10)} |
129-
{'LPT%d' % i for i in range(1, 10)}
130-
)
131-
132126
# Interesting findings about extended paths:
133127
# - '\\?\c:\a', '//?/c:\a' and '//?/c:/a' are all supported
134128
# but '\\?\c:/a' is not
@@ -193,18 +187,6 @@ def _split_extended_path(self, s, ext_prefix=ext_namespace_prefix):
193187
s = '\\' + s[3:]
194188
return prefix, s
195189

196-
def is_reserved(self, parts):
197-
# NOTE: the rules for reserved names seem somewhat complicated
198-
# (e.g. r"..\NUL" is reserved but not r"foo\NUL").
199-
# We err on the side of caution and return True for paths which are
200-
# not considered reserved by Windows.
201-
if not parts:
202-
return False
203-
if parts[0].startswith('\\\\'):
204-
# UNC paths are never reserved
205-
return False
206-
return parts[-1].partition('.')[0].upper() in self.reserved_names
207-
208190
def make_uri(self, path):
209191
# Under Windows, file URIs use the UTF-8 encoding.
210192
drive = path.drive
@@ -250,9 +232,6 @@ def casefold_parts(self, parts):
250232
def compile_pattern(self, pattern):
251233
return re.compile(fnmatch.translate(pattern)).fullmatch
252234

253-
def is_reserved(self, parts):
254-
return False
255-
256235
def make_uri(self, path):
257236
# We represent the path using the local filesystem encoding,
258237
# for portability to other applications.
@@ -875,7 +854,7 @@ def is_absolute(self):
875854
def is_reserved(self):
876855
"""Return True if the path contains one of the special names reserved
877856
by the system, if any."""
878-
return self._flavour.is_reserved(self._parts)
857+
raise NotImplementedError
879858

880859
def match(self, path_pattern):
881860
"""
@@ -916,6 +895,9 @@ class PurePosixPath(PurePath):
916895
_flavour = _posix_flavour
917896
__slots__ = ()
918897

898+
def is_reserved(self):
899+
return False
900+
919901

920902
class PureWindowsPath(PurePath):
921903
"""PurePath subclass for Windows systems.
@@ -924,8 +906,25 @@ class PureWindowsPath(PurePath):
924906
However, you can also instantiate it directly on any system.
925907
"""
926908
_flavour = _windows_flavour
909+
_reserved_names = (
910+
{'CON', 'PRN', 'AUX', 'NUL'} |
911+
{'COM%d' % i for i in range(1, 10)} |
912+
{'LPT%d' % i for i in range(1, 10)}
913+
)
927914
__slots__ = ()
928915

916+
def is_reserved(self):
917+
# NOTE: the rules for reserved names seem somewhat complicated
918+
# (e.g. r"..\NUL" is reserved but not r"foo\NUL").
919+
# We err on the side of caution and return True for paths which are
920+
# not considered reserved by Windows.
921+
if not self._parts:
922+
return False
923+
if self._parts[0].startswith('\\\\'):
924+
# UNC paths are never reserved
925+
return False
926+
return self._parts[-1].partition('.')[0].upper() in self._reserved_names
927+
929928

930929
# Filesystem-accessing classes
931930

0 commit comments

Comments
 (0)