[Python-checkins] cpython (3.3): Issue #18792: Use "127.0.0.1" or "::1" instead of "localhost" as much as

antoine.pitrou python-checkins at python.org
Thu Aug 22 00:49:01 CEST 2013


http://hg.python.org/cpython/rev/7728b073c77c
changeset:   85302:7728b073c77c
branch:      3.3
parent:      85296:6bc533d06cf1
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Thu Aug 22 00:39:46 2013 +0200
summary:
  Issue #18792: Use "127.0.0.1" or "::1" instead of "localhost" as much as possible, since "localhost" goes through a DNS lookup under recent Windows versions.

files:
  Lib/test/support/__init__.py     |   6 +++++-
  Lib/test/test_asyncore.py        |   6 ++----
  Lib/test/test_ftplib.py          |   8 ++++----
  Lib/test/test_multiprocessing.py |  10 +++++-----
  Lib/test/test_timeout.py         |   2 +-
  Misc/NEWS                        |   4 ++++
  6 files changed, 21 insertions(+), 15 deletions(-)


diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -479,7 +479,11 @@
     return decorator
 
 
-HOST = 'localhost'
+# Don't use "localhost", since resolving it uses the DNS under recent
+# Windows versions (see issue #18792).
+HOST = "127.0.0.1"
+HOSTv6 = "::1"
+
 
 def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):
     """Returns an unused port that should be suitable for binding.  This is
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -10,7 +10,7 @@
 import struct
 
 from test import support
-from test.support import TESTFN, run_unittest, unlink
+from test.support import TESTFN, run_unittest, unlink, HOST, HOSTv6
 from io import BytesIO
 from io import StringIO
 
@@ -19,8 +19,6 @@
 except ImportError:
     threading = None
 
-HOST = support.HOST
-
 HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX')
 
 class dummysocket:
@@ -809,7 +807,7 @@
 @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 support required')
 class TestAPI_UseIPv6Sockets(BaseTestAPI):
     family = socket.AF_INET6
-    addr = ('::1', 0)
+    addr = (HOSTv6, 0)
 
 @unittest.skipUnless(HAS_UNIX_SOCKETS, 'Unix sockets required')
 class TestAPI_UseUnixSockets(BaseTestAPI):
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -18,7 +18,7 @@
 
 from unittest import TestCase
 from test import support
-from test.support import HOST
+from test.support import HOST, HOSTv6
 threading = support.import_module('threading')
 
 # the dummy data returned by server over the data channel when
@@ -766,7 +766,7 @@
 class TestIPv6Environment(TestCase):
 
     def setUp(self):
-        self.server = DummyFTPServer(('::1', 0), af=socket.AF_INET6)
+        self.server = DummyFTPServer((HOSTv6, 0), af=socket.AF_INET6)
         self.server.start()
         self.client = ftplib.FTP()
         self.client.connect(self.server.host, self.server.port)
@@ -949,7 +949,7 @@
         self.assertTrue(socket.getdefaulttimeout() is None)
         socket.setdefaulttimeout(30)
         try:
-            ftp = ftplib.FTP("localhost")
+            ftp = ftplib.FTP(HOST)
         finally:
             socket.setdefaulttimeout(None)
         self.assertEqual(ftp.sock.gettimeout(), 30)
@@ -961,7 +961,7 @@
         self.assertTrue(socket.getdefaulttimeout() is None)
         socket.setdefaulttimeout(30)
         try:
-            ftp = ftplib.FTP("localhost", timeout=None)
+            ftp = ftplib.FTP(HOST, timeout=None)
         finally:
             socket.setdefaulttimeout(None)
         self.assertTrue(ftp.sock.gettimeout() is None)
diff --git a/Lib/test/test_multiprocessing.py b/Lib/test/test_multiprocessing.py
--- a/Lib/test/test_multiprocessing.py
+++ b/Lib/test/test_multiprocessing.py
@@ -1968,7 +1968,7 @@
         authkey = os.urandom(32)
 
         manager = QueueManager(
-            address=('localhost', 0), authkey=authkey, serializer=SERIALIZER
+            address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER
             )
         manager.start()
 
@@ -2006,7 +2006,7 @@
     def test_rapid_restart(self):
         authkey = os.urandom(32)
         manager = QueueManager(
-            address=('localhost', 0), authkey=authkey, serializer=SERIALIZER)
+            address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
         srvr = manager.get_server()
         addr = srvr.address
         # Close the connection.Listener socket which gets opened as a part
@@ -2478,7 +2478,7 @@
             l.close()
 
         l = socket.socket()
-        l.bind(('localhost', 0))
+        l.bind((test.support.HOST, 0))
         l.listen(1)
         conn.send(l.getsockname())
         new_conn, addr = l.accept()
@@ -3235,9 +3235,9 @@
     def test_wait_socket(self, slow=False):
         from multiprocessing.connection import wait
         l = socket.socket()
-        l.bind(('', 0))
+        l.bind((test.support.HOST, 0))
         l.listen(4)
-        addr = ('localhost', l.getsockname()[1])
+        addr = l.getsockname()
         readers = []
         procs = []
         dic = {}
diff --git a/Lib/test/test_timeout.py b/Lib/test/test_timeout.py
--- a/Lib/test/test_timeout.py
+++ b/Lib/test/test_timeout.py
@@ -110,7 +110,7 @@
     # solution.
     fuzz = 2.0
 
-    localhost = '127.0.0.1'
+    localhost = support.HOST
 
     def setUp(self):
         raise NotImplementedError()
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -289,6 +289,10 @@
 Tests
 -----
 
+- Issue #18792: Use "127.0.0.1" or "::1" instead of "localhost" as much as
+  possible, since "localhost" goes through a DNS lookup under recent Windows
+  versions.
+
 - Issue #1666318: Add a test that shutil.copytree() retains directory
   permissions.  Patch by Catherine Devlin.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list