Skip to content

Commit b92c526

Browse files
GPerybenjaminp
authored andcommitted
closes bpo-34353: Add sockets to stat.filemode fallback python implementation. (GH-8703)
1 parent a754823 commit b92c526

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

Lib/stat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def S_ISSOCK(mode):
111111

112112
_filemode_table = (
113113
((S_IFLNK, "l"),
114+
(S_IFSOCK, "s"), # Must appear before IFREG and IFDIR as IFSOCK == IFREG | IFDIR
114115
(S_IFREG, "-"),
115116
(S_IFBLK, "b"),
116117
(S_IFDIR, "d"),

Lib/test/test_stat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22
import os
3+
import socket
34
import sys
45
from test.support import TESTFN, import_fresh_module
56

@@ -191,6 +192,14 @@ def test_devices(self):
191192
self.assertS_IS("BLK", st_mode)
192193
break
193194

195+
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix socket')
196+
def test_socket(self):
197+
with socket.socket(socket.AF_UNIX) as s:
198+
s.bind(TESTFN)
199+
st_mode, modestr = self.get_mode()
200+
self.assertEqual(modestr[0], 's')
201+
self.assertS_IS("SOCK", st_mode)
202+
194203
def test_module_attributes(self):
195204
for key, value in self.stat_struct.items():
196205
modvalue = getattr(self.statmod, key)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added the "socket" option in the `stat.filemode()` Python implementation to
2+
match the C implementation.

0 commit comments

Comments
 (0)