Skip to content

Commit

Permalink
Patch is_reserved for Windows/PosixPurePath
Browse files Browse the repository at this point in the history
- had been only patched for pathlib.Path
  • Loading branch information
mrbean-bremen committed Oct 5, 2024
1 parent 7ac7064 commit 0328c75
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions pyfakefs/fake_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,33 +848,15 @@ def touch(self, mode=0o666, exist_ok=True):
fake_file.close()
self.chmod(mode)

if sys.version_info >= (3, 12):
"""These are reimplemented for now because the original implementation
checks the flavour against ntpath/posixpath.
"""

def is_absolute(self):
if self.filesystem.is_windows_fs:
return self.drive and self.root
return os.path.isabs(self._path())

def is_reserved(self):
if sys.version_info >= (3, 13):
warnings.warn(
"pathlib.PurePath.is_reserved() is deprecated and scheduled "
"for removal in Python 3.15. Use os.path.isreserved() to detect "
"reserved paths on Windows.",
DeprecationWarning,
)
if not self.filesystem.is_windows_fs:
return False
if sys.version_info < (3, 13):
if not self._tail or self._tail[0].startswith("\\\\"):
# UNC paths are never reserved.
return False
name = self._tail[-1].partition(".")[0].partition(":")[0].rstrip(" ")
return name.upper() in pathlib._WIN_RESERVED_NAMES
return self.filesystem.isreserved(self._path())
def _warn_is_reserved_deprecated():
if sys.version_info >= (3, 13):
warnings.warn(
"pathlib.PurePath.is_reserved() is deprecated and scheduled "
"for removal in Python 3.15. Use os.path.isreserved() to detect "
"reserved paths on Windows.",
DeprecationWarning,
)


class FakePathlibModule:
Expand All @@ -900,12 +882,40 @@ class PurePosixPath(PurePath):
paths"""

__slots__ = ()
if sys.version_info >= (3, 12):

def is_reserved(self):
_warn_is_reserved_deprecated()
return False

def is_absolute(self):
return os.path.isabs(self)

class PureWindowsPath(PurePath):
"""A subclass of PurePath, that represents Windows filesystem paths"""

__slots__ = ()

if sys.version_info >= (3, 12):
"""These are reimplemented because the PurePath implementation
checks the flavour against ntpath/posixpath.
"""

def is_reserved(self):
_warn_is_reserved_deprecated()
if sys.version_info < (3, 13):
if not self._tail or self._tail[0].startswith("\\\\"):
# UNC paths are never reserved.
return False
name = (
self._tail[-1].partition(".")[0].partition(":")[0].rstrip(" ")
)
return name.upper() in pathlib._WIN_RESERVED_NAMES
return os.path.isreserved(self)

def is_absolute(self):
return bool(self.drive and self.root)

class WindowsPath(FakePath, PureWindowsPath):
"""A subclass of Path and PureWindowsPath that represents
concrete Windows filesystem paths.
Expand Down

0 comments on commit 0328c75

Please sign in to comment.