o
    ûÞh\  ã                   @  s¬   d dl m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r3ddlmZ d&dd„Ze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   úW/var/www/html/premium_crap/venv/lib/python3.10/site-packages/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úsocket.socketc                 C  s$  | \}}|  d¡r| d¡}d}tƒ }z| d¡ W n ty*   td|› d�ƒd‚w t |||tj¡D ]O}|\}	}
}}}d}z(t |	|
|¡}t	||ƒ |t
urU| |¡ |r\| |¡ | |¡ d}|W   S  tyƒ } z|}|dury| ¡  W Y d}~q4d}~ww |durŽz|‚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 longz!getaddrinfo returns an empty list)Ú
startswithÚstripÚallowed_gai_familyÚencodeÚUnicodeErrorr   ÚsocketÚgetaddrinfoÚSOCK_STREAMÚ_set_socket_optionsr   Ú
settimeoutÚbindÚconnectÚOSErrorÚclose)r   r   r   r   ÚhostÚportÚerrÚfamilyÚresÚafÚsocktypeÚprotoÚ	canonnameÚsaÚsockÚ_r   r   r   Úcreate_connection   sD   

ÿ




€ýr5   r3   ÚoptionsÚNonec                 C  s$   |d u rd S |D ]}| j |Ž  qd S )N)Ú
setsockopt)r3   r6   Úoptr   r   r   r#   ]   s
   ÿr#   úsocket.AddressFamilyc                  C  s   t j} trt j} | S )z³This 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   g   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)   r3   r?   r   r   r   Ú	_has_ipv6r   s   ÿrB   z::1)r	   r   r
   r   )
r   r   r   r   r   r   r   r   r
   r   )r3   r   r6   r   r
   r7   )r
   r:   )r)   r>   r
   r   )Ú
__future__r   r    ÚtypingÚ
exceptionsr   r   r   r   ÚlistÚtupleÚintÚUnionÚbytesÚ_TYPE_SOCKET_OPTIONSÚTYPE_CHECKINGÚ_base_connectionr   r   r5   r#   r   rB   r<   r   r   r   r   Ú<module>   s"    
ü
B


