annotate Lib/stat.py @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents de947db308ba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11707
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
1 """Constants/functions for interpreting results of os.stat() and os.lstat().
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
2
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
3 Suggested usage: from stat import *
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
4 """
6f4146846337 The third and final doc-string sweep by Ka-Ping Yee.
Guido van Rossum <guido@python.org>
parents: 1810
diff changeset
5
45955
36e296e66d21 Merged revisions 61644,61646-61647,61649-61652,61656-61658,61663,61665,61667 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 42084
diff changeset
6 # Indices for stat struct members in the tuple returned by os.stat()
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 ST_MODE = 0
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 ST_INO = 1
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 ST_DEV = 2
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 ST_NLINK = 3
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 ST_UID = 4
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 ST_GID = 5
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 ST_SIZE = 6
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 ST_ATIME = 7
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 ST_MTIME = 8
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 ST_CTIME = 9
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
775
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
19 # Extract bits from the mode
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
20
56
a7e8fb7bb6a2 Added S_IMODE() to strip the file type (S_IFMT) from a mode.
Guido van Rossum <guido@python.org>
parents: 20
diff changeset
21 def S_IMODE(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
22 """Return the portion of the file's mode that can be set by
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
23 os.chmod().
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
24 """
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40872
diff changeset
25 return mode & 0o7777
775
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
26
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 def S_IFMT(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
28 """Return the portion of the file's mode that describes the
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
29 file type.
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
30 """
42084
229c28cb9afb Merged revisions 55817-55961 via svnmerge from
Guido van Rossum <guido@python.org>
parents: 40872
diff changeset
31 return mode & 0o170000
775
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
32
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
33 # Constants used as S_IFMT() for various file types
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
34 # (not all are implemented on all systems)
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
36 S_IFDIR = 0o040000 # directory
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
37 S_IFCHR = 0o020000 # character device
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
38 S_IFBLK = 0o060000 # block device
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
39 S_IFREG = 0o100000 # regular file
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
40 S_IFIFO = 0o010000 # fifo (named pipe)
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
41 S_IFLNK = 0o120000 # symbolic link
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
42 S_IFSOCK = 0o140000 # socket file
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
775
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
44 # Functions to test for each file type
45b3a78f256b Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
45
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 def S_ISDIR(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
47 """Return True if mode is from a directory."""
15872
3685ef2a55a4 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11707
diff changeset
48 return S_IFMT(mode) == S_IFDIR
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 def S_ISCHR(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
51 """Return True if mode is from a character special device file."""
15872
3685ef2a55a4 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11707
diff changeset
52 return S_IFMT(mode) == S_IFCHR
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 def S_ISBLK(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
55 """Return True if mode is from a block special device file."""
15872
3685ef2a55a4 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11707
diff changeset
56 return S_IFMT(mode) == S_IFBLK
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 def S_ISREG(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
59 """Return True if mode is from a regular file."""
15872
3685ef2a55a4 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11707
diff changeset
60 return S_IFMT(mode) == S_IFREG
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 def S_ISFIFO(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
63 """Return True if mode is from a FIFO (named pipe)."""
15872
3685ef2a55a4 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11707
diff changeset
64 return S_IFMT(mode) == S_IFIFO
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 def S_ISLNK(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
67 """Return True if mode is from a symbolic link."""
15872
3685ef2a55a4 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11707
diff changeset
68 return S_IFMT(mode) == S_IFLNK
20
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
118545312f3b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 def S_ISSOCK(mode):
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
71 """Return True if mode is from a socket."""
15872
3685ef2a55a4 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 11707
diff changeset
72 return S_IFMT(mode) == S_IFSOCK
852
1ac5c6727e8c Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents: 775
diff changeset
73
1ac5c6727e8c Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents: 775
diff changeset
74 # Names for permission bits
1ac5c6727e8c Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents: 775
diff changeset
75
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
76 S_ISUID = 0o4000 # set UID bit
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
77 S_ISGID = 0o2000 # set GID bit
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
78 S_ENFMT = S_ISGID # file locking enforcement
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
79 S_ISVTX = 0o1000 # sticky bit
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
80 S_IREAD = 0o0400 # Unix V7 synonym for S_IRUSR
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
81 S_IWRITE = 0o0200 # Unix V7 synonym for S_IWUSR
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
82 S_IEXEC = 0o0100 # Unix V7 synonym for S_IXUSR
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
83 S_IRWXU = 0o0700 # mask for owner permissions
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
84 S_IRUSR = 0o0400 # read by owner
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
85 S_IWUSR = 0o0200 # write by owner
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
86 S_IXUSR = 0o0100 # execute by owner
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
87 S_IRWXG = 0o0070 # mask for group permissions
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
88 S_IRGRP = 0o0040 # read by group
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
89 S_IWGRP = 0o0020 # write by group
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
90 S_IXGRP = 0o0010 # execute by group
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
91 S_IRWXO = 0o0007 # mask for others (not in group) permissions
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
92 S_IROTH = 0o0004 # read by others
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
93 S_IWOTH = 0o0002 # write by others
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
94 S_IXOTH = 0o0001 # execute by others
40872
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 16657
diff changeset
95
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 16657
diff changeset
96 # Names for file flags
53fd144a3f1a Patch #1490190: posixmodule now includes os.chflags() and os.lchflags()
Martin v. Löwis <martin@v.loewis.de>
parents: 16657
diff changeset
97
76927
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
98 UF_NODUMP = 0x00000001 # do not dump file
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
99 UF_IMMUTABLE = 0x00000002 # file may not be changed
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
100 UF_APPEND = 0x00000004 # file may only be appended to
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
101 UF_OPAQUE = 0x00000008 # directory is opaque when viewed through a union stack
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
102 UF_NOUNLINK = 0x00000010 # file may not be renamed or deleted
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
103 UF_COMPRESSED = 0x00000020 # OS X: file is hfs-compressed
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
104 UF_HIDDEN = 0x00008000 # OS X: file should not be displayed
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
105 SF_ARCHIVED = 0x00010000 # file may be archived
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
106 SF_IMMUTABLE = 0x00020000 # file may not be changed
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
107 SF_APPEND = 0x00040000 # file may only be appended to
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
108 SF_NOUNLINK = 0x00100000 # file may not be renamed or deleted
2a695cbdf090 Issue 14800: add comments explaining stat.py constants + docstring for S_* functions.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 71031
diff changeset
109 SF_SNAPSHOT = 0x00200000 # file is a snapshot file
76949
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
110
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
111
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
112 _filemode_table = (
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
113 ((S_IFLNK, "l"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
114 (S_IFREG, "-"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
115 (S_IFBLK, "b"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
116 (S_IFDIR, "d"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
117 (S_IFCHR, "c"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
118 (S_IFIFO, "p")),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
119
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
120 ((S_IRUSR, "r"),),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
121 ((S_IWUSR, "w"),),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
122 ((S_IXUSR|S_ISUID, "s"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
123 (S_ISUID, "S"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
124 (S_IXUSR, "x")),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
125
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
126 ((S_IRGRP, "r"),),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
127 ((S_IWGRP, "w"),),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
128 ((S_IXGRP|S_ISGID, "s"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
129 (S_ISGID, "S"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
130 (S_IXGRP, "x")),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
131
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
132 ((S_IROTH, "r"),),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
133 ((S_IWOTH, "w"),),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
134 ((S_IXOTH|S_ISVTX, "t"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
135 (S_ISVTX, "T"),
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
136 (S_IXOTH, "x"))
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
137 )
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
138
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
139 def filemode(mode):
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
140 """Convert a file's mode to a string of the form '-rwxrwxrwx'."""
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
141 perm = []
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
142 for table in _filemode_table:
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
143 for bit, char in table:
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
144 if mode & bit == bit:
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
145 perm.append(char)
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
146 break
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
147 else:
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
148 perm.append("-")
492e6c6a01bb #14807: move undocumented tarfile.filemode() to stat.filemode(). Add tarfile.filemode alias with deprecation warning.
Giampaolo Rodola' <g.rodola@gmail.com>
parents: 76927
diff changeset
149 return "".join(perm)
84258
420f70a22b9d Issue #11016: Add C implementation of the stat module as _stat
Christian Heimes <christian@cheimes.de>
parents: 76949
diff changeset
150
420f70a22b9d Issue #11016: Add C implementation of the stat module as _stat
Christian Heimes <christian@cheimes.de>
parents: 76949
diff changeset
151 # If available, use C implementation
420f70a22b9d Issue #11016: Add C implementation of the stat module as _stat
Christian Heimes <christian@cheimes.de>
parents: 76949
diff changeset
152 try:
420f70a22b9d Issue #11016: Add C implementation of the stat module as _stat
Christian Heimes <christian@cheimes.de>
parents: 76949
diff changeset
153 from _stat import *
84448
de947db308ba Issue #15767: Excise the remaining instances of ModuleNotFoundError
Brett Cannon <brett@python.org>
parents: 84258
diff changeset
154 except ImportError:
84258
420f70a22b9d Issue #11016: Add C implementation of the stat module as _stat
Christian Heimes <christian@cheimes.de>
parents: 76949
diff changeset
155 pass