Mercurial > cpython-lru_cache-weakref
annotate Lib/stat.py @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | d892ac4b4fb9 |
| children | 6f4146846337 |
| rev | line source |
|---|---|
| 20 | 1 # Module 'stat' |
|
775
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
2 # |
| 20 | 3 # Defines constants and functions for interpreting stat/lstat struct |
|
775
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
4 # as returned by os.stat() and os.lstat() (if it exists). |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
5 # |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
6 # Suggested usage: from stat import * |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
7 # |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
8 # XXX Strictly spoken, this module may have to be adapted for each POSIX |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
9 # implementation; in practice, however, the numeric constants used by |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
10 # stat() are almost universal (even for stat() emulations on non-UNIX |
|
1810
d892ac4b4fb9
* Lib/linecache.py: don't crash on empty filename
Guido van Rossum <guido@python.org>
parents:
852
diff
changeset
|
11 # systems like MS-DOS). |
| 20 | 12 |
|
775
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
13 # Indices for stat struct members in tuple returned by os.stat() |
| 20 | 14 |
| 15 ST_MODE = 0 | |
| 16 ST_INO = 1 | |
| 17 ST_DEV = 2 | |
| 18 ST_NLINK = 3 | |
| 19 ST_UID = 4 | |
| 20 ST_GID = 5 | |
| 21 ST_SIZE = 6 | |
| 22 ST_ATIME = 7 | |
| 23 ST_MTIME = 8 | |
| 24 ST_CTIME = 9 | |
| 25 | |
|
775
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
26 # 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
|
27 |
|
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
|
28 def S_IMODE(mode): |
|
775
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
29 return mode & 07777 |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
30 |
| 20 | 31 def S_IFMT(mode): |
|
852
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
32 return mode & 0170000 |
|
775
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
33 |
|
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
34 # 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
|
35 # (not all are implemented on all systems) |
| 20 | 36 |
| 37 S_IFDIR = 0040000 | |
| 38 S_IFCHR = 0020000 | |
| 39 S_IFBLK = 0060000 | |
| 40 S_IFREG = 0100000 | |
| 41 S_IFIFO = 0010000 | |
| 42 S_IFLNK = 0120000 | |
| 43 S_IFSOCK = 0140000 | |
| 44 | |
|
775
45b3a78f256b
Use bitwise ops instead of %; added some warnings and comments
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
45 # 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
|
46 |
| 20 | 47 def S_ISDIR(mode): |
| 559 | 48 return S_IFMT(mode) == S_IFDIR |
| 20 | 49 |
| 50 def S_ISCHR(mode): | |
| 559 | 51 return S_IFMT(mode) == S_IFCHR |
| 20 | 52 |
| 53 def S_ISBLK(mode): | |
| 559 | 54 return S_IFMT(mode) == S_IFBLK |
| 20 | 55 |
| 56 def S_ISREG(mode): | |
| 559 | 57 return S_IFMT(mode) == S_IFREG |
| 20 | 58 |
| 59 def S_ISFIFO(mode): | |
| 559 | 60 return S_IFMT(mode) == S_IFIFO |
| 20 | 61 |
| 62 def S_ISLNK(mode): | |
| 559 | 63 return S_IFMT(mode) == S_IFLNK |
| 20 | 64 |
| 65 def S_ISSOCK(mode): | |
| 559 | 66 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
|
67 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
68 # Names for permission bits |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
69 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
70 S_ISUID = 04000 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
71 S_ISGID = 02000 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
72 S_ENFMT = S_ISGID |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
73 S_ISVTX = 01000 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
74 S_IREAD = 00400 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
75 S_IWRITE = 00200 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
76 S_IEXEC = 00100 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
77 S_IRWXU = 00700 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
78 S_IRUSR = 00400 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
79 S_IWUSR = 00200 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
80 S_IXUSR = 00100 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
81 S_IRWXG = 00070 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
82 S_IRGRP = 00040 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
83 S_IWGRP = 00020 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
84 S_IXGRP = 00010 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
85 S_IRWXO = 00007 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
86 S_IROTH = 00004 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
87 S_IWOTH = 00002 |
|
1ac5c6727e8c
Add names for perm bits (S_IREAD etc).
Guido van Rossum <guido@python.org>
parents:
775
diff
changeset
|
88 S_IXOTH = 00001 |
