def parse_endpoint(endpoint): url = urlparse(endpoint) # IPV6 addresses will not work correctly with urlparse and Endpoint if we # just use netloc as default. IPV4 works with .hostname while IPV6 works # with .netloc # for example an IPV6 address like e40:92be:ab1c:c9c1:3e2e:dbf6:57c6:8922 # would evaluate to 'e40' if we used .hostname # this looks repetitive but we don't know yet if we are IPV6 try: port = url.port except ValueError: port = None if network.is_ipv6(url.netloc): port = detect_ipv6_port(url) if (sys.version_info[0], sys.version_info[1]) <= (2, 6): log.error( 'Python 2.6 does not support IPV6 addresses, cannot continue' ) log.error('host can be used instead of raw IPV6 addresses') if os.environ.get('PYTEST') is None: # don't bail on tests raise RuntimeError( 'IPV6 address was used for endpoint: %s' % endpoint ) host = normalize_netloc(url, port) else: host = url.hostname if url.scheme not in ['http', 'https']: raise exc.InvalidProtocol('invalid protocol %r' % url.scheme) if not url.hostname: raise exc.InvalidHost('no hostname in %r' % endpoint) return Endpoint(host, port, url.scheme == 'https')
def parse_endpoint(endpoint): url = urlparse(endpoint) # IPV6 addresses will not work correctly with urlparse and Endpoint if we # just use netloc as default. IPV4 works with .hostname while IPV6 works # with .netloc # for example an IPV6 address like e40:92be:ab1c:c9c1:3e2e:dbf6:57c6:8922 # would evaluate to 'e40' if we used .hostname # this looks repetitive but we don't know yet if we are IPV6 try: port = url.port except ValueError: port = None if network.is_ipv6(url.netloc): port = detect_ipv6_port(url) if (sys.version_info[0], sys.version_info[1]) <= (2, 6): log.error( 'Python 2.6 does not support IPV6 addresses, cannot continue') log.error('host can be used instead of raw IPV6 addresses') if os.environ.get('PYTEST') is None: # don't bail on tests raise RuntimeError('IPV6 address was used for endpoint: %s' % endpoint) host = normalize_netloc(url, port) else: host = url.hostname if url.scheme not in ['http', 'https']: raise exc.InvalidProtocol('invalid protocol %r' % url.scheme) if not url.hostname: raise exc.InvalidHost('no hostname in %r' % endpoint) return Endpoint(host, port, url.scheme == 'https')
def test_passes_valid_addresses_with_brackets_and_ports(self, address): assert network.is_ipv6(address) is True
def test_catches_invalid_addresses(self, address): assert network.is_ipv6(address) is False
def test_passes_valid_addresses(self, address): assert network.is_ipv6(address) is True