From 01e1a604fe43be4cadfa3f5821dbb3f9a2852c33 Mon Sep 17 00:00:00 2001 From: bluelhf Date: Fri, 7 Jul 2023 11:18:43 +0300 Subject: [PATCH 1/8] fix(socket): don't lookup own hostname in getfqdn() --- Lib/socket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/socket.py b/Lib/socket.py index 321fcda51505c18..2a86500d9d34655 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -790,7 +790,7 @@ def getfqdn(name=''): """ name = name.strip() if not name or name in ('0.0.0.0', '::'): - name = gethostname() + return gethostname() try: hostname, aliases, ipaddrs = gethostbyaddr(name) except error: From a99f24bbc996d837875ac50432ebd7ab9aec243e Mon Sep 17 00:00:00 2001 From: bluelhf Date: Fri, 7 Jul 2023 11:48:12 +0300 Subject: [PATCH 2/8] chore(blurb): add news entry --- .../2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst new file mode 100644 index 000000000000000..4c220c2ad981d08 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst @@ -0,0 +1,2 @@ +don't resolve the computer's own hostname when getting a fully-qualified +domain name From 353a0880ce472357aac18f8c1c6314b7362ab2ef Mon Sep 17 00:00:00 2001 From: bluelhf Date: Fri, 7 Jul 2023 11:48:33 +0300 Subject: [PATCH 3/8] chore(acks): add self --- Misc/ACKS | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/ACKS b/Misc/ACKS index 454b63155f013c9..b30d991896ca87e 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1769,6 +1769,7 @@ Daniel Stutzbach Andreas Stührk Colin Su Pal Subbiah +Ilari Suhonen Michael J. Sullivan Nathan Sullivan Mark Summerfield From 63702061111e62985912ca58e1baf403b2f99771 Mon Sep 17 00:00:00 2001 From: Ilari Suhonen Date: Wed, 28 Feb 2024 12:02:32 +0200 Subject: [PATCH 4/8] fix(blurb): reword news entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NEWS entries must start with a title case letter and end with a period — the entry was also rewritten to match the usual wording of entries --- .../2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst index 4c220c2ad981d08..894263a72702d87 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst @@ -1,2 +1,2 @@ -don't resolve the computer's own hostname when getting a fully-qualified -domain name +Fix ``getfqdn()`` attempting to resolve the computer's own hostname, instead +of returning it as-is. From 19c4464df52a39405eebc97ccdbc471896a742d0 Mon Sep 17 00:00:00 2001 From: bluelhf Date: Sun, 6 Sep 2026 21:34:03 +0300 Subject: [PATCH 5/8] feat(tests): add getfqdn-with-undefined test --- Lib/test/test_socket.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 0eaf64257c3b818..e8647855fb49136 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -1,4 +1,5 @@ import unittest +import unittest.mock from test import support from test.support import os_helper from test.support import socket_helper @@ -1081,6 +1082,17 @@ def test_sethostname(self): finally: socket.sethostname(oldhn) + def test_getfqdn_undefined_address(self): + for addr in ('', '0.0.0.0', '::'): + with self.subTest(addr=addr): + called = [] + with unittest.mock.patch.object( + socket, 'gethostbyaddr', + side_effect=lambda addr: called.append(addr) or ("", [], []) + ): + socket.getfqdn(addr) + self.assertFalse(called, f"gethostbyaddr was called for undefined address {addr!r}") + @unittest.skipUnless(hasattr(socket, 'if_nameindex'), 'socket.if_nameindex() not available.') def testInterfaceNameIndex(self): @@ -5713,7 +5725,6 @@ def testEmptyAddress(self): # Test that binding empty address fails. self.assertRaises(OSError, self.sock.bind, "") - class BufferIOTest(SocketConnectedTest): """ Test the buffer versions of socket.recv() and socket.send(). From 25d94e48bab5c738d3b67eff6cae890bff6fec50 Mon Sep 17 00:00:00 2001 From: bluelhf Date: Sun, 6 Sep 2026 21:42:28 +0300 Subject: [PATCH 6/8] chore(news): update date of news entry --- ....nwL_5c.rst => 2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/Core and Builtins/{2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst => 2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst} (100%) diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst b/Misc/NEWS.d/next/Core and Builtins/2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst similarity index 100% rename from Misc/NEWS.d/next/Core and Builtins/2023-07-07-11-47-56.gh-issue-106505.nwL_5c.rst rename to Misc/NEWS.d/next/Core and Builtins/2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst From 0ddb83b85e0b20b7481dfd0b1b65bcefa8f6c850 Mon Sep 17 00:00:00 2001 From: bluelhf Date: Sun, 6 Sep 2026 22:12:57 +0300 Subject: [PATCH 7/8] style(test_socket): re-add double newline before BufferIOTest --- Lib/test/test_socket.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 5570f2e2a0febf1..f8c4b6f6c266df8 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -6466,6 +6466,7 @@ def testEmptyAddress(self): # Test that binding empty address fails. self.assertRaises(OSError, self.sock.bind, "") + class BufferIOTest(SocketConnectedTest): """ Test the buffer versions of socket.recv() and socket.send(). From e5405b7871025ae794f00cdd0886d359e58d2c33 Mon Sep 17 00:00:00 2001 From: bluelhf Date: Sun, 6 Sep 2026 22:19:53 +0300 Subject: [PATCH 8/8] fix(news): correct #106505 news location --- .../2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/{Core and Builtins => Core_and_Builtins}/2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst (100%) diff --git a/Misc/NEWS.d/next/Core and Builtins/2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst similarity index 100% rename from Misc/NEWS.d/next/Core and Builtins/2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst rename to Misc/NEWS.d/next/Core_and_Builtins/2026-09-06-21-40-17.gh-issue-106505.nwL_5c.rst