def _has_ipv6():
    """ Returns True if the system can bind an IPv6 address."""
    sock = None
    has_ipv6 = False

    try:
        sock = socket.socket(socket.AF_INET6)
        sock.bind(("::1", 0))
        has_ipv6 = True
    except socket.error:
        pass

    if sock:
        sock.close()
    return has_ipv6
 Returns True if the system can bind an IPv6 address.
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/test/test_udp.py