
                        (   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j                  ej                  eeej                  eef   f      Zej                   rddlmZ ddZeddd f	 	 	 	 	 	 	 	 	 	 	 dd	Z	 	 	 	 	 	 dd
ZddZddZ ed      Zy)    )annotationsN)LocationParseError   )_DEFAULT_TIMEOUT_TYPE_TIMEOUT   )BaseHTTPConnectionc                    | j                    S )z
    Returns True if the connection is dropped and should be closed.
    :param conn: :class:`urllib3.connection.HTTPConnection` object.
    )is_connected)conns    *lib/third_party/urllib3/util/connection.pyis_connection_droppedr      s    
         c                0   | \  }}|j                  d      r|j                  d      }d}t               }	 |j                  d       t        j                  |||t        j                        D ]  }	|	\  }
}}}}d}	 t        j                  |
||      }d}	 |j                  t        j                  ||       t        ||       |t        ur|j!                  |       |r|j#                  |       |j%                  |       d}|c S  |	 |t        d      # t        $ r t        d| d      dw xY w# t        $ r(}|j                  t        j                  k7  r Y d}~d}~ww xY w# t        $ r}|}||j'                          Y d}~d}~ww xY w# d}w xY w)	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)addresstimeoutsource_addresssocket_optionsgoogle_protocol_idhostporterrfamilyresafsocktypeproto	canonnamesasock_SO_GOOGLE_NET_PROTOCOL_ID	exception_s                      r   create_connectionr9      s   & JD$szz$
C
  !FQF !!$ff6H6HI-0*HeY 	==Xu5D
 *4&%%.&  n5..(		.)LLCK= JJ 	I
 9::_  Q 1TF*D!EFDPQ&  ??e&7&77 8   	C

	 CsZ   D :E&!D25AE&F D/2	E#;EE&E##E&&	F/F		FFc                6    |y |D ]  } | j                   |   y )N)r   )r5   optionsopts      r   r!   r!   m   s$      r   c                 R    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)r.   s    r   r   r   w   s     
 ^^F!!Mr   c                    d}d}t         j                  r9	 t        j                   t         j                        }|j                  | df       d}|r|j                          |S # t        $ r Y w xY w)z4Returns True if the system can bind an IPv6 address.NFr   T)r   has_ipv6AF_INET6r#   	Exceptionr%   )r+   r5   rB   s      r   	_has_ipv6rE      sf    DH	==1DIItQi H 

O  		s   8A" "	A.-A.z::1)r   r	   returnbool)r&   ztuple[str, int]r'   r   r(   ztuple[str, int] | Noner)   _TYPE_SOCKET_OPTIONS | Noner*   intrF   socket.socket)r5   rJ   r;   rH   rF   None)rF   zsocket.AddressFamily)r+   strrF   rG   )
__future__r   r   r   typingurllib3.exceptionsr   r'   r   r   SequenceTuplerI   Unionbytes_TYPE_SOCKET_OPTIONSTYPE_CHECKING_base_connectionr	   r   r9   r!   r   rE   r?    r   r   <module>rX      s    "    1 4v||Cfll3PU:>V4V'WX 	5! .-126N;N;N; +N; 0	N;
 N; N;b
"=	. Ur   