Skip to content

Commit 4dd7c21

Browse files
committed
GH-125413: Add private metadata methods to pathlib.Path.info
Add the following private methods to `pathlib.Path.info`: - `_get_mode()`: returns the POSIX file mode (`st_mode`), or zero if `os.stat()` fails. - `_get_times_ns()`: returns the access and modify times in nanoseconds (`st_atime_ns` and `st_mtime_ns`), or zeroes if `os.stat()` fails. - `_get_flags()`: returns the BSD file flags (`st_flags`), or zero if `os.stat()` fails. - `_get_xattrs()`: returns the file extended attributes as a list of key, value pairs, or an empty list if `listxattr()` or `getattr()` fail. These methods replace `LocalCopyReader.read_metadata()`, and so we can delete the `CopyReader` and `LocalCopyReader` classes. Rather than reading metadata via `source._copy_reader.read_metadata()`, we instead call `source.info._get_mode()`, `_get_times_ns()`, etc. Copying metadata is only supported for local-to-local copies at the moment. To support copying between arbitrary `ReadablePath` and `WritablePath` objects, we'd need to make the new methods public and documented.
1 parent c88dacb commit 4dd7c21

File tree

3 files changed

+177
-216
lines changed

3 files changed

+177
-216
lines changed

Lib/pathlib/_abc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import functools
1515
import posixpath
1616
from glob import _PathGlobber, _no_recurse_symlinks
17-
from pathlib._os import magic_open, CopyReader, CopyWriter
17+
from pathlib._os import magic_open, CopyWriter
1818

1919

2020
@functools.cache
@@ -354,8 +354,6 @@ def readlink(self):
354354
"""
355355
raise NotImplementedError
356356

357-
_copy_reader = property(CopyReader)
358-
359357
def copy(self, target, follow_symlinks=True, dirs_exist_ok=False,
360358
preserve_metadata=False):
361359
"""

Lib/pathlib/_local.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
except ImportError:
2020
grp = None
2121

22-
from pathlib._os import LocalCopyReader, LocalCopyWriter, PathInfo, DirEntryInfo
22+
from pathlib._os import LocalCopyWriter, PathInfo, DirEntryInfo
2323
from pathlib._abc import JoinablePath, ReadablePath, WritablePath
2424

2525

@@ -1055,7 +1055,6 @@ def replace(self, target):
10551055
os.replace(self, target)
10561056
return self.with_segments(target)
10571057

1058-
_copy_reader = property(LocalCopyReader)
10591058
_copy_writer = property(LocalCopyWriter)
10601059

10611060
def move(self, target):

0 commit comments

Comments
 (0)