Commit 59c2a549 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #18792: Use "127.0.0.1" or "::1" instead of "localhost" as much as...

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.
parent 3915133a
...@@ -479,7 +479,11 @@ def requires_mac_ver(*min_version): ...@@ -479,7 +479,11 @@ def requires_mac_ver(*min_version):
return decorator 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): def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM):
"""Returns an unused port that should be suitable for binding. This is """Returns an unused port that should be suitable for binding. This is
......
...@@ -10,7 +10,7 @@ import errno ...@@ -10,7 +10,7 @@ import errno
import struct import struct
from test import support 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 BytesIO
from io import StringIO from io import StringIO
...@@ -19,8 +19,6 @@ try: ...@@ -19,8 +19,6 @@ try:
except ImportError: except ImportError:
threading = None threading = None
HOST = support.HOST
HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX') HAS_UNIX_SOCKETS = hasattr(socket, 'AF_UNIX')
class dummysocket: class dummysocket:
...@@ -809,7 +807,7 @@ class TestAPI_UseIPv4Sockets(BaseTestAPI): ...@@ -809,7 +807,7 @@ class TestAPI_UseIPv4Sockets(BaseTestAPI):
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 support required') @unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 support required')
class TestAPI_UseIPv6Sockets(BaseTestAPI): class TestAPI_UseIPv6Sockets(BaseTestAPI):
family = socket.AF_INET6 family = socket.AF_INET6
addr = ('::1', 0) addr = (HOSTv6, 0)
@unittest.skipUnless(HAS_UNIX_SOCKETS, 'Unix sockets required') @unittest.skipUnless(HAS_UNIX_SOCKETS, 'Unix sockets required')
class TestAPI_UseUnixSockets(BaseTestAPI): class TestAPI_UseUnixSockets(BaseTestAPI):
......
...@@ -18,7 +18,7 @@ except ImportError: ...@@ -18,7 +18,7 @@ except ImportError:
from unittest import TestCase from unittest import TestCase
from test import support from test import support
from test.support import HOST from test.support import HOST, HOSTv6
threading = support.import_module('threading') threading = support.import_module('threading')
# the dummy data returned by server over the data channel when # the dummy data returned by server over the data channel when
...@@ -766,7 +766,7 @@ class TestFTPClass(TestCase): ...@@ -766,7 +766,7 @@ class TestFTPClass(TestCase):
class TestIPv6Environment(TestCase): class TestIPv6Environment(TestCase):
def setUp(self): 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.server.start()
self.client = ftplib.FTP() self.client = ftplib.FTP()
self.client.connect(self.server.host, self.server.port) self.client.connect(self.server.host, self.server.port)
...@@ -949,7 +949,7 @@ class TestTimeouts(TestCase): ...@@ -949,7 +949,7 @@ class TestTimeouts(TestCase):
self.assertTrue(socket.getdefaulttimeout() is None) self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30) socket.setdefaulttimeout(30)
try: try:
ftp = ftplib.FTP("localhost") ftp = ftplib.FTP(HOST)
finally: finally:
socket.setdefaulttimeout(None) socket.setdefaulttimeout(None)
self.assertEqual(ftp.sock.gettimeout(), 30) self.assertEqual(ftp.sock.gettimeout(), 30)
...@@ -961,7 +961,7 @@ class TestTimeouts(TestCase): ...@@ -961,7 +961,7 @@ class TestTimeouts(TestCase):
self.assertTrue(socket.getdefaulttimeout() is None) self.assertTrue(socket.getdefaulttimeout() is None)
socket.setdefaulttimeout(30) socket.setdefaulttimeout(30)
try: try:
ftp = ftplib.FTP("localhost", timeout=None) ftp = ftplib.FTP(HOST, timeout=None)
finally: finally:
socket.setdefaulttimeout(None) socket.setdefaulttimeout(None)
self.assertTrue(ftp.sock.gettimeout() is None) self.assertTrue(ftp.sock.gettimeout() is None)
......
...@@ -1968,7 +1968,7 @@ class _TestRemoteManager(BaseTestCase): ...@@ -1968,7 +1968,7 @@ class _TestRemoteManager(BaseTestCase):
authkey = os.urandom(32) authkey = os.urandom(32)
manager = QueueManager( manager = QueueManager(
address=('localhost', 0), authkey=authkey, serializer=SERIALIZER address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER
) )
manager.start() manager.start()
...@@ -2006,7 +2006,7 @@ class _TestManagerRestart(BaseTestCase): ...@@ -2006,7 +2006,7 @@ class _TestManagerRestart(BaseTestCase):
def test_rapid_restart(self): def test_rapid_restart(self):
authkey = os.urandom(32) authkey = os.urandom(32)
manager = QueueManager( manager = QueueManager(
address=('localhost', 0), authkey=authkey, serializer=SERIALIZER) address=(test.support.HOST, 0), authkey=authkey, serializer=SERIALIZER)
srvr = manager.get_server() srvr = manager.get_server()
addr = srvr.address addr = srvr.address
# Close the connection.Listener socket which gets opened as a part # Close the connection.Listener socket which gets opened as a part
...@@ -2478,7 +2478,7 @@ class _TestPicklingConnections(BaseTestCase): ...@@ -2478,7 +2478,7 @@ class _TestPicklingConnections(BaseTestCase):
l.close() l.close()
l = socket.socket() l = socket.socket()
l.bind(('localhost', 0)) l.bind((test.support.HOST, 0))
l.listen(1) l.listen(1)
conn.send(l.getsockname()) conn.send(l.getsockname())
new_conn, addr = l.accept() new_conn, addr = l.accept()
...@@ -3235,9 +3235,9 @@ class TestWait(unittest.TestCase): ...@@ -3235,9 +3235,9 @@ class TestWait(unittest.TestCase):
def test_wait_socket(self, slow=False): def test_wait_socket(self, slow=False):
from multiprocessing.connection import wait from multiprocessing.connection import wait
l = socket.socket() l = socket.socket()
l.bind(('', 0)) l.bind((test.support.HOST, 0))
l.listen(4) l.listen(4)
addr = ('localhost', l.getsockname()[1]) addr = l.getsockname()
readers = [] readers = []
procs = [] procs = []
dic = {} dic = {}
......
...@@ -110,7 +110,7 @@ class TimeoutTestCase(unittest.TestCase): ...@@ -110,7 +110,7 @@ class TimeoutTestCase(unittest.TestCase):
# solution. # solution.
fuzz = 2.0 fuzz = 2.0
localhost = '127.0.0.1' localhost = support.HOST
def setUp(self): def setUp(self):
raise NotImplementedError() raise NotImplementedError()
......
...@@ -289,6 +289,10 @@ IDLE ...@@ -289,6 +289,10 @@ IDLE
Tests 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 - Issue #1666318: Add a test that shutil.copytree() retains directory
permissions. Patch by Catherine Devlin. permissions. Patch by Catherine Devlin.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment