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 wiggin15
Recipients wiggin15
Date 2020-02-23.10:08:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582452524.82.0.552566008779.issue39729@roundup.psfhosted.org>
In-reply-to
Content
The C implementation of the "stat" module on Python 3 (_stat) is using the type "mode_t" for file modes, which differs between operating systems. This type can be defined as either "unsigned short" (for example, in macOS, or the definition added specifically for Windows in _stat.c) or "unsigned long" (Linux and other Unix systems such as AIX).
This means that the "stat" module may only work with file modes that come from the same system that Python was compiled for.
It is sometimes desirable to work with file modes on remote systems (for example, when using the "fabric" module to handle remote files - https://github.com/fabric/fabric/blob/1.10/fabric/sftp.py#L42).
With the pure-python "stat" module on Python 2.7, using macros such as "stat.S_ISDIR" with any value used to work (even values that exceed "unsigned short" on macOS, for example) but with the C implementation this can result in an exception on systems with an "unsigned short" mode_t:

    >>> stat.S_ISDIR(0o240755)
    OverflowError: mode out of range

I encountered this exception when trying to "put" files from a macOS system to an AIX system with "fabric" (0o240755 is the st_mode found for "/" on AIX).

For uniform handling of file modes, modes should be handled as unsigned long instead of the system-defined "mode_t".
History
Date User Action Args
2020-02-23 10:08:44wiggin15setrecipients: + wiggin15
2020-02-23 10:08:44wiggin15setmessageid: <1582452524.82.0.552566008779.issue39729@roundup.psfhosted.org>
2020-02-23 10:08:44wiggin15linkissue39729 messages
2020-02-23 10:08:44wiggin15create