]> granicus.if.org Git - python/commitdiff
closes bpo-34353: Add sockets to stat.filemode fallback python implementation. (GH...
authorGPery <GPery@pm.me>
Fri, 10 Aug 2018 05:12:08 +0000 (08:12 +0300)
committerBenjamin Peterson <benjamin@python.org>
Fri, 10 Aug 2018 05:12:08 +0000 (22:12 -0700)
Lib/stat.py
Lib/test/test_stat.py
Misc/NEWS.d/next/Core and Builtins/2018-08-09-18-42-49.bpo-34353.GIOm_8.rst [new file with mode: 0644]

index 46837c06dacfb8864456d600442a8c4d7d4ee0de..a9c678ec03c9cb8c834ac9462bcb7a31cc4bf652 100644 (file)
@@ -111,6 +111,7 @@ SF_SNAPSHOT  = 0x00200000  # file is a snapshot file
 
 _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"),
index 73cd901bdbf5c1a192470791212391a23a4f7959..38ff2bcf8a6b646bbe05e26855c35ef6b2b6abf1 100644 (file)
@@ -1,5 +1,6 @@
 import unittest
 import os
+import socket
 import sys
 from test.support import TESTFN, import_fresh_module
 
@@ -191,6 +192,14 @@ class TestFilemode:
                 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 (file)
index 0000000..6799141
--- /dev/null
@@ -0,0 +1,2 @@
+Added the "socket" option in the `stat.filemode()` Python implementation to
+match the C implementation.