summaryrefslogtreecommitdiffstats
path: root/Lib/stat.py
diff options
context:
space:
mode:
authorGiampaolo Rodola' <g.rodola@gmail.com>2012-05-15 13:30:25 (GMT)
committerGiampaolo Rodola' <g.rodola@gmail.com>2012-05-15 13:30:25 (GMT)
commitffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0 (patch)
tree2c5626573e004979e0c38b58ed9ce31a3c96dcb5 /Lib/stat.py
parent41829e82c1826dd71b64f8334959bcf7731f66fc (diff)
downloadcpython-ffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0.zip
cpython-ffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0.tar.gz
cpython-ffa1d0b8d53f426f1f9a0d47f25440b8994c4fb0.tar.bz2
#14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Diffstat (limited to 'Lib/stat.py')
-rw-r--r--Lib/stat.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/stat.py b/Lib/stat.py
index 0f29498..704adfe 100644
--- a/Lib/stat.py
+++ b/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)