[Python-checkins] cpython (3.2): Issue #12054: use support.find_unused_port() instead of reinventing the wheel

antoine.pitrou python-checkins at python.org
Tue May 10 23:38:11 CEST 2011


http://hg.python.org/cpython/rev/695a7acae392
changeset:   70016:695a7acae392
branch:      3.2
parent:      70012:713006ecee0c
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Tue May 10 23:37:11 2011 +0200
summary:
  Issue #12054: use support.find_unused_port() instead of reinventing the wheel

files:
  Lib/test/test_socket.py |  18 ++----------------
  1 files changed, 2 insertions(+), 16 deletions(-)


diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -564,23 +564,9 @@
 
     # XXX The following don't test module-level functionality...
 
-    def _get_unused_port(self, bind_address='0.0.0.0'):
-        """Use a temporary socket to elicit an unused ephemeral port.
-
-        Args:
-            bind_address: Hostname or IP address to search for a port on.
-
-        Returns: A most likely to be unused port.
-        """
-        tempsock = socket.socket()
-        tempsock.bind((bind_address, 0))
-        host, port = tempsock.getsockname()
-        tempsock.close()
-        return port
-
     def testSockName(self):
         # Testing getsockname()
-        port = self._get_unused_port()
+        port = support.find_unused_port()
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.addCleanup(sock.close)
         sock.bind(("0.0.0.0", port))
@@ -629,7 +615,7 @@
 
     def test_getsockaddrarg(self):
         host = '0.0.0.0'
-        port = self._get_unused_port(bind_address=host)
+        port = support.find_unused_port()
         big_port = port + 65536
         neg_port = port - 65536
         sock = socket.socket()

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


More information about the Python-checkins mailing list