Checks if the host name also contains a port and separates the two. Returns either [host] or [host, port]. Detects if host is an ipv6 address like "[::]" and removes the brackets from it.
(addr)
| 1016 | |
| 1017 | @staticmethod |
| 1018 | def __parse_host_port(addr): |
| 1019 | """Checks if the host name also contains a port and separates the two. |
| 1020 | Returns either [host] or [host, port]. Detects if host is an ipv6 address like "[::]" |
| 1021 | and removes the brackets from it. |
| 1022 | """ |
| 1023 | split_by_colon = addr.split(':') |
| 1024 | ipv6addr = len(split_by_colon) > 2 |
| 1025 | host_port = None |
| 1026 | if ipv6addr: |
| 1027 | if addr[0] == "[": |
| 1028 | parts = addr.split("]") |
| 1029 | host_port = [parts[0][1:]] |
| 1030 | has_port = parts[1] != "" |
| 1031 | if has_port: |
| 1032 | if parts[1][0] != ":": return None |
| 1033 | host_port.append(parts[1][1:]) |
| 1034 | else: |
| 1035 | host_port = [addr] |
| 1036 | else: |
| 1037 | host_port = [val for val in split_by_colon if val.strip()] |
| 1038 | # validate the connection string. |
| 1039 | if ':' in addr and len(host_port) != 2: return None |
| 1040 | return host_port |
| 1041 | |
| 1042 | def do_connect(self, args): |
| 1043 | """Connect to an Impalad instance: |