Skip to content

Commit 7bb1431

Browse files
rlamyvstinner
authored andcommitted
bpo-38109: Add missing constants to Lib/stat.py (GH-16665)
Add missing stat.S_IFDOOR, stat.S_IFPORT, stat.S_IFWHT, stat.S_ISDOOR, stat.S_ISPORT, and stat.S_ISWHT values to the Python implementation of the stat module.
1 parent a544773 commit 7bb1431

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

Lib/stat.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ def S_IFMT(mode):
4040
S_IFIFO = 0o010000 # fifo (named pipe)
4141
S_IFLNK = 0o120000 # symbolic link
4242
S_IFSOCK = 0o140000 # socket file
43+
# Fallbacks for uncommon platform-specific constants
44+
S_IFDOOR = 0
45+
S_IFPORT = 0
46+
S_IFWHT = 0
4347

4448
# Functions to test for each file type
4549

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

78+
def S_ISDOOR(mode):
79+
"""Return True if mode is from a door."""
80+
return False
81+
82+
def S_ISPORT(mode):
83+
"""Return True if mode is from an event port."""
84+
return False
85+
86+
def S_ISWHT(mode):
87+
"""Return True if mode is from a whiteout."""
88+
return False
89+
7490
# Names for permission bits
7591

7692
S_ISUID = 0o4000 # set UID bit

Lib/test/test_stat.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class TestFilemode:
1616
'UF_IMMUTABLE', 'UF_NODUMP', 'UF_NOUNLINK', 'UF_OPAQUE'}
1717

1818
formats = {'S_IFBLK', 'S_IFCHR', 'S_IFDIR', 'S_IFIFO', 'S_IFLNK',
19-
'S_IFREG', 'S_IFSOCK'}
19+
'S_IFREG', 'S_IFSOCK', 'S_IFDOOR', 'S_IFPORT', 'S_IFWHT'}
2020

2121
format_funcs = {'S_ISBLK', 'S_ISCHR', 'S_ISDIR', 'S_ISFIFO', 'S_ISLNK',
22-
'S_ISREG', 'S_ISSOCK'}
22+
'S_ISREG', 'S_ISSOCK', 'S_ISDOOR', 'S_ISPORT', 'S_ISWHT'}
2323

2424
stat_struct = {
2525
'ST_MODE': 0,
@@ -231,10 +231,6 @@ def test_file_attribute_constants(self):
231231
class TestFilemodeCStat(TestFilemode, unittest.TestCase):
232232
statmod = c_stat
233233

234-
formats = TestFilemode.formats | {'S_IFDOOR', 'S_IFPORT', 'S_IFWHT'}
235-
format_funcs = TestFilemode.format_funcs | {'S_ISDOOR', 'S_ISPORT',
236-
'S_ISWHT'}
237-
238234

239235
class TestFilemodePyStat(TestFilemode, unittest.TestCase):
240236
statmod = py_stat
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add missing :data:`stat.S_IFDOOR`, :data:`stat.S_IFPORT`, :data:`stat.S_IFWHT`,
2+
:func:`stat.S_ISDOOR`, :func:`stat.S_ISPORT`, and :func:`stat.S_ISWHT` values to
3+
the Python implementation of :mod:`stat`.

0 commit comments

Comments
 (0)