2017-11-29 10:42:35 +03:00
|
|
|
|
|
|
|
|
2017-08-07 07:15:35 +03:00
|
|
|
def build_endpoint_description_strings(
|
|
|
|
host=None,
|
|
|
|
port=None,
|
|
|
|
unix_socket=None,
|
|
|
|
file_descriptor=None
|
2017-11-29 10:42:35 +03:00
|
|
|
):
|
2017-08-07 07:15:35 +03:00
|
|
|
"""
|
|
|
|
Build a list of twisted endpoint description strings that the server will listen on.
|
|
|
|
This is to streamline the generation of twisted endpoint description strings from easier
|
|
|
|
to use command line args such as host, port, unix sockets etc.
|
|
|
|
"""
|
|
|
|
socket_descriptions = []
|
2018-02-02 07:12:56 +03:00
|
|
|
if host and port is not None:
|
2017-11-26 00:40:15 +03:00
|
|
|
host = host.strip("[]").replace(":", "\:")
|
|
|
|
socket_descriptions.append("tcp:port=%d:interface=%s" % (int(port), host))
|
2017-08-07 07:15:35 +03:00
|
|
|
elif any([host, port]):
|
2017-11-26 00:40:15 +03:00
|
|
|
raise ValueError("TCP binding requires both port and host kwargs.")
|
2017-08-07 07:15:35 +03:00
|
|
|
|
|
|
|
if unix_socket:
|
2017-11-26 00:40:15 +03:00
|
|
|
socket_descriptions.append("unix:%s" % unix_socket)
|
2017-08-07 07:15:35 +03:00
|
|
|
|
|
|
|
if file_descriptor is not None:
|
2017-11-26 00:40:15 +03:00
|
|
|
socket_descriptions.append("fd:fileno=%d" % int(file_descriptor))
|
2017-08-07 07:15:35 +03:00
|
|
|
|
|
|
|
return socket_descriptions
|