Inverse of `stat.filemode` (for permission bits) Using mode strings rather than numbers makes the later tests more readable.
(mode)
| 3545 | self.assertEqual(expected, got) |
| 3546 | |
| 3547 | def _filemode_to_int(mode): |
| 3548 | """Inverse of `stat.filemode` (for permission bits) |
| 3549 | |
| 3550 | Using mode strings rather than numbers makes the later tests more readable. |
| 3551 | """ |
| 3552 | str_mode = mode[1:] |
| 3553 | result = ( |
| 3554 | {'r': stat.S_IRUSR, '-': 0}[str_mode[0]] |
| 3555 | | {'w': stat.S_IWUSR, '-': 0}[str_mode[1]] |
| 3556 | | {'x': stat.S_IXUSR, '-': 0, |
| 3557 | 's': stat.S_IXUSR | stat.S_ISUID, |
| 3558 | 'S': stat.S_ISUID}[str_mode[2]] |
| 3559 | | {'r': stat.S_IRGRP, '-': 0}[str_mode[3]] |
| 3560 | | {'w': stat.S_IWGRP, '-': 0}[str_mode[4]] |
| 3561 | | {'x': stat.S_IXGRP, '-': 0, |
| 3562 | 's': stat.S_IXGRP | stat.S_ISGID, |
| 3563 | 'S': stat.S_ISGID}[str_mode[5]] |
| 3564 | | {'r': stat.S_IROTH, '-': 0}[str_mode[6]] |
| 3565 | | {'w': stat.S_IWOTH, '-': 0}[str_mode[7]] |
| 3566 | | {'x': stat.S_IXOTH, '-': 0, |
| 3567 | 't': stat.S_IXOTH | stat.S_ISVTX, |
| 3568 | 'T': stat.S_ISVTX}[str_mode[8]] |
| 3569 | ) |
| 3570 | # check we did this right |
| 3571 | assert stat.filemode(result)[1:] == mode[1:] |
| 3572 | |
| 3573 | return result |
| 3574 | |
| 3575 | class ArchiveMaker: |
| 3576 | """Helper to create a tar file with specific contents |