From c4b92d1bab4e85022c8cdbc8ba66e3947bd19ec3 Mon Sep 17 00:00:00 2001 From: GPery Date: Tue, 7 Aug 2018 20:19:39 +0300 Subject: [PATCH 1/4] Added S_IFSOCK to _filemode_table in stat.py --- Lib/stat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/stat.py b/Lib/stat.py index 46837c06dacfb88..a9c678ec03c9cb8 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"), From cb9b1708df7a29fd0f5424bf723d2a3ebab7fc09 Mon Sep 17 00:00:00 2001 From: GPery Date: Wed, 8 Aug 2018 21:43:07 +0300 Subject: [PATCH 2/4] Added test for socket stat filemode --- Lib/test/test_stat.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Lib/test/test_stat.py b/Lib/test/test_stat.py index 73cd901bdbf5c1a..4ad89acad2519b2 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,17 @@ def test_devices(self): self.assertS_IS("BLK", st_mode) break + @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix socket') + def test_socket(self): + s = socket.socket(socket.AF_UNIX) + s.bind(TESTFN) + try: + st_mode, modestr = self.get_mode() + self.assertEqual(modestr[0], 's') + self.assertS_IS("SOCK", st_mode) + finally: + s.close() + def test_module_attributes(self): for key, value in self.stat_struct.items(): modvalue = getattr(self.statmod, key) From 939596cb6ef2f95d482dd3789371b91fd78026fc Mon Sep 17 00:00:00 2001 From: GPery Date: Thu, 9 Aug 2018 18:42:54 +0300 Subject: [PATCH 3/4] Added NEWS item for socket in stat.filemode --- .../Core and Builtins/2018-08-09-18-42-49.bpo-34353.GIOm_8.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2018-08-09-18-42-49.bpo-34353.GIOm_8.rst 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 000000000000000..679914120a438b3 --- /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. From c613e102e6158e147f04f6886b8799587b1430f2 Mon Sep 17 00:00:00 2001 From: GPery Date: Thu, 9 Aug 2018 18:44:46 +0300 Subject: [PATCH 4/4] Changed socket cleanup to use context manager syntax instead of try/finally --- Lib/test/test_stat.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_stat.py b/Lib/test/test_stat.py index 4ad89acad2519b2..38ff2bcf8a6b646 100644 --- a/Lib/test/test_stat.py +++ b/Lib/test/test_stat.py @@ -194,14 +194,11 @@ def test_devices(self): @unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'requires unix socket') def test_socket(self): - s = socket.socket(socket.AF_UNIX) - s.bind(TESTFN) - try: + 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) - finally: - s.close() def test_module_attributes(self): for key, value in self.stat_struct.items():