MCPcopy
hub / github.com/urllib3/urllib3 / _has_ipv6

Function _has_ipv6

dummyserver/socketserver.py:58–78  ·  view source on GitHub ↗

Returns True if the system can bind an IPv6 address.

(host: str)

Source from the content-addressed store, hash-verified

56
57
58def _has_ipv6(host: str) -> bool:
59 """Returns True if the system can bind an IPv6 address."""
60 sock = None
61 has_ipv6 = False
62
63 if socket.has_ipv6:
64 # has_ipv6 returns true if cPython was compiled with IPv6 support.
65 # It does not tell us if the system has IPv6 support enabled. To
66 # determine that we must bind to an IPv6 address.
67 # https://github.com/urllib3/urllib3/pull/611
68 # https://bugs.python.org/issue658327
69 try:
70 sock = socket.socket(socket.AF_INET6)
71 sock.bind((host, 0))
72 has_ipv6 = _resolves_to_ipv6("localhost")
73 except Exception:
74 pass
75
76 if sock:
77 sock.close()
78 return has_ipv6
79
80
81# Some systems may have IPv6 support but DNS may not be configured

Callers 1

socketserver.pyFile · 0.70

Calls 2

_resolves_to_ipv6Function · 0.85
closeMethod · 0.45

Tested by

no test coverage detected