From c7c333d25d258187d71b6658e90796daba708912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Fran=C3=A7ois=20Natali?= Date: Tue, 21 May 2013 09:49:18 +0200 Subject: Issue #17683: socket module: return AF_UNIX addresses in Linux abstract namespace as string. --- Lib/test/test_socket.py | 12 ++++++------ Misc/NEWS | 3 +++ Modules/socketmodule.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 546d793..cb00c38 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -4451,7 +4451,7 @@ class TestLinuxAbstractNamespace(unittest.TestCase): UNIX_PATH_MAX = 108 def testLinuxAbstractNamespace(self): - address = b"\x00python-test-hello\x00\xff" + address = "\x00python-test-hello\x00\xff" with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s1: s1.bind(address) s1.listen(1) @@ -4462,7 +4462,7 @@ class TestLinuxAbstractNamespace(unittest.TestCase): self.assertEqual(s2.getpeername(), address) def testMaxName(self): - address = b"\x00" + b"h" * (self.UNIX_PATH_MAX - 1) + address = "\x00" + "h" * (self.UNIX_PATH_MAX - 1) with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: s.bind(address) self.assertEqual(s.getsockname(), address) @@ -4472,12 +4472,12 @@ class TestLinuxAbstractNamespace(unittest.TestCase): with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: self.assertRaises(OSError, s.bind, address) - def testStrName(self): - # Check that an abstract name can be passed as a string. + def testBytesName(self): + # Check that an abstract name can be passed as bytes. s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) try: - s.bind("\x00python\x00test\x00") - self.assertEqual(s.getsockname(), b"\x00python\x00test\x00") + s.bind(b"\x00python\x00test\x00") + self.assertEqual(s.getsockname(), "\x00python\x00test\x00") finally: s.close() diff --git a/Misc/NEWS b/Misc/NEWS index acd89e4..12bb2d4 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -99,6 +99,9 @@ Core and Builtins Library ------- +- Issue #17683: socket module: return AF_UNIX addresses in Linux abstract + namespace as string. + - Issue #17914: Add os.cpu_count(). Patch by Yogesh Chaudhari, based on an initial patch by Trent Nelson. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 20db3d9..ae2924c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1018,7 +1018,7 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto) #ifdef linux if (a->sun_path[0] == 0) { /* Linux abstract namespace */ addrlen -= offsetof(struct sockaddr_un, sun_path); - return PyBytes_FromStringAndSize(a->sun_path, addrlen); + return PyUnicode_DecodeFSDefaultAndSize(a->sun_path, addrlen); } else #endif /* linux */ -- cgit v0.12