mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
bpo-39924: handle missing os functions more consistently in pathlib (GH-19220)
This commit is contained in:
parent
7482838190
commit
b57e045320
1 changed files with 16 additions and 27 deletions
|
@ -13,16 +13,10 @@ from stat import S_ISDIR, S_ISLNK, S_ISREG, S_ISSOCK, S_ISBLK, S_ISCHR, S_ISFIFO
|
||||||
from urllib.parse import quote_from_bytes as urlquote_from_bytes
|
from urllib.parse import quote_from_bytes as urlquote_from_bytes
|
||||||
|
|
||||||
|
|
||||||
supports_symlinks = True
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
import nt
|
from nt import _getfinalpathname
|
||||||
if sys.getwindowsversion()[:2] >= (6, 0):
|
|
||||||
from nt import _getfinalpathname
|
|
||||||
else:
|
|
||||||
supports_symlinks = False
|
|
||||||
_getfinalpathname = None
|
|
||||||
else:
|
else:
|
||||||
nt = None
|
_getfinalpathname = None
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
@ -412,18 +406,17 @@ class _NormalAccessor(_Accessor):
|
||||||
if hasattr(os, "lchmod"):
|
if hasattr(os, "lchmod"):
|
||||||
lchmod = os.lchmod
|
lchmod = os.lchmod
|
||||||
else:
|
else:
|
||||||
def lchmod(self, pathobj, mode):
|
def lchmod(self, path, mode):
|
||||||
raise NotImplementedError("lchmod() not available on this system")
|
raise NotImplementedError("os.lchmod() not available on this system")
|
||||||
|
|
||||||
mkdir = os.mkdir
|
mkdir = os.mkdir
|
||||||
|
|
||||||
unlink = os.unlink
|
unlink = os.unlink
|
||||||
|
|
||||||
if hasattr(os, "link"):
|
if hasattr(os, "link"):
|
||||||
link_to = os.link
|
link = os.link
|
||||||
else:
|
else:
|
||||||
@staticmethod
|
def link(self, src, dst):
|
||||||
def link_to(self, target):
|
|
||||||
raise NotImplementedError("os.link() not available on this system")
|
raise NotImplementedError("os.link() not available on this system")
|
||||||
|
|
||||||
rmdir = os.rmdir
|
rmdir = os.rmdir
|
||||||
|
@ -432,23 +425,19 @@ class _NormalAccessor(_Accessor):
|
||||||
|
|
||||||
replace = os.replace
|
replace = os.replace
|
||||||
|
|
||||||
if nt:
|
if hasattr(os, "symlink"):
|
||||||
if supports_symlinks:
|
symlink = os.symlink
|
||||||
symlink = os.symlink
|
|
||||||
else:
|
|
||||||
def symlink(a, b, target_is_directory):
|
|
||||||
raise NotImplementedError("symlink() not available on this system")
|
|
||||||
else:
|
else:
|
||||||
# Under POSIX, os.symlink() takes two args
|
def symlink(self, src, dst, target_is_directory=False):
|
||||||
@staticmethod
|
raise NotImplementedError("os.symlink() not available on this system")
|
||||||
def symlink(a, b, target_is_directory):
|
|
||||||
return os.symlink(a, b)
|
|
||||||
|
|
||||||
utime = os.utime
|
utime = os.utime
|
||||||
|
|
||||||
# Helper for resolve()
|
if hasattr(os, "readlink"):
|
||||||
def readlink(self, path):
|
readlink = os.readlink
|
||||||
return os.readlink(path)
|
else:
|
||||||
|
def readlink(self, path):
|
||||||
|
raise NotImplementedError("os.readlink() not available on this system")
|
||||||
|
|
||||||
def owner(self, path):
|
def owner(self, path):
|
||||||
try:
|
try:
|
||||||
|
@ -1369,7 +1358,7 @@ class Path(PurePath):
|
||||||
"""
|
"""
|
||||||
Create a hard link pointing to a path named target.
|
Create a hard link pointing to a path named target.
|
||||||
"""
|
"""
|
||||||
self._accessor.link_to(self, target)
|
self._accessor.link(self, target)
|
||||||
|
|
||||||
def rename(self, target):
|
def rename(self, target):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue