PEP8 compliant

This commit is contained in:
donneypr 2025-09-15 18:20:28 -04:00
commit a599cdafa3

View file

@ -271,35 +271,46 @@ class ConnectionManager(object):
return servers return servers
def _convert_endpoint_address_to_manual_address(self, info): def _convert_endpoint_address_to_manual_address(self, info):
addr = info.get("Address") addr = info.get("Address")
endpoint = info.get("EndpointAddress") endpoint = info.get("EndpointAddress")
if not addr or not endpoint: if not addr or not endpoint:
return None return None
# Getting the host from EndpointAddress checking for IPv6 formatting
# Host from EndpointAddress - IPv6 friendly
if endpoint.startswith('['): if endpoint.startswith('['):
rb = endpoint.find(']') right_bracket = endpoint.find(']')
if rb != -1: if right_bracket != -1:
host = endpoint[1:rb] host = endpoint[1:right_bracket]
else: else:
return None return None
else: else:
if endpoint.count(':') > 1: if endpoint.count(':') > 1:
# Raw IPv6
host = endpoint host = endpoint
else: else:
# IPv4 hostname strip option
host = endpoint.rsplit(':', 1)[0] if ':' in endpoint else endpoint host = endpoint.rsplit(':', 1)[0] if ':' in endpoint else endpoint
# Getting the port from the address
port = None port = None
if addr.startswith('['): if addr.startswith('['):
rb = addr.find(']') right_bracket = addr.find(']')
if rb != -1 and rb + 1 < len(addr) and addr[rb + 1] == ':': has_port = (
ps = addr[rb + 2:] right_bracket != -1
if ps.isdigit(): and right_bracket + 1 < len(addr)
port = int(ps) and addr[right_bracket + 1] == ':'
)
if has_port:
port_str = addr[right_bracket + 2:]
if port_str.isdigit():
port = int(port_str)
else: else:
# Non-bracketed: allow exactly one colon for host:port
if addr.count(':') == 1: if addr.count(':') == 1:
ps = addr.rsplit(':', 1)[1] port_str = addr.rsplit(':', 1)[1]
if ps.isdigit(): if port_str.isdigit():
port = int(ps) port = int(port_str)
if port is None: if port is None:
return None return None