summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2021-04-07 15:53:39 (GMT)
committerGitHub <noreply@github.com>2021-04-07 15:53:39 (GMT)
commitabf964942f97f6489360a75fd57b5e4f41c75f57 (patch)
tree109be2453227ad4cae6204d1f364704527dc3af6 /Lib/pathlib.py
parent7a7ba3d343d360a03a34bc3901628f9f40a58307 (diff)
downloadcpython-abf964942f97f6489360a75fd57b5e4f41c75f57.zip
cpython-abf964942f97f6489360a75fd57b5e4f41c75f57.tar.gz
cpython-abf964942f97f6489360a75fd57b5e4f41c75f57.tar.bz2
bpo-39906: Add follow_symlinks parameter to pathlib.Path.stat() and chmod() (GH-18864)
Diffstat (limited to 'Lib/pathlib.py')
-rw-r--r--Lib/pathlib.py20
1 files changed, 6 insertions, 14 deletions
diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 9db8ae2..eaaf980 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -393,8 +393,6 @@ class _NormalAccessor(_Accessor):
stat = os.stat
- lstat = os.lstat
-
open = os.open
listdir = os.listdir
@@ -403,12 +401,6 @@ class _NormalAccessor(_Accessor):
chmod = os.chmod
- if hasattr(os, "lchmod"):
- lchmod = os.lchmod
- else:
- def lchmod(self, path, mode):
- raise NotImplementedError("os.lchmod() not available on this system")
-
mkdir = os.mkdir
unlink = os.unlink
@@ -1191,12 +1183,12 @@ class Path(PurePath):
normed = self._flavour.pathmod.normpath(s)
return self._from_parts((normed,))
- def stat(self):
+ def stat(self, *, follow_symlinks=True):
"""
Return the result of the stat() system call on this path, like
os.stat() does.
"""
- return self._accessor.stat(self)
+ return self._accessor.stat(self, follow_symlinks=follow_symlinks)
def owner(self):
"""
@@ -1286,18 +1278,18 @@ class Path(PurePath):
if not exist_ok or not self.is_dir():
raise
- def chmod(self, mode):
+ def chmod(self, mode, *, follow_symlinks=True):
"""
Change the permissions of the path, like os.chmod().
"""
- self._accessor.chmod(self, mode)
+ self._accessor.chmod(self, mode, follow_symlinks=follow_symlinks)
def lchmod(self, mode):
"""
Like chmod(), except if the path points to a symlink, the symlink's
permissions are changed, rather than its target's.
"""
- self._accessor.lchmod(self, mode)
+ self.chmod(mode, follow_symlinks=False)
def unlink(self, missing_ok=False):
"""
@@ -1321,7 +1313,7 @@ class Path(PurePath):
Like stat(), except if the path points to a symlink, the symlink's
status information is returned, rather than its target's.
"""
- return self._accessor.lstat(self)
+ return self.stat(follow_symlinks=False)
def link_to(self, target):
"""