Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7fcace9

Browse files
GH-125413: Add private metadata methods topathlib.Path.info (#129897)
Add the following private methods to `pathlib.Path.info`:- `_posix_permissions()`: the POSIX file permissions (`S_IMODE(st_mode)`)- `_file_id()`: the file ID (`(st_dev, st_ino)`)- `_access_time_ns()`: the access time in nanoseconds (`st_atime_ns`)- `_mod_time_ns()`: the modify time in nanoseconds (`st_mtime_ns`)- `_bsd_flags()`: the BSD file flags (`st_flags`)- `_xattrs()`: the file extended attributes as a list of key, value pairs, or an empty list if `listxattr()` or `getxattr()` fail in an ignorable way.These methods replace `LocalCopyReader.read_metadata()`, and so we candelete the `CopyReader` and `LocalCopyReader` classes. Rather than readingmetadata via `source._copy_reader.read_metadata()`, we instead call`source.info._posix_permissions()`, `_access_time_ns()`, etc.Preserving metadata is only supported for local-to-local copies at themoment. To support copying metadata between arbitrary `ReadablePath` and`WritablePath` objects, we'd need to make the new methods public anddocumented.Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parentbd1642c commit7fcace9

File tree

4 files changed

+204
-206
lines changed

4 files changed

+204
-206
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
fromabcimportABC,abstractmethod
1515
fromglobimport_PathGlobber,_no_recurse_symlinks
1616
frompathlibimportPurePath,Path
17-
frompathlib._osimportmagic_open,CopyReader,CopyWriter
17+
frompathlib._osimportmagic_open,CopyWriter
1818

1919

2020
def_explode_path(path):
@@ -353,8 +353,6 @@ def readlink(self):
353353
"""
354354
raiseNotImplementedError
355355

356-
_copy_reader=property(CopyReader)
357-
358356
defcopy(self,target,follow_symlinks=True,dirs_exist_ok=False,
359357
preserve_metadata=False):
360358
"""

‎Lib/pathlib/_local.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
exceptImportError:
2020
grp=None
2121

22-
frompathlib._osimportLocalCopyReader,LocalCopyWriter,PathInfo,DirEntryInfo
22+
frompathlib._osimportLocalCopyWriter,PathInfo,DirEntryInfo,ensure_different_files
2323

2424

2525
__all__= [
@@ -1079,7 +1079,6 @@ def replace(self, target):
10791079
os.replace(self,target)
10801080
returnself.with_segments(target)
10811081

1082-
_copy_reader=property(LocalCopyReader)
10831082
_copy_writer=property(LocalCopyWriter)
10841083

10851084
defcopy(self,target,follow_symlinks=True,dirs_exist_ok=False,
@@ -1125,7 +1124,7 @@ def move(self, target):
11251124
else:
11261125
ifnothasattr(target,'_copy_writer'):
11271126
target=self.with_segments(target_str)
1128-
target._copy_writer._ensure_different_file(self)
1127+
ensure_different_files(self,target)
11291128
try:
11301129
os.replace(self,target_str)
11311130
returntarget

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp