0001 """Constants/functions for interpreting results of os.stat() and os.lstat(). 0002 0003 Suggested usage: from stat import * 0004 """ 0005 0006 # XXX Strictly spoken, this module may have to be adapted for each POSIX 0007 # implementation; in practice, however, the numeric constants used by 0008 # stat() are almost universal (even for stat() emulations on non-UNIX 0009 # systems like MS-DOS). 0010 0011 # Indices for stat struct members in tuple returned by os.stat() 0012 0013 ST_MODE = 0 0014 ST_INO = 1 0015 ST_DEV = 2 0016 ST_NLINK = 3 0017 ST_UID = 4 0018 ST_GID = 5 0019 ST_SIZE = 6 0020 ST_ATIME = 7 0021 ST_MTIME = 8 0022 ST_CTIME = 9 0023 0024 # Extract bits from the mode 0025 0026 def S_IMODE(mode): 0027 return mode & 07777 0028 0029 def S_IFMT(mode): 0030 return mode & 0170000 0031 0032 # Constants used as S_IFMT() for various file types 0033 # (not all are implemented on all systems) 0034 0035 S_IFDIR = 0040000 0036 S_IFCHR = 0020000 0037 S_IFBLK = 0060000 0038 S_IFREG = 0100000 0039 S_IFIFO = 0010000 0040 S_IFLNK = 0120000 0041 S_IFSOCK = 0140000 0042 0043 # Functions to test for each file type 0044 0045 def S_ISDIR(mode): 0046 return S_IFMT(mode) == S_IFDIR 0047 0048 def S_ISCHR(mode): 0049 return S_IFMT(mode) == S_IFCHR 0050 0051 def S_ISBLK(mode): 0052 return S_IFMT(mode) == S_IFBLK 0053 0054 def S_ISREG(mode): 0055 return S_IFMT(mode) == S_IFREG 0056 0057 def S_ISFIFO(mode): 0058 return S_IFMT(mode) == S_IFIFO 0059 0060 def S_ISLNK(mode): 0061 return S_IFMT(mode) == S_IFLNK 0062 0063 def S_ISSOCK(mode): 0064 return S_IFMT(mode) == S_IFSOCK 0065 0066 # Names for permission bits 0067 0068 S_ISUID = 04000 0069 S_ISGID = 02000 0070 S_ENFMT = S_ISGID 0071 S_ISVTX = 01000 0072 S_IREAD = 00400 0073 S_IWRITE = 00200 0074 S_IEXEC = 00100 0075 S_IRWXU = 00700 0076 S_IRUSR = 00400 0077 S_IWUSR = 00200 0078 S_IXUSR = 00100 0079 S_IRWXG = 00070 0080 S_IRGRP = 00040 0081 S_IWGRP = 00020 0082 S_IXGRP = 00010 0083 S_IRWXO = 00007 0084 S_IROTH = 00004 0085 S_IWOTH = 00002 0086 S_IXOTH = 00001 0087
Generated by PyXR 0.9.4