U en@sddlmZddlZddlZddlmZddlmZmZej ej e e ej e e ffZejrjddlmZdd d d d Zeddfd dddddddZddddddZddddZdd ddd Zed!ZdS)") annotationsN)LocationParseError)_DEFAULT_TIMEOUT _TYPE_TIMEOUT)BaseHTTPConnectionrbool)connreturncCs|j S)z Returns True if the connection is dropped and should be closed. :param conn: :class:`urllib3.connection.HTTPConnection` object. )Z is_connected)r r E/opt/hc_python/lib/python3.8/site-packages/urllib3/util/connection.pyis_connection_droppedsrztuple[str, int]rztuple[str, int] | Nonez_TYPE_SOCKET_OPTIONS | Nonez socket.socket)addresstimeoutsource_addresssocket_optionsr c Cs:|\}}|dr|d}d}t}z|dWn&tk rZtd|ddYnXt|||tjD]}|\} } } } } d}zPt| | | }t |||t k r| ||r| || | d}|WStk r}z|}|dk r|W5d}~XYqnXqn|dk r.z|W5d}XntddS)akConnect to *address* and return the socket object. Convenience function. Connect to *address* (a 2-tuple ``(host, port)``) and return the socket object. Passing the optional *timeout* parameter will set the timeout on the socket instance before attempting to connect. If no *timeout* is supplied, the global default timeout setting returned by :func:`socket.getdefaulttimeout` is used. If *source_address* is set it must be a tuple of (host, port) for the socket to bind as a source address before making the connection. An host of '' or port 0 tells the OS to use the default. [z[]Nidna'z', label empty or too longz!getaddrinfo returns an empty list) startswithstripallowed_gai_familyencode UnicodeErrorrsocket getaddrinfo SOCK_STREAM_set_socket_optionsr settimeoutbindconnectOSErrorclose)rrrrhostporterrfamilyresafsocktypeproto canonnamesasock_r r r create_connections>         r0None)r.optionsr cCs$|dkr dS|D]}|j|qdS)N) setsockopt)r.r2optr r r r]srzsocket.AddressFamily)r cCstj}trtj}|S)zThis function is designed to work in the context of getaddrinfo, where family=socket.AF_UNSPEC is the default and will perform a DNS search for both IPv6 and IPv4 records.)rAF_INETHAS_IPV6 AF_UNSPEC)r'r r r rgsrstr)r$r cCsVd}d}tjrFz"ttj}||dfd}Wntk rDYnX|rR||S)z4Returns True if the system can bind an IPv6 address.NFrT)rhas_ipv6AF_INET6r Exceptionr#)r$r.r9r r r _has_ipv6rs r<z::1) __future__rrtyping exceptionsrrrrSequenceTupleintUnionbytesZ_TYPE_SOCKET_OPTIONS TYPE_CHECKINGZ_base_connectionrrr0rrr<r6r r r r s    B