BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib64/python3.6/site-packages/tornado/__pycache__/tcpclient.cpython-36.pyc
3

	��fz/�@s�dZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
ddlmZddl
mZddlmZddlmZdd	lmZddlZdd
lmZmZmZmZmZmZmZejr�ddlmZmZdZ Gd
d�de!�Z"Gdd�de!�Z#dS)z'A non-blocking TCP connection factory.
�N)�Future�future_add_done_callback)�IOLoop)�IOStream)�gen)�Resolver)�set_close_exec)�TimeoutError)�Any�Union�Dict�Tuple�List�Callable�Iterator)�Optional�Setg333333�?c@sNeZdZdZeeeejegee	dffdd�dd�Z
eeeeeeejefeeejeffd�dd	��Ze
dfeeeejfd
d�dd
�Zeeejefdd�dd�Zeeejefejeddd�dd�Zedd�dd�Zdd�dd�Zdd�dd�Zeeejfdd�dd�Zdd�dd �Zdd�d!d"�Zdd�d#d$�ZdS)%�
_Connectora�A stateless implementation of the "Happy Eyeballs" algorithm.

    "Happy Eyeballs" is documented in RFC6555 as the recommended practice
    for when both IPv4 and IPv6 addresses are available.

    In this implementation, we partition the addresses by family, and
    make the first connection attempt to whichever address was
    returned first by ``getaddrinfo``.  If that connection fails or
    times out, we begin a connection in parallel to the first address
    of the other family.  If there are additional failures we retry
    with other addresses, keeping one connection attempt per family
    in flight at a time.

    http://tools.ietf.org/html/rfc6555

    zFuture[IOStream]N)�addrinfo�connect�returncCsRtj�|_||_t�|_d|_d|_d|_t	|�|_
|j|�\|_|_
t�|_dS)N)r�current�io_looprr�future�timeout�connect_timeout�
last_error�len�	remaining�split�
primary_addrs�secondary_addrs�set�streams)�selfrr�r%�!/usr/lib64/python3.6/tcpclient.py�__init__<s

z_Connector.__init__)rrcCsTg}g}|dd}x6|D].\}}||kr:|j||f�q|j||f�qW||fS)a�Partition the ``addrinfo`` list by address family.

        Returns two lists.  The first list contains the first entry from
        ``addrinfo`` and all others with the same family, and the
        second list contains all other addresses (normally one list will
        be AF_INET and the other AF_INET6, although non-standard resolvers
        may return additional families).
        r)�append)rZprimaryZ	secondaryZ
primary_af�af�addrr%r%r&rPsz_Connector.splitz2Future[Tuple[socket.AddressFamily, Any, IOStream]])rrrcCs2|jt|j��|j|�|dk	r,|j|�|jS)N)�try_connect�iterr �set_timeout�set_connect_timeoutr)r$rrr%r%r&�startis


z_Connector.start)�addrsrcCs�yt|�\}}Wn@tk
rP|jdkrL|jj�rL|jj|jpHtd��dSX|j||�\}}|j	j
|�t|tj
|j|||��dS)Nrzconnection failed)�next�
StopIterationrr�done�
set_exceptionr�IOErrorrr#�addr�	functools�partial�on_connect_done)r$r0r)r*�streamrr%r%r&r+tsz_Connector.try_connect)r0r)r*rrcCs�|jd8_y|j�}Wn^tk
rx}zB|jj�r:dS||_|j|�|jdk	rj|jj	|j�|j
�dSd}~XnX|j�|jj�r�|j�n&|j
j|�|jj|||f�|j�dS)N�)r�result�	Exceptionrr3rr+rr�remove_timeout�
on_timeout�clear_timeouts�closer#�discardZ
set_result�
close_streams)r$r0r)r*rr:�er%r%r&r9�s$




z_Connector.on_connect_done)rrcCs |jj|jj�||j�|_dS)N)r�add_timeout�timer?r)r$rr%r%r&r-�sz_Connector.set_timeout)rcCs$d|_|jj�s |jt|j��dS)N)rrr3r+r,r!)r$r%r%r&r?�s
z_Connector.on_timeoutcCs|jdk	r|jj|j�dS)N)rrr>)r$r%r%r&�
clear_timeout�s
z_Connector.clear_timeout)rrcCs|jj||j�|_dS)N)rrE�on_connect_timeoutr)r$rr%r%r&r.�sz_Connector.set_connect_timeoutcCs$|jj�s|jjt��|j�dS)N)rr3r4r	rC)r$r%r%r&rH�s
z_Connector.on_connect_timeoutcCs4|jdk	r|jj|j�|jdk	r0|jj|j�dS)N)rrr>r)r$r%r%r&r@�s

z_Connector.clear_timeoutscCsx|jD]}|j�qWdS)N)r#rA)r$r:r%r%r&rC�sz_Connector.close_streams)�__name__�
__module__�__qualname__�__doc__rr
r�socket�
AddressFamilyrr'�staticmethodr�_INITIAL_CONNECT_TIMEOUT�floatr�datetime�	timedeltar/rr+r9r-r?rGr.rHr@rCr%r%r%r&r*s6"rc@s�eZdZdZdedd�dd�Zdd�dd�Zejdddddfe	e
ejee
e	efejfe
e	e
eeejfed	�	d
d�Zde
ejee	e
eedfd
�dd�ZdS)�	TCPClientz�A non-blocking TCP connection factory.

    .. versionchanged:: 5.0
       The ``io_loop`` argument (deprecated since version 4.1) has been removed.
    N)�resolverrcCs(|dk	r||_d|_nt�|_d|_dS)NFT)rU�
_own_resolverr)r$rUr%r%r&r'�s
zTCPClient.__init__)rcCs|jr|jj�dS)N)rVrUrA)r$r%r%r&rA�szTCPClient.close)	�host�portr)�ssl_options�max_buffer_size�	source_ip�source_portrrc	
�s|dk	rTt|tj�r&tj�j�|}n.t|tj�rHtj�j�|j�}nt	d|��|dk	r|t
j||jj
|||��IdH}	n|jj
|||�IdH}	t|	tj|j|||d��}
|
j|d�IdH\}}}|dk	�r|dk	r�t
j||jd||d��IdH}n|jd||d�IdH}|S)a�Connect to the given host and port.

        Asynchronously returns an `.IOStream` (or `.SSLIOStream` if
        ``ssl_options`` is not None).

        Using the ``source_ip`` kwarg, one can specify the source
        IP address to use when establishing the connection.
        In case the user needs to resolve and
        use a specific interface, it has to be handled outside
        of Tornado as this depends very much on the platform.

        Raises `TimeoutError` if the input future does not complete before
        ``timeout``, which may be specified in any form allowed by
        `.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or an absolute time
        relative to `.IOLoop.time`)

        Similarly, when the user requires a certain source port, it can
        be specified using the ``source_port`` arg.

        .. versionchanged:: 4.5
           Added the ``source_ip`` and ``source_port`` arguments.

        .. versionchanged:: 5.0
           Added the ``timeout`` argument.
        NzUnsupported timeout %r)r[r\)rF)rYZserver_hostname)�
isinstance�numbersZRealrrrFrRrSZ
total_seconds�	TypeErrorrZwith_timeoutrUZresolverr7r8�_create_streamr/Z	start_tls)
r$rWrXr)rYrZr[r\rrZ	connectorr*r:r%r%r&r�s6$

zTCPClient.connectzFuture[IOStream])rZr)r*r[r\rcCs�t|t�r|nd}|}|r2|r2|tjkr.dnd}tj|�}t|j��|sP|r�y|j||f�Wn tjk
r�|j��YnXyt	||d�}	Wn6tjk
r�}
zt
�}|j|
�|	|fSd}
~
XnX|	|	j|�fSdS)Nrz::1z	127.0.0.1)rZ)
r]�intrMZAF_INET6r�filenoZbind�errorrArrr4r)r$rZr)r*r[r\Zsource_port_bindZsource_ip_bindZ
socket_objr:rDZfur%r%r&r`*s&



zTCPClient._create_stream)N)NN)rIrJrKrLrr'rArMZ	AF_UNSPEC�strrarNrrr
�sslZ
SSLContextrQrRrSrrr
r`r%r%r%r&rT�s2GrT)$rLr7rMr^rRreZtornado.concurrentrrZtornado.iolooprZtornado.iostreamrZtornadorZtornado.netutilrZtornado.platform.autorZtornado.genr	Ztypingr
rrr
rrrZ
TYPE_CHECKINGrrrP�objectrrTr%r%r%r&�<module>s($"