MCPcopy
hub / github.com/urllib3/urllib3 / is_ipaddress

Function is_ipaddress

src/urllib3/util/ssl_.py:437–447  ·  view source on GitHub ↗

Detects whether the hostname given is an IPv4 or IPv6 address. Also detects IPv6 addresses with Zone IDs. :param str hostname: Hostname to examine. :return: True if the hostname is an IP address, False otherwise.

(hostname: str | bytes)

Source from the content-addressed store, hash-verified

435
436
437def is_ipaddress(hostname: str | bytes) -> bool:
438 """Detects whether the hostname given is an IPv4 or IPv6 address.
439 Also detects IPv6 addresses with Zone IDs.
440
441 :param str hostname: Hostname to examine.
442 :return: True if the hostname is an IP address, False otherwise.
443 """
444 if isinstance(hostname, bytes):
445 # IDN A-label bytes are ASCII compatible.
446 hostname = hostname.decode("ascii")
447 return bool(_IPV4_RE.match(hostname) or _BRACELESS_IPV6_ADDRZ_RE.match(hostname))
448
449
450def _is_key_file_encrypted(key_file: str) -> bool:

Callers 2

_match_hostnameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected