MCPcopy Index your code
hub / github.com/python/cpython / _filemode_to_int

Function _filemode_to_int

Lib/test/test_tarfile.py:3564–3590  ·  view source on GitHub ↗

Inverse of `stat.filemode` (for permission bits) Using mode strings rather than numbers makes the later tests more readable.

(mode)

Source from the content-addressed store, hash-verified

3562 self.assertEqual(expected, got)
3563
3564def _filemode_to_int(mode):
3565 """Inverse of `stat.filemode` (for permission bits)
3566
3567 Using mode strings rather than numbers makes the later tests more readable.
3568 """
3569 str_mode = mode[1:]
3570 result = (
3571 {'r': stat.S_IRUSR, '-': 0}[str_mode[0]]
3572 | {'w': stat.S_IWUSR, '-': 0}[str_mode[1]]
3573 | {'x': stat.S_IXUSR, '-': 0,
3574 's': stat.S_IXUSR | stat.S_ISUID,
3575 'S': stat.S_ISUID}[str_mode[2]]
3576 | {'r': stat.S_IRGRP, '-': 0}[str_mode[3]]
3577 | {'w': stat.S_IWGRP, '-': 0}[str_mode[4]]
3578 | {'x': stat.S_IXGRP, '-': 0,
3579 's': stat.S_IXGRP | stat.S_ISGID,
3580 'S': stat.S_ISGID}[str_mode[5]]
3581 | {'r': stat.S_IROTH, '-': 0}[str_mode[6]]
3582 | {'w': stat.S_IWOTH, '-': 0}[str_mode[7]]
3583 | {'x': stat.S_IXOTH, '-': 0,
3584 't': stat.S_IXOTH | stat.S_ISVTX,
3585 'T': stat.S_ISVTX}[str_mode[8]]
3586 )
3587 # check we did this right
3588 assert stat.filemode(result)[1:] == mode[1:]
3589
3590 return result
3591
3592class ArchiveMaker:
3593 """Helper to create a tar file with specific contents

Callers 1

addMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…