]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add 'address' keyword control binded address #2969
authoryouguanxinqing <youguanxinqing@qq.com>
Mon, 11 Jan 2021 14:35:20 +0000 (22:35 +0800)
committeryouguanxinqing <youguanxinqing@qq.com>
Mon, 11 Jan 2021 14:35:20 +0000 (22:35 +0800)
tornado/testing.py

index 98b54eabb4b0b241e002662851d8830d626d6f1c..e8d6d29edf410adcc18fe591c61095d9097d7f6d 100644 (file)
@@ -45,17 +45,17 @@ if typing.TYPE_CHECKING:
 _NON_OWNED_IOLOOPS = AsyncIOMainLoop
 
 
-def bind_unused_port(reuse_port: bool = False) -> Tuple[socket.socket, int]:
+def bind_unused_port(reuse_port: bool = False, address: str = "127.0.0.1") -> Tuple[socket.socket, int]:
     """Binds a server socket to an available port on localhost.
 
     Returns a tuple (socket, port).
 
     .. versionchanged:: 4.4
-       Always binds to ``127.0.0.1`` without resolving the name
+       Default binds to ``127.0.0.1`` without resolving the name
        ``localhost``.
     """
     sock = netutil.bind_sockets(
-        0, "127.0.0.1", family=socket.AF_INET, reuse_port=reuse_port
+        0, address, family=socket.AF_INET, reuse_port=reuse_port
     )[0]
     port = sock.getsockname()[1]
     return sock, port