Guido van Rossum | 7aeb4b9 | 1994-08-23 13:32:20 +0000 | [diff] [blame] | 1 | # Module 'stat' |
| 2 | # |
| 3 | # Defines constants and functions for interpreting stat/lstat struct |
| 4 | # as returned by os.stat() and os.lstat() (if it exists). |
| 5 | # |
| 6 | # Suggested usage: from stat import * |
| 7 | # |
| 8 | # XXX Strictly spoken, this module may have to be adapted for each POSIX |
| 9 | # implementation; in practice, however, the numeric constants used by |
| 10 | # stat() are almost universal (even for stat() emulations on non-UNIX |
| 11 | # systems like MS-DOS). |
| 12 | |
| 13 | # Indices for stat struct members in tuple returned by os.stat() |
| 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 | |
| 26 | # Extract bits from the mode |
| 27 | |
| 28 | def S_IMODE(mode): |
| 29 | return 0 |
| 30 | |
| 31 | def S_IFMT(mode): |
| 32 | return mode & 0xFFFF |
| 33 | |
| 34 | # Constants used as S_IFMT() for various file types |
| 35 | # (not all are implemented on all systems) |
| 36 | |
| 37 | S_IFDIR = 0x0000 |
| 38 | S_IFREG = 0x0003 |
| 39 | |
| 40 | # Functions to test for each file type |
| 41 | |
| 42 | def S_ISDIR(mode): |
| 43 | return S_IFMT(mode) == S_IFDIR |
| 44 | |
| 45 | def S_ISCHR(mode): |
| 46 | return 0 |
| 47 | |
| 48 | def S_ISBLK(mode): |
| 49 | return 0 |
| 50 | |
| 51 | def S_ISREG(mode): |
| 52 | return S_IFMT(mode) == S_IFREG |
| 53 | |
| 54 | def S_ISFIFO(mode): |
| 55 | return 0 |
| 56 | |
| 57 | def S_ISLNK(mode): |
| 58 | return 0 |
| 59 | |
| 60 | def S_ISSOCK(mode): |
| 61 | return 0 |
| 62 | |
| 63 | # Names for permission bits |
| 64 | |
| 65 | S_ISUID = 04000 |
| 66 | S_ISGID = 02000 |
| 67 | S_ENFMT = S_ISGID |
| 68 | S_ISVTX = 01000 |
| 69 | S_IREAD = 00400 |
| 70 | S_IWRITE = 00200 |
| 71 | S_IEXEC = 00100 |
| 72 | S_IRWXU = 00700 |
| 73 | S_IRUSR = 00400 |
| 74 | S_IWUSR = 00200 |
| 75 | S_IXUSR = 00100 |
| 76 | S_IRWXG = 00070 |
| 77 | S_IRGRP = 00040 |
| 78 | S_IWGRP = 00020 |
| 79 | S_IXGRP = 00010 |
| 80 | S_IRWXO = 00007 |
| 81 | S_IROTH = 00004 |
| 82 | S_IWOTH = 00002 |
| 83 | S_IXOTH = 00001 |