Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccc87b5

Browse files
committed
Issue #12054: use support.find_unused_port() instead of reinventing the wheel
1 parent 1be815a commit ccc87b5

1 file changed

Lines changed: 2 additions & 16 deletions

File tree

Lib/test/test_socket.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -564,23 +564,9 @@ def testStringToIPv6(self):
564564

565565
# XXX The following don't test module-level functionality...
566566

567-
def _get_unused_port(self, bind_address='0.0.0.0'):
568-
"""Use a temporary socket to elicit an unused ephemeral port.
569-
570-
Args:
571-
bind_address: Hostname or IP address to search for a port on.
572-
573-
Returns: A most likely to be unused port.
574-
"""
575-
tempsock = socket.socket()
576-
tempsock.bind((bind_address, 0))
577-
host, port = tempsock.getsockname()
578-
tempsock.close()
579-
return port
580-
581567
def testSockName(self):
582568
# Testing getsockname()
583-
port = self._get_unused_port()
569+
port = support.find_unused_port()
584570
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
585571
self.addCleanup(sock.close)
586572
sock.bind(("0.0.0.0", port))
@@ -629,7 +615,7 @@ def testNewAttributes(self):
629615

630616
def test_getsockaddrarg(self):
631617
host = '0.0.0.0'
632-
port = self._get_unused_port(bind_address=host)
618+
port = support.find_unused_port()
633619
big_port = port + 65536
634620
neg_port = port - 65536
635621
sock = socket.socket()

0 commit comments

Comments
 (0)