Skip to content

bpo-38109: Add missing constants to Lib/stat.py #16665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def S_IFMT(mode):
S_IFIFO = 0o010000 # fifo (named pipe)
S_IFLNK = 0o120000 # symbolic link
S_IFSOCK = 0o140000 # socket file
# Fallbacks for uncommon platform-specific constants
S_IFDOOR = 0
S_IFPORT = 0
S_IFWHT = 0

# Functions to test for each file type

Expand Down Expand Up @@ -71,6 +75,18 @@ def S_ISSOCK(mode):
"""Return True if mode is from a socket."""
return S_IFMT(mode) == S_IFSOCK

def S_ISDOOR(mode):
"""Return True if mode is from a door."""
return False

def S_ISPORT(mode):
"""Return True if mode is from an event port."""
return False

def S_ISWHT(mode):
"""Return True if mode is from a whiteout."""
return False

# Names for permission bits

S_ISUID = 0o4000 # set UID bit
Expand Down
8 changes: 2 additions & 6 deletions Lib/test/test_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class TestFilemode:
'UF_IMMUTABLE', 'UF_NODUMP', 'UF_NOUNLINK', 'UF_OPAQUE'}

formats = {'S_IFBLK', 'S_IFCHR', 'S_IFDIR', 'S_IFIFO', 'S_IFLNK',
'S_IFREG', 'S_IFSOCK'}
'S_IFREG', 'S_IFSOCK', 'S_IFDOOR', 'S_IFPORT', 'S_IFWHT'}

format_funcs = {'S_ISBLK', 'S_ISCHR', 'S_ISDIR', 'S_ISFIFO', 'S_ISLNK',
'S_ISREG', 'S_ISSOCK'}
'S_ISREG', 'S_ISSOCK', 'S_ISDOOR', 'S_ISPORT', 'S_ISWHT'}

stat_struct = {
'ST_MODE': 0,
Expand Down Expand Up @@ -231,10 +231,6 @@ def test_file_attribute_constants(self):
class TestFilemodeCStat(TestFilemode, unittest.TestCase):
statmod = c_stat

formats = TestFilemode.formats | {'S_IFDOOR', 'S_IFPORT', 'S_IFWHT'}
format_funcs = TestFilemode.format_funcs | {'S_ISDOOR', 'S_ISPORT',
'S_ISWHT'}


class TestFilemodePyStat(TestFilemode, unittest.TestCase):
statmod = py_stat
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add missing :data:`stat.S_IFDOOR`, :data:`stat.S_IFPORT`, :data:`stat.S_IFWHT`,
:func:`stat.S_ISDOOR`, :func:`stat.S_ISPORT`, and :func:`stat.S_ISWHT` values to
the Python implementation of :mod:`stat`.