o
                         @  s   d dl mZ d dlZd dlZd dlZd dlmZ ddlmZm	Z	 e
eeeejeef f  Zejr7ddlmZ d(ddZeddd fd)ddZd*ddZd+d!d"Zd,d%d&Zed'ZdS )-    )annotationsN)LocationParseError   )_DEFAULT_TIMEOUT_TYPE_TIMEOUT   )BaseHTTPConnectionconnr   returnboolc                 C  s   | j  S )z
    Returns True if the connection is dropped and should be closed.
    :param conn: :class:`urllib3.connection.HTTPConnection` object.
    )is_connected)r	    r   @/tmp/google-cloud-sdk/lib/third_party/urllib3/util/connection.pyis_connection_dropped   s   r   addresstuple[str, int]timeoutr   source_addresstuple[str, int] | Nonesocket_options_TYPE_SOCKET_OPTIONS | Nonegoogle_protocol_idintsocket.socketc                 C  sp  | \}}| dr|d}d}t }z|d W n ty*   td| ddw t|||tjD ]u}	|	\}
}}}}d}zNt|
||}d}z
|	tj
|| W n tyl } z|jtjkrb W Y d}~nd}~ww t|| |tur{|| |r|| || d}|W   S  ty } z|}|dur|  W Y d}~q4d}~ww |durz|d}w td)	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[]Nidna'z', label empty or too longib z!getaddrinfo returns an empty list)
startswithstripallowed_gai_familyencodeUnicodeErrorr   socketgetaddrinfoSOCK_STREAM
setsockopt
SOL_SOCKETOSErrorerrnoENOPROTOOPT_set_socket_optionsr   
settimeoutbindconnectclose)r   r   r   r   r   hostporterrfamilyresafsocktypeproto	canonnamesasock_SO_GOOGLE_NET_PROTOCOL_ID	exception_r   r   r   create_connection   s^   






r=   r9   optionsNonec                 C  s$   |d u rd S |D ]}| j |  qd S )N)r%   )r9   r>   optr   r   r   r*   m   s
   r*   socket.AddressFamilyc                  C  s   t j} trt 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_INETHAS_IPV6	AF_UNSPEC)r2   r   r   r   r   w   s   r   r/   strc                 C  sT   d}d}t jr"zt  t j}|| df d}W n	 ty!   Y nw |r(|  |S )z4Returns True if the system can bind an IPv6 address.NFr   T)r"   has_ipv6AF_INET6r,   	Exceptionr.   )r/   r9   rF   r   r   r   	_has_ipv6   s   rI   z::1)r	   r   r
   r   )r   r   r   r   r   r   r   r   r   r   r
   r   )r9   r   r>   r   r
   r?   )r
   rA   )r/   rE   r
   r   )
__future__r   r(   r"   typingurllib3.exceptionsr   r   r   r   listtupler   Unionbytes_TYPE_SOCKET_OPTIONSTYPE_CHECKING_base_connectionr   r   r=   r*   r   rI   rC   r   r   r   r   <module>   s&    

Q


