U fj @ s d dl mZ d dlZd dlZddlmZ ddlmZmZ ej ej eeejee f f ZejrjddlmZ dd d ddZeddfd dddddddZddddddZddddZdd ddd Zed!ZdS )" )annotationsN )LocationParseError )_DEFAULT_TIMEOUT _TYPE_TIMEOUT)BaseHTTPConnectionr bool)connreturnc C s | j S )z Returns True if the connection is dropped and should be closed. :param conn: :class:`urllib3.connection.HTTPConnection` object. )Zis_connected)r r H/opt/alt/python38/lib/python3.8/site-packages/urllib3/util/connection.pyis_connection_dropped s r ztuple[str, int]r ztuple[str, int] | Nonez_TYPE_SOCKET_OPTIONS | Nonez socket.socket)addresstimeoutsource_addresssocket_optionsr c C s: | \}}| dr|d}d}t }z|d W n& tk rZ td| ddY nX t|||tjD ]}|\} } }}} d}zPt| | |}t || |t k r|| |r|| | | d}|W S tk r } z|}|dk r| W 5 d}~X Y qnX qn|dk r.z|W 5 d}X ntddS )ak Connect 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_familyencodeUnicodeErrorr socketgetaddrinfoSOCK_STREAM_set_socket_optionsr settimeoutbindconnectOSErrorclose)r r r r hostporterrfamilyresafsocktypeproto canonnamesasock_r r r create_connection s> r0 None)r. optionsr c C s$ |d krd S |D ]}| j | qd S )N) setsockopt)r. r2 optr r r r ] s r zsocket.AddressFamily)r c C s t j} trt j} | 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.)r AF_INETHAS_IPV6 AF_UNSPEC)r' r r r r g s r str)r$ r c C sV d}d}t jrFz"t t j}|| df d}W n tk rD Y nX |rR| |S )z4Returns True if the system can bind an IPv6 address.NFr T)r has_ipv6AF_INET6r Exceptionr# )r$ r. r9 r r r _has_ipv6r s r<