[Python-checkins] closes bpo-34353: Add sockets to stat.filemode fallback python implementation. (GH-8703)

Benjamin Peterson webhook-mailer at python.org
Fri Aug 10 01:12:13 EDT 2018


https://github.com/python/cpython/commit/b92c526ed5da474694f89e29d82565f2a654c29b
commit: b92c526ed5da474694f89e29d82565f2a654c29b
branch: master
author: GPery <GPery at pm.me>
committer: Benjamin Peterson <benjamin at python.org>
date: 2018-08-09T22:12:08-07:00
summary:

closes bpo-34353: Add sockets to stat.filemode fallback python implementation. (GH-8703)

files:
A Misc/NEWS.d/next/Core and Builtins/2018-08-09-18-42-49.bpo-34353.GIOm_8.rst
M Lib/stat.py
M Lib/test/test_stat.py

diff --git a/Lib/stat.py b/Lib/stat.py
index 46837c06dacf..a9c678ec03c9 100644
--- a/Lib/stat.py
+++ b/Lib/stat.py
@@ -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"),
diff --git a/Lib/test/test_stat.py b/Lib/test/test_stat.py
index 73cd901bdbf5..38ff2bcf8a6b 100644
--- a/Lib/test/test_stat.py
+++ b/Lib/test/test_stat.py
@@ -1,5 +1,6 @@
 import unittest
 import os
+import socket
 import sys
 from test.support import TESTFN, import_fresh_module
 
@@ -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)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2018-08-09-18-42-49.bpo-34353.GIOm_8.rst b/Misc/NEWS.d/next/Core and Builtins/2018-08-09-18-42-49.bpo-34353.GIOm_8.rst
new file mode 100644
index 000000000000..679914120a43
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2018-08-09-18-42-49.bpo-34353.GIOm_8.rst	
@@ -0,0 +1,2 @@
+Added the "socket" option in the `stat.filemode()` Python implementation to
+match the C implementation.



More information about the Python-checkins mailing list