Simplify is_port_free(), as discussed in the code review.
diff --git a/src/portpicker.py b/src/portpicker.py
index f5315cd..08dde0a 100644
--- a/src/portpicker.py
+++ b/src/portpicker.py
@@ -97,8 +97,7 @@
Returns:
boolean, whether it is free to use for both TCP and UDP
"""
- return (bind(port, _PROTOS[0][0], _PROTOS[0][1]) and
- bind(port, _PROTOS[1][0], _PROTOS[1][1]))
+ return bind(port, *_PROTOS[0]) and bind(port, *_PROTOS[1])
IsPortFree = is_port_free # legacy API. pylint: disable=invalid-name
diff --git a/src/portserver.py b/src/portserver.py
index 493f45f..fcade6c 100644
--- a/src/portserver.py
+++ b/src/portserver.py
@@ -58,6 +58,7 @@
return 0
+# TODO: Consider importing portpicker.bind() instead of duplicating the code.
def _bind(port, socket_type, socket_proto):
"""Try to bind to a socket of the specified type, protocol, and port.
@@ -101,8 +102,7 @@
Returns:
boolean, whether it is free to use for both TCP and UDP
"""
- return (_bind(port, _PROTOS[0][0], _PROTOS[0][1]) and
- _bind(port, _PROTOS[1][0], _PROTOS[1][1]))
+ return _bind(port, *_PROTOS[0]) and _bind(port, *_PROTOS[1])
def _should_allocate_port(pid):