mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
#14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
This commit is contained in:
parent
41829e82c1
commit
ffa1d0b8d5
6 changed files with 124 additions and 43 deletions
40
Lib/stat.py
40
Lib/stat.py
|
@ -107,3 +107,43 @@ SF_IMMUTABLE = 0x00020000 # file may not be changed
|
|||
SF_APPEND = 0x00040000 # file may only be appended to
|
||||
SF_NOUNLINK = 0x00100000 # file may not be renamed or deleted
|
||||
SF_SNAPSHOT = 0x00200000 # file is a snapshot file
|
||||
|
||||
|
||||
_filemode_table = (
|
||||
((S_IFLNK, "l"),
|
||||
(S_IFREG, "-"),
|
||||
(S_IFBLK, "b"),
|
||||
(S_IFDIR, "d"),
|
||||
(S_IFCHR, "c"),
|
||||
(S_IFIFO, "p")),
|
||||
|
||||
((S_IRUSR, "r"),),
|
||||
((S_IWUSR, "w"),),
|
||||
((S_IXUSR|S_ISUID, "s"),
|
||||
(S_ISUID, "S"),
|
||||
(S_IXUSR, "x")),
|
||||
|
||||
((S_IRGRP, "r"),),
|
||||
((S_IWGRP, "w"),),
|
||||
((S_IXGRP|S_ISGID, "s"),
|
||||
(S_ISGID, "S"),
|
||||
(S_IXGRP, "x")),
|
||||
|
||||
((S_IROTH, "r"),),
|
||||
((S_IWOTH, "w"),),
|
||||
((S_IXOTH|S_ISVTX, "t"),
|
||||
(S_ISVTX, "T"),
|
||||
(S_IXOTH, "x"))
|
||||
)
|
||||
|
||||
def filemode(mode):
|
||||
"""Convert a file's mode to a string of the form '-rwxrwxrwx'."""
|
||||
perm = []
|
||||
for table in _filemode_table:
|
||||
for bit, char in table:
|
||||
if mode & bit == bit:
|
||||
perm.append(char)
|
||||
break
|
||||
else:
|
||||
perm.append("-")
|
||||
return "".join(perm)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue