Path: blob/main/python/python-wasm/data/pip/scratch.py
1067 views
"""12"""34import socket56def _set_socket_options(sock, options):7if options is None:8return910for opt in options:11sock.setsockopt(*opt)121314def f(address):15timeout = 516socket_options = [(6, 1, 1)]1718host, port = address19if host.startswith("["):20host = host.strip("[]")21err = None2223# Using the value from allowed_gai_family() in the context of getaddrinfo lets24# us select whether to work with IPv4 DNS records, IPv6 records, or both.25# The original create_connection function always returns all records.26family = socket.AF_INET2728host.encode("idna")2930for res in socket.getaddrinfo("pypi.org", 443, family, socket.SOCK_STREAM):31print("res = ", res)32af, socktype, proto, canonname, sa = res33sock = socket.socket(af, socktype, proto)34_set_socket_options(sock, socket_options)35sock.settimeout(timeout)36print("sock.connect(sa) ", sock, sa)37sock.connect(sa)38print("connected!", sock)39return sock404142f(['pypy.org', 443])434445