Skip to content
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
1 change: 1 addition & 0 deletions Lib/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def S_ISSOCK(mode):

_filemode_table = (
((S_IFLNK, "l"),
(S_IFSOCK, "s"), # Must appear before IFREG and IFDIR as IFSOCK == IFREG | IFDIR
(S_IFREG, "-"),
(S_IFBLK, "b"),
(S_IFDIR, "d"),
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_stat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import os
import socket
import sys
from test.support import TESTFN, import_fresh_module

Expand Down Expand Up @@ -191,6 +192,14 @@ def test_devices(self):
self.assertS_IS("BLK", st_mode)
break

@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix socket')
def test_socket(self):
with socket.socket(socket.AF_UNIX) as s:
s.bind(TESTFN)
st_mode, modestr = self.get_mode()
self.assertEqual(modestr[0], 's')
self.assertS_IS("SOCK", st_mode)

def test_module_attributes(self):
for key, value in self.stat_struct.items():
modvalue = getattr(self.statmod, key)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added the "socket" option in the `stat.filemode()` Python implementation to
match the C implementation.