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__/simple_httpclient.cpython-36.pyc
3

	��f�k�@s�ddlmZddlmZddlmZmZmZmZm	Z	m
Z
ddlmZddlm
Z
mZddlmZddlmZmZddlmZmZmZmZdd	lmZdd
lmZddlZddlZddlZddl Z ddl!Z!ddl"Z"ddl#Z#ddl$Z$ddl%Z%ddl&m'Z'ddl(Z)dd
l*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddl*Z*e*j3�rLddl*m4Z4m5Z5m6Z6Gdd�de�Z7Gdd�de�Z8Gdd�de�Z9Gdd�dej:�Z;e<dk�r�ej=e9�e�dS)�)�_unicode)�gen)�HTTPResponse�	HTTPError�AsyncHTTPClient�main�
_RequestProxy�HTTPRequest)�httputil)�HTTP1Connection�HTTP1ConnectionParameters)�IOLoop)�StreamClosedError�IOStream)�Resolver�OverrideResolver�_client_ssl_defaults�is_valid_ip)�gen_log)�	TCPClientN)�BytesIO)�Dict�Any�Callable�Optional�Type�Union)�
TracebackType)�Deque�Tuple�Listcs6eZdZdZedd��fdd�Zed�dd�Z�ZS)	�HTTPTimeoutErrorz�Error raised by SimpleAsyncHTTPClient on timeout.

    For historical reasons, this is a subclass of `.HTTPClientError`
    which simulates a response code of 599.

    .. versionadded:: 5.1
    N)�message�returncstt|�jd|d�dS)NiW)r")�superr!�__init__)�selfr")�	__class__��)/usr/lib64/python3.6/simple_httpclient.pyr%5szHTTPTimeoutError.__init__)r#cCs
|jpdS)N�Timeout)r")r&r(r(r)�__str__8szHTTPTimeoutError.__str__)�__name__�
__module__�__qualname__�__doc__�strr%r+�
__classcell__r(r()r'r)r!,sr!cs6eZdZdZedd��fdd�Zed�dd�Z�ZS)	�HTTPStreamClosedErroraZError raised by SimpleAsyncHTTPClient when the underlying stream is closed.

    When a more specific exception is available (such as `ConnectionResetError`),
    it may be raised instead of this one.

    For historical reasons, this is a subclass of `.HTTPClientError`
    which simulates a response code of 599.

    .. versionadded:: 5.1
    N)r"r#cstt|�jd|d�dS)NiW)r")r$r2r%)r&r")r'r(r)r%HszHTTPStreamClosedError.__init__)r#cCs
|jpdS)Nz
Stream closed)r")r&r(r(r)r+KszHTTPStreamClosedError.__str__)r,r-r.r/r0r%r+r1r(r()r'r)r2<s
r2c
s�eZdZdZdeeeefeeeeefeedd��fdd�
Z	dd��fd	d
�Z
eee
gdfdd�dd
�Zdd�dd�Zed�dd�Zeegdfee
gdfdd�dd�Zedd�dd�Zedd�dd�Zdeedd�dd�Z�ZS)�SimpleAsyncHTTPClientaiNon-blocking HTTP client with no external dependencies.

    This class implements an HTTP 1.1 client on top of Tornado's IOStreams.
    Some features found in the curl-based AsyncHTTPClient are not yet
    supported.  In particular, proxies are not supported, connections
    are not reused, and callers cannot select the network interface to be
    used.
    �
N�@)�max_clients�hostname_mapping�max_buffer_size�resolver�defaults�max_header_size�
max_body_sizer#cs�tt|�j|d�||_tj�|_i|_i|_||_	||_
||_|rR||_d|_
nt�|_d|_
|dk	rxt|j|d�|_t|jd�|_dS)aCreates a AsyncHTTPClient.

        Only a single AsyncHTTPClient instance exists per IOLoop
        in order to provide limitations on the number of pending connections.
        ``force_instance=True`` may be used to suppress this behavior.

        Note that because of this implicit reuse, unless ``force_instance``
        is used, only the first call to the constructor actually uses
        its arguments. It is recommended to use the ``configure`` method
        instead of the constructor to ensure that arguments take effect.

        ``max_clients`` is the number of concurrent requests that can be
        in progress; when this limit is reached additional requests will be
        queued. Note that time spent waiting in this queue still counts
        against the ``request_timeout``.

        ``hostname_mapping`` is a dictionary mapping hostnames to IP addresses.
        It can be used to make local DNS changes when modifying system-wide
        settings like ``/etc/hosts`` is not possible or desirable (e.g. in
        unittests).

        ``max_buffer_size`` (default 100MB) is the number of bytes
        that can be read into memory at once. ``max_body_size``
        (defaults to ``max_buffer_size``) is the largest response body
        that the client will accept.  Without a
        ``streaming_callback``, the smaller of these two limits
        applies; with a ``streaming_callback`` only ``max_body_size``
        does.

        .. versionchanged:: 4.2
           Added the ``max_body_size`` argument.
        )r:FTN)r9�mapping)r9)r$r3�
initializer6�collections�deque�queue�active�waitingr8r;r<r9�own_resolverrrr�
tcp_client)r&r6r7r8r9r:r;r<)r'r(r)r>Ys"*
z SimpleAsyncHTTPClient.initialize)r#cs,tt|�j�|jr|jj�|jj�dS)N)r$r3�closerDr9rE)r&)r'r(r)rF�s
zSimpleAsyncHTTPClient.close)�request�callbackr#cCs�t�}|jj|||f�t|j�|jkst|jdk	s6t�|jdk	sDt�|j	j
|j	j�t|j|j�t
j|j|d��}nd}|||f|j|<|j�|jr�tjdt|j�t|j�f�dS)Nzin request queuezImax_clients limit reached, request queued. %d active, %d queued requests.)�objectrA�append�lenrBr6�connect_timeout�AssertionError�request_timeout�io_loop�add_timeout�time�min�	functools�partial�_on_timeoutrC�_process_queuer�debug)r&rGrH�key�timeout_handler(r(r)�
fetch_impl�s z SimpleAsyncHTTPClient.fetch_implcCspxj|jrjt|j�|jkrj|jj�\}}}||jkr4q|j|�||f|j|<tj|j	|�}|j
|||�qWdS)N)rArKrBr6�popleftrC�_remove_timeoutrSrT�_release_fetch�_handle_request)r&rXrGrH�release_callbackr(r(r)rV�s

z$SimpleAsyncHTTPClient._process_queuecCstS)N)�_HTTPConnection)r&r(r(r)�_connection_class�sz'SimpleAsyncHTTPClient._connection_class)rGr_�final_callbackr#c	Cs&|j�|||||j|j|j|j�dS)N)rar8rEr;r<)r&rGr_rbr(r(r)r^�sz%SimpleAsyncHTTPClient._handle_request)rXr#cCs|j|=|j�dS)N)rBrV)r&rXr(r(r)r]�sz$SimpleAsyncHTTPClient._release_fetchcCs:||jkr6|j|\}}}|dk	r.|jj|�|j|=dS)N)rCrO�remove_timeout)r&rXrGrHrYr(r(r)r\�s

z%SimpleAsyncHTTPClient._remove_timeout)rX�infor#cCsn|j|\}}}|jj|||f�|r0dj|�nd}t|dt|�|jj�|jd�}|jj	||�|j|=dS)z�Timeout callback of request.

        Construct a timeout HTTPResponse when a timeout occurs.

        :arg object key: A simple object to mark the request.
        :info string key: More detailed timeout information.
        zTimeout {0}r*iW)�error�request_timeN)
rCrA�remove�formatrr!rOrQ�
start_time�add_callback)r&rXrdrGrHrY�
error_messageZtimeout_responser(r(r)rU�sz!SimpleAsyncHTTPClient._on_timeout)r4Nr5NNNN)N)r,r-r.r/�intrr0rrr>rFr	rrrZrV�typerar^rIr]r\rUr1r(r()r'r)r3Os* =

r3c
@sjeZdZedddddddg�Zeeeegdfee	gdfe
ee
e
dd	�	d
d�Zdd�d
d�Z
eedeeefejfd�dd�Zd4edd�dd�Zdd�dd�Zeed�dd�Zedd�dd�Zdd�dd�Ze	dd�d d!�Zd"eeeeed#�d$d%�Z dd�d&d'�Z!ee"j#e"j$fe"j%dd(�d)d*�Z&ed�d+d,�Z'dd�d-d.�Z(dd�d/d0�Z)e*dd1�d2d3�Z+dS)5r`�GETZHEAD�POST�PUTZDELETE�PATCHZOPTIONSN)	�clientrGr_rbr8rEr;r<r#c		Cs�tj�|_|jj�|_tj�|_||_||_||_||_	||_
||_||_||_
d|_d|_g|_d|_d|_d|_tj�jtj|j��dd��dS)NcSs|j�S)N)�result)�fr(r(r)�<lambda>sz*_HTTPConnection.__init__.<locals>.<lambda>)r
ZcurrentrOrQri�start_wall_timerrrGr_rbr8rEr;r<�code�headers�chunksZ
_decompressor�_timeout�	_sockaddrZ
add_futurerZconvert_yielded�run)	r&rrrGr_rbr8rEr;r<r(r(r)r%s&

z_HTTPConnection.__init__)r#c�s��y�tjjt|jj��|_|jjd-kr6td|jj��|jj	}d|krV|j
d�\}}}tj|�\}}|dkr�|jjdkr|dnd}t
jd|�r�|dd.�}||_|jjd	kr�tj}ntj}|j|jj�}d}|jj�r�t|jj�r�|jj}ntd
|jjf��t|jj|jj�}	|	�r�|jj|j|	tj|jd��|_ |j!j"|||||j#|d�IdH}
|j$dk�rl|
j%�dS|
|_&|j&j'|j(�|j)�|j$dk�r�dS|jj�r�|jj|j|jjtj|jd
��|_ |jj*|j+k�r�|jj,�r�t-d|jj*��x*d/D]"}t.|j|d��r�t/d|���q�Wd|jj0k�r8d|jj0d<d|jj0k�r�d|jj	k�rp|jj	j
d�d0|jj0d<n|jj	|jj0d<d1\}}
|jj1dk	�r�|jj1|jj2}}
n$|jj3dk	�r�|jj3}|jj4�p�d}
|dk	�r$|
dk	�s�t5�|jj6d2k�rtd|jj6��dtt7j8tj9||
���|jj0d<|jj:�r>|jj:|jj0d<|jj,�s�|jj*d3k}|jj;dk	�pl|jj<dk	}|�r||�s�|�r�|�r�td!|�r�d"nd|jj*f��|jj=�r�d#|jj0d$<|jj;dk	�r�t>t?|jj;��|jj0d%<|jj*dk�rd&|jj0k�rd'|jj0d&<|jj@�r"d(|jj0d)<|jjA�p.d*|jjB�rDd+|jjBnd}|jC|
�|_DtjE|jj*|d�}|jDjF||jj0�|jj=�r�|jDjG|�IdHn|jHd,�IdHWn(tIk
�r�|jJtKjL���s΂YnXdS)4N�http�httpszUnsupported url scheme: %s�@i��Pz^\[.*\]$�Fz?Unrecognized IPv4 or IPv6 address for network_interface, got %rzwhile connecting)�af�ssl_optionsr8�	source_ipzduring requestzunknown method %s�
proxy_host�
proxy_port�proxy_username�proxy_password�proxy_auth_modez%s not supportedZ
ConnectionrF�Host��basiczunsupported auth_mode %szBasic Z
Authorizationz
User-AgentrorqrpzLBody must %sbe None for method %s (unless allow_nonstandard_methods is true)znot z100-continueZExpectzContent-LengthzContent-Typez!application/x-www-form-urlencodedZgzipzAccept-Encoding�/�?T)r}r~���)r�r�r�r�r�r�)NN)Nr�)rorqrp)M�urllib�parseZurlsplitrrG�urlZparsed�scheme�
ValueError�netloc�
rpartitionr
Zsplit_host_and_port�re�matchZparsed_hostnameZ
allow_ipv6�socketZAF_INETZ	AF_UNSPEC�_get_ssl_optionsZnetwork_interfacerrRrLrNrOrPrirSrTrUrzrEZconnectr8rbrF�streamZset_close_callback�on_connection_closer\�method�_SUPPORTED_METHODSZallow_nonstandard_methods�KeyError�getattr�NotImplementedErrorrx�username�passwordZ
auth_usernameZ
auth_passwordrMZ	auth_mode�base64Z	b64encodeZencode_username_passwordZ
user_agent�body�
body_producer�expect_100_continuer0rK�decompress_response�pathZquery�_create_connection�
connection�RequestStartLineZ
write_headers�
read_response�_write_body�	Exception�_handle_exception�sys�exc_info)r&r�Zuserpass�_�hostZportr�r�r�Ztimeoutr�rXr�r�Z
body_expectedZbody_presentZreq_pathZ
start_liner(r(r)r|!s�








z_HTTPConnection.run)r�r#cCs�|dkr�|jjdk	r|jjS|jjrL|jjdkrL|jjdkrL|jjdkrLtStjtj	j
|jjd�}|jjsxd|_tj|_
|jjdk	r�|j|jj|jj�ttd�r�|jtjO_|SdS)Nr~)ZcafileF�OP_NO_COMPRESSION)rGr�Z
validate_certZca_certsZclient_certZ
client_keyr�sslZcreate_default_contextZPurposeZSERVER_AUTHZcheck_hostnameZ	CERT_NONEZverify_modeZload_cert_chain�hasattrZoptionsr�)r&r�Zssl_ctxr(r(r)r��s(
z _HTTPConnection._get_ssl_options)rdr#cCs8d|_|rdj|�nd}|jdk	r4|jtt|�d�dS)z�Timeout callback of _HTTPConnection instance.

        Raise a `HTTPTimeoutError` when a timeout occurs.

        :info string key: More detailed timeout information.
        NzTimeout {0}r*)rzrhrbr�r!)r&rdrkr(r(r)rU�s

z_HTTPConnection._on_timeoutcCs"|jdk	r|jj|j�d|_dS)N)rzrOrc)r&r(r(r)r\�s
z_HTTPConnection._remove_timeout)r�r#c	Cs6|jd�t|dtd|j|jt|jj�d�|j�}|S)NT)Z
no_keep_aliver;r<Z
decompress)	Zset_nodelayrrr;r<�boolrGr�r{)r&r�r�r(r(r)r��s
z"_HTTPConnection._create_connection)�
start_readr#c�s�|jjdk	r|jj|jj�n.|jjdk	rL|jj|jj�}|dk	rL|IdH|jj�|r�y|jj|�IdHWn$tk
r�|jt	j
��s��YnXdS)N)rGr�r��writer��finishr�rr�r�r�)r&r��futr(r(r)r��s

z_HTTPConnection._write_bodycCs |jdk	r|j}d|_|�dS)N)r_)r&r_r(r(r)�_releases
z_HTTPConnection._release)�responser#cCs0|j�|jdk	r,|j}d|_|jj||�dS)N)r�rbrOrj)r&r�rbr(r(r)�
_run_callbacks

z_HTTPConnection._run_callbackzOptional[Type[BaseException]])�typ�value�tbr#cCs�|jrr|j�t|t�r2|jdkr,td�}n|j}|jt|jd||j	j
�|j|jd��t
|d�rn|jj�dSt|t�SdS)Nz
Stream closediW)rerfrir�T)rbr\�
isinstancerZ
real_errorr2r�rrGrOrQrirvr�r�rF)r&r�r�r�r(r(r)r�s"




z!_HTTPConnection._handle_exceptioncCsR|jdk	rNd}|jjr|jj�yt|��Wn"tk
rL|jtj��YnXdS)NzConnection closed)rbr�rer2r�r�r�)r&r"r(r(r)r�<s
z#_HTTPConnection.on_connection_close)�
first_linerxr#c�s�t|tj�st�|jjr6|jdkr6|jd�IdHdS|j|_|j|_||_	|j
�rXdS|jjdk	r�|jjd|�x*|j	j�D]\}}|jjd||f�q�W|jjd�dS)N�dFz
%s %s %s
z%s: %s
z
)
r�r
�ResponseStartLinerMrGr�rwr��reasonrx�_should_follow_redirectZheader_callbackZget_all)r&r�rx�k�vr(r(r)�headers_receivedFsz _HTTPConnection.headers_receivedcCsL|jjrH|jjdk	st�|jd	koF|jjdkoF|jdk	oF|jjd�dk	SdS)
N�-�.�/�3�4r�LocationF)r�r�r�r�r�)rGZfollow_redirects�
max_redirectsrMrwrx�get)r&r(r(r)r�]s

z'_HTTPConnection._should_follow_redirectcs�|jdk	st�dj|j�}|j�t|jd|j�}|j��r&t|jt	�sLt�t
j
|jj�}tjj
|jj|jd�|_|jjd|_|jd=|jdkr�|jjd	kr�d
|_d|_x0dD](}y|jj|=Wq�tk
r�Yq�Xq�W||_|j�d|_|j�|jj|dd�}|j�fdd��|j�dS|jj�r8t�}nt|�}t||jt|dd�|j|jj�|j |j!||jjd�}|j"|�|j�dS)N��original_requestr�r�r��-�.�/rorn�Content-Length�Content-Type�Content-Encoding�Transfer-EncodingF)Zraise_errorcs�|j��S)N)rs)rt)rbr(r)ru�sz(_HTTPConnection.finish.<locals>.<lambda>r�)r�rxrfri�bufferZ
effective_url)r�r�r�)r�r�r�r�)#rwrM�joinryr\r�rGr�r�r�copyr�r�Zurljoinr�rxr�r�r�r�r�rbr�rrZfetchZadd_done_callback�_on_end_request�streaming_callbackrrrOrQrirvr�)r&�datar�Znew_request�hr�r�r�r()rbr)r�hsZ




z_HTTPConnection.finishcCs|jj�dS)N)r�rF)r&r(r(r)r��sz_HTTPConnection._on_end_request)�chunkr#cCs6|j�rdS|jjdk	r&|jj|�n|jj|�dS)N)r�rGr�ryrJ)r&r�r(r(r)�
data_received�s
z_HTTPConnection.data_received)N),r,r-r.�setr�rr3r	rrrlrr%r|r0rrrr�Z
SSLContextr�rUr\rrr�r�r�r�r��
BaseExceptionrr�r�r
r�r�ZHTTPHeadersr�r�r�r��bytesr�r(r(r(r)r`�sB
"	=r`�__main__)>Ztornado.escaperZtornadorZtornado.httpclientrrrrrr	r
Ztornado.http1connectionrrZtornado.ioloopr
Ztornado.iostreamrrZtornado.netutilrrrrZtornado.logrZtornado.tcpclientrr�r?r�rSr�r�r�r�rQ�iorZurllib.parser�Ztypingrrrrrr�typesrZ
TYPE_CHECKINGrrr r!r2r3ZHTTPMessageDelegater`r,Z	configurer(r(r(r)�<module>sH  -: