Joins a hostname and port together. This is a minimal implementation intended to cope with IPv6 literals. For example, _join_host_port('::1', 80) == '[::1]:80'. Args: host: hostname or IP port: port number
(host: str, port: int)
| 95 | |
| 96 | |
| 97 | def join_host_port(host: str, port: int) -> str: |
| 98 | """Joins a hostname and port together. |
| 99 | |
| 100 | This is a minimal implementation intended to cope with IPv6 literals. For |
| 101 | example, _join_host_port('::1', 80) == '[::1]:80'. |
| 102 | |
| 103 | Args: |
| 104 | host: hostname or IP |
| 105 | port: port number |
| 106 | """ |
| 107 | if ":" in host and not host.startswith("["): |
| 108 | return f"[{host}]:{port}" |
| 109 | return f"{host}:{port}" |
| 110 | |
| 111 | |
| 112 | def is_connectable(port: int, host: str | None = "localhost") -> bool: |
nothing calls this directly
no outgoing calls
no test coverage detected