| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e58f98b commit 3bc034b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,15 +1,16 @@ | |||
| 1 | 1 | # Module 'stat' | |
| 2 | - | ||
| 2 | + # | ||
| 3 | 3 | # Defines constants and functions for interpreting stat/lstat struct | |
| 4 | - # as returned by posix.stat() and posix.lstat() (if it exists). | ||
| 5 | - | ||
| 6 | - # XXX This module may have to be adapted for UNIXoid systems whose | ||
| 7 | - # <sys/stat.h> deviates from AT&T or BSD UNIX; their S_IF* constants | ||
| 8 | - # may differ. | ||
| 9 | - | ||
| 4 | + # as returned by os.stat() and os.lstat() (if it exists). | ||
| 5 | + # | ||
| 10 | 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 Macintosh or MS-DOS). | ||
| 11 | 12 | ||
| 12 | - # Tuple indices for stat struct members | ||
| 13 | + # Indices for stat struct members in tuple returned by os.stat() | ||
| 13 | 14 | ||
| 14 | 15 | ST_MODE = 0 | |
| 15 | 16 | ST_INO = 1 | |
@@ -22,10 +23,16 @@ | |||
| 22 | 23 | ST_MTIME = 8 | |
| 23 | 24 | ST_CTIME = 9 | |
| 24 | 25 | ||
| 26 | + # Extract bits from the mode | ||
| 27 | + | ||
| 25 | 28 | def S_IMODE(mode): | |
| 26 | - return mode%4096 | ||
| 29 | + return mode & 07777 | ||
| 30 | + | ||
| 27 | 31 | def S_IFMT(mode): | |
| 28 | - return mode - mode%4096 | ||
| 32 | + return mode & ~07777 | ||
| 33 | + | ||
| 34 | + # Constants used as S_IFMT() for various file types | ||
| 35 | + # (not all are implemented on all systems) | ||
| 29 | 36 | ||
| 30 | 37 | S_IFDIR = 0040000 | |
| 31 | 38 | S_IFCHR = 0020000 | |
@@ -35,6 +42,8 @@ def S_IFMT(mode): | |||
| 35 | 42 | S_IFLNK = 0120000 | |
| 36 | 43 | S_IFSOCK = 0140000 | |
| 37 | 44 | ||
| 45 | + # Functions to test for each file type | ||
| 46 | + | ||
| 38 | 47 | def S_ISDIR(mode): | |
| 39 | 48 | return S_IFMT(mode) == S_IFDIR | |
| 40 | 49 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments