a
    0f%                     @   s   d dl mZ d dlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZ d	d
 ZejddfddZdd Zdd Zdd ZedZdS )    )absolute_importN   )_appengine_environ)LocationParseError)six   )NoWayToWaitForSocketErrorwait_for_readc                 C   sL   t | dd}|du rdS |du r$dS zt|ddW S  tyF   Y dS 0 dS )a$  
    Returns True if the connection is dropped and should be closed.

    :param conn:
        :class:`http.client.HTTPConnection` object.

    Note: For platforms like AppEngine, this will always return ``False`` to
    let the platform handle connection recycling transparently for us.
    sockFNTg        )timeout)getattrr	   r   )connr
    r   \/var/www/ai-form-bot/venv/lib/python3.9/site-packages/pip/_vendor/urllib3/util/connection.pyis_connection_dropped   s    
r   c                 C   s4  | \}}| dr|d}d}t }z|d W n& tyZ   ttd| d Y S 0 t	|||tj
D ]}|\}	}
}}}d}zNt|	|
|}t|| |tjur|| |r|| || |W   S  tjy } z&|}|dur |  d}W Y d}~qnd}~0 0 qn|dur&|tddS )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idnaz'%s', label empty or too longz!getaddrinfo returns an empty list)
startswithstripallowed_gai_familyencodeUnicodeErrorr   
raise_fromr   socketgetaddrinfoSOCK_STREAM_set_socket_options_GLOBAL_DEFAULT_TIMEOUT
settimeoutbindconnecterrorclose)addressr   source_addresssocket_optionshostporterrfamilyresafsocktypeproto	canonnamesar
   er   r   r   create_connection%   s>    










r1   c                 C   s$   |d u rd S |D ]}| j |  qd S )N)
setsockopt)r
   optionsoptr   r   r   r   d   s    r   c                  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)r)   r   r   r   r   l   s    r   c                 C   s`   d}d}t  rdS tjrPz"ttj}|| df d}W n tyN   Y n0 |r\|  |S )z4Returns True if the system can bind an IPv6 address.NFr   T)r   is_appengine_sandboxr   has_ipv6AF_INET6r   	Exceptionr"   )r&   r
   r9   r   r   r   	_has_ipv6w   s    r<   z::1)
__future__r   r   contribr   
exceptionsr   packagesr   waitr   r	   r   r   r1   r   r   r<   r6   r   r   r   r   <module>   s   
?