From ad5bad8d2074a8d709f26b6d40d3471d56fdda63 Mon Sep 17 00:00:00 2001 From: Xyphuz Date: Fri, 27 May 2022 17:37:39 +0800 Subject: [PATCH] fix: port parsing --- compose_viz/parser.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/compose_viz/parser.py b/compose_viz/parser.py index 50627f3..9ae4e86 100644 --- a/compose_viz/parser.py +++ b/compose_viz/parser.py @@ -62,7 +62,10 @@ class Parser: container_port: Optional[str] = None protocol: Optional[str] = None - if type(port_data) is str: + if type(port_data) is float: + container_port = str(int(port_data)) + host_port = f"0.0.0.0:{container_port}" + elif type(port_data) is str: regex = r"(?P\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:)?((?P\d+(\-\d+)?):)?((?P\d+(\-\d+)?))?(/(?P\w+))?" # noqa: E501 match = re.match(regex, port_data) @@ -74,10 +77,10 @@ class Parser: assert container_port, "Invalid port format, aborting." - if container_port and not host_port: + if container_port is not None and host_port is None: host_port = container_port - if host_ip: + if host_ip is not None: host_port = f"{host_ip}{host_port}" else: host_port = f"0.0.0.0:{host_port}" @@ -97,11 +100,11 @@ class Parser: host_ip = port_data.host_ip protocol = port_data.protocol - if container_port and not host_port: + if container_port is not None and host_port is None: host_port = container_port - if host_ip: - host_port = f"{host_ip}{host_port}" + if host_ip is not None: + host_port = f"{host_ip}:{host_port}" else: host_port = f"0.0.0.0:{host_port}"