This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rmilne
Recipients christian.heimes, rmilne, vstinner
Date 2013-06-21.13:03:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1371819818.66.0.966848674241.issue17913@psf.upfronthosting.co.za>
In-reply-to
Content
I've added some changes to the module which (I believe) not only fix this bug, but add the reverse function, converting a permission string to a number.

The diff was made against Lib/stat.py @ 84234:f32dad3a243e, which was the most recent version of the file I could find. My patch is intended for Python 2.7, but should work on 3.3 (though I haven't tested it there).

My 'filemode' function ('mode2str') is not as short and elegant as the current one, but then it should fix this bug, and it doesn't require duplicating so many of the module's constants in a lookup table. It also includes a check to make sure mode characters (like 'p', 's', '-', etc) are defined for every numeric mode in the module... so long as their names start with the prefix "S_IF" (... which may lead to conflicts with issue 17924).

I may also have gone beyond the scope, and added code to recognise the git link file mode (see http://stackoverflow.com/questions/737673/how-to-read-the-mode-field-of-git-ls-trees-output), but this extension should be easy to recognise and remove.

Lastly, there are some minor whitespace and sorting changes (notably, S_IF* defs sorted by mode num).

As for tests, I couldn't find any for this module in Lib/test. I have at least included a command line test which exhaustively tests the encoding and decoding of every valid file mode. If you want, I've even a test script which creates an example of every valid file type (apart from socket and git link types), with every valid file mode!
History
Date User Action Args
2013-06-21 13:03:38rmilnesetrecipients: + rmilne, vstinner, christian.heimes
2013-06-21 13:03:38rmilnesetmessageid: <1371819818.66.0.966848674241.issue17913@psf.upfronthosting.co.za>
2013-06-21 13:03:38rmilnelinkissue17913 messages
2013-06-21 13:03:38rmilnecreate