Convert a file's mode to a string of the form '-rwxrwxrwx'.
(mode)
| 162 | ) |
| 163 | |
| 164 | def filemode(mode): |
| 165 | """Convert a file's mode to a string of the form '-rwxrwxrwx'.""" |
| 166 | perm = [] |
| 167 | for index, table in enumerate(_filemode_table): |
| 168 | for bit, char in table: |
| 169 | if index == 0: |
| 170 | if S_IFMT(mode) == bit: |
| 171 | perm.append(char) |
| 172 | break |
| 173 | else: |
| 174 | if mode & bit == bit: |
| 175 | perm.append(char) |
| 176 | break |
| 177 | else: |
| 178 | if index == 0: |
| 179 | # Unknown filetype |
| 180 | perm.append("?") |
| 181 | else: |
| 182 | perm.append("-") |
| 183 | return "".join(perm) |
| 184 | |
| 185 | |
| 186 | # Windows FILE_ATTRIBUTE constants for interpreting os.stat()'s |