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

	��f9^�@sdZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddl	mZddlm
Z
mZddlmZmZmZmZmZddlmZdd	lmZmZmZmZddlZejr�dd
lmZmZmZej d�Z!Gdd
�d
e�Z"Gdd�de�Z#e$dk�rej%e"�e�dS)z5Non-blocking HTTP client implementation using pycurl.�N)�BytesIO)�httputil)�ioloop)�utf8�
native_str)�HTTPRequest�HTTPResponse�	HTTPError�AsyncHTTPClient�main)�app_log)�Dict�Any�Callable�Union)�Deque�Tuple�Optionalztornado.curl_httpclientcsReZdZd.eeeefdd��fdd�
Zdd��fdd�Ze	e
egdfdd	�d
d�Zeeee
dd�d
d�Zedd�dd�Zeedd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zdd�dd�Zd/ejeedd�dd�Zedd �d!d"�Zejd�d#d$�Zeje	eejdd%�d&d'�Zeje
egdfe
dd(�d)d*�Zeedd+�d,d-�Z�Z S)0�CurlAsyncHTTPClient�
N)�max_clients�defaults�returncs�tt��j|d�tj��_�jjtj�j��jjtj	�j
��fdd�t|�D��_�jdd��_
tj��_i�_d�_tj�jd��_�jj�tj�}�jj|��jj|�dS)N)rcsg|]}�j��qS�)�_curl_create)�.0�i)�selfr�'/usr/lib64/python3.6/curl_httpclient.py�
<listcomp>8sz2CurlAsyncHTTPClient.initialize.<locals>.<listcomp>i�)�superr�
initialize�pycurlZ	CurlMulti�_multi�setoptZM_TIMERFUNCTION�_set_timeoutZM_SOCKETFUNCTION�_handle_socket�range�_curls�
_free_list�collections�deque�	_requests�_fds�_timeoutrZPeriodicCallback�_handle_force_timeout�_force_timeout_callback�start�Curl�
add_handle�
remove_handle)rrrZdummy_curl_handle)�	__class__)rrr!1s


zCurlAsyncHTTPClient.initialize)rcsb|jj�|jdk	r"|jj|j�x|jD]}|j�q*W|jj�tt	|�j�d|_d|_dS)N)
r0�stopr.�io_loop�remove_timeoutr(�closer#r r)r�curl)r5rrr9Rs


zCurlAsyncHTTPClient.close)�request�callbackrcCs.|jj|||jj�f�|j�|jd�dS)Nr)r,�appendr7�time�_process_queuer%)rr;r<rrr�
fetch_implaszCurlAsyncHTTPClient.fetch_impl)�event�fd�multi�datarc	Cs�tjtjjtjtjjtjtjjtj	tjjtjjBi}|tj
kr^||jkr�|jj
|�|j|=n:||}||jkr||jj
|�|jj||j|�||j|<dS)z_Called by libcurl when it wants to change the file descriptors
        it cares about.
        N)r"Z	POLL_NONEr�IOLoopZNONEZPOLL_IN�READZPOLL_OUT�WRITEZ
POLL_INOUTZPOLL_REMOVEr-r7Zremove_handlerZadd_handler�_handle_events)rrArBrCrDZ	event_mapZioloop_eventrrrr&hs





	
z"CurlAsyncHTTPClient._handle_socket)�msecsrcCs<|jdk	r|jj|j�|jj|jj�|d|j�|_dS)z(Called by libcurl to schedule a timeout.Ng@�@)r.r7r8Zadd_timeoutr>�_handle_timeout)rrIrrrr%�s
z CurlAsyncHTTPClient._set_timeout)rB�eventsrcCs�d}|tjj@r|tjO}|tjj@r0|tjO}xVy|jj||�\}}Wn.tj	k
rv}z|j
d}WYdd}~XnX|tjkr2Pq2W|j�dS)zXCalled by IOLoop when there is activity on one of our
        file descriptors.
        rN)
rrErFr"Z
CSELECT_INrGZCSELECT_OUTr#�
socket_action�error�args�E_CALL_MULTI_PERFORM�_finish_pending_requests)rrBrK�action�ret�num_handles�errrrH�s


z"CurlAsyncHTTPClient._handle_eventscCs�d|_xXy|jjtjd�\}}Wn.tjk
rN}z|jd}WYdd}~XnX|tjkrPqW|j�|jj	�}|dkr�|j
|�dS)z7Called by IOLoop when the requested timeout has passed.Nr)r.r#rLr"ZSOCKET_TIMEOUTrMrNrOrPZtimeoutr%)rrRrSrTZnew_timeoutrrrrJ�s

z#CurlAsyncHTTPClient._handle_timeoutcCs`xRy|jj�\}}Wn.tjk
rB}z|jd}WYdd}~XnX|tjkrPqW|j�dS)zpCalled by IOLoop periodically to ask libcurl to process any
        events it may have forgotten about.
        rN)r#Z
socket_allr"rMrNrOrP)rrRrSrTrrrr/�s
z)CurlAsyncHTTPClient._handle_force_timeoutcCsfxX|jj�\}}}x|D]}|j|�qWx |D]\}}}|j|||�q0W|dkrPqW|j�dS)zbProcess any requests that were completed by the last
        call to multi.socket_action.
        rN)r#Z	info_read�_finishr?)rZnum_qZok_listZerr_listr:Zerrnum�errmsgrrrrP�s
z,CurlAsyncHTTPClient._finish_pending_requestscCs�x�d}x�|jr�|jr�|d7}|jj�}|jj�\}}}tj�t�|||tj�|jj	�j�d�|_
y |j|||j
d|j
d�Wn@tk
r�}z$|jj
|�|t|d|d��WYdd}~XqX|jj|�qW|sPqWdS)Nr�)�headers�bufferr;r<�queue_start_time�curl_start_time�curl_start_ioloop_timerYrXiW)r;�coderM)r)r,�pop�popleftr�HTTPHeadersrr>r7Zcurrent�info�_curl_setup_request�	Exceptionr=rr#r3)rZstartedr:r;r<rZrTrrrr?�s,
	$z"CurlAsyncHTTPClient._process_queue)r:�
curl_error�curl_messagerc
Csd|j}d|_|jj|�|jj|�|d}|rj|dk	s<t�t||�}|dk	sRt�|j}d}|j�d}n&d}|j	t
j�}|j	t
j�}|j
d�t|d|d|j	t
j�|j	t
j�|j	t
j�|j	t
j�|j	t
j�|j	t
j�|j	t
j�d�}	yN|dt|d||d||||djd	d�|jj�|d|d
|	d�
�Wn$tk
�r^|j|d�YnXdS)NrYrr\rZ)ZqueueZ
namelookupZconnectZ
appconnectZpretransferZ
starttransferZtotalZredirectr<r;rXz
X-Http-Reasonr[)
r;r]rXrY�
effective_urlrM�reasonZrequest_timeZ
start_time�	time_info)rar#r4r)r=�AssertionError�	CurlErrorr]r9Zgetinfor"Z	HTTP_CODEZ
EFFECTIVE_URL�seek�dictZNAMELOOKUP_TIMEZCONNECT_TIMEZAPPCONNECT_TIMEZPRETRANSFER_TIMEZSTARTTRANSFER_TIMEZ
TOTAL_TIMEZ
REDIRECT_TIMEr�getr7r>rc�handle_callback_exception)
rr:rdrerarYrMr]rfrhrrrrU�sR







zCurlAsyncHTTPClient._finish)r<rcCstjd|dd�dS)NzException in callback %rT)�exc_info)rrM)rr<rrrrn/sz-CurlAsyncHTTPClient.handle_callback_exceptioncCsltj�}tjtj�r2|jtjd�|jtj|j	�t
td�rh|jtjtjtj
B�|jtjtjtj
B�|S)NrW�	PROTOCOLS)r"r2�curl_logZisEnabledFor�logging�DEBUGr$�VERBOSEZ
DEBUGFUNCTION�_curl_debug�hasattrrpZ
PROTO_HTTPZPROTO_HTTPSZREDIR_PROTOCOLS)rr:rrrr2sz CurlAsyncHTTPClient._curl_create)r:r;rYrXrcs��jtjt�j��d�jkr(d�jd<d�jkr<d�jd<�jtjdd��jj�D���jtjt	j
�j|�j���j
r�tttftd���fdd�}n|j}�jtj|��jtj�j��jtj�j��jdk	s�t��jtjtd	�j���jdk	�st��jtjtd	�j���j�r<�jtjt�j��n�jtjd
��j�rb�jtj �j��j!�rz�jtj"d�n�jtj"d��j#�rF�j$�rF�jtj%�j#��jtj&�j$��j'�r�j(dk	�s�t�t)j*�j'�j(�}�jtj+|��j,dk�s�j,d
k�r�jtj-tj.�n,�j,dk�r6�jtj-tj/�nt0d�j,��n�jtj%d��j1tj+��j2�r��jtj3d��jtj4d�n�jtj3d��jtj4d��j5dk	�r��jtj6�j5�n�j7dk�rވjtj8tj9�n�jtj8tj:�tj;tj<tj=tj>d�}t?dddg�}x|j@�D]}	�j|	d��qW�jA|k�r^�j1tjB��j|�jAd�n4�jC�sr�jA|k�r��jtjB�jA�ntDd�jA���jAd'k}
�jEdk	}�jC�s�|
�r�|�s�|�r�|
�r�t0d|
�r�dnd�jAf��|
�s�|�r��jAdk�rt0d��tFtG�jE�pd���tdd ���fd!d"�}�jtjH�jI��jtjJ|��jAdk�rv�jtjKtL�jE�pnd��n(�jtj=d��jtjMtL�jE�p�d���jNdk	�rF�jOdk	�s�t��jPdk�s҈jPd
k�r�jtjQtj.�n,�jPdk�r�jtjQtj/�nt0d#�jP��t)j*�jN�jO�}
�jtjR|
�tSjTd$�jA�j�jN�n�j1tjR�tSjTd%�jA�j��jUdk	�r��jtjV�jU��jWdk	�r��jtjX�jW��jYdk	�r�t0d&��tZj[�dk�r̈jtj\d��j]dk	�r�j]��dS)(NZExpect�ZPragmacSs$g|]\}}dt|�t|�f�qS)z%s: %s)r)r�k�vrrrrYsz;CurlAsyncHTTPClient._curl_setup_request.<locals>.<listcomp>)�brcs&�jdk	st��jj�j|�t|�S)N)�streaming_callbackrir7�add_callback�len)rz)r;rrr�write_functionfsz?CurlAsyncHTTPClient._curl_setup_request.<locals>.write_functioni�z Mozilla/5.0 (compatible; pycurl)zgzip,deflateZnoneZbasicZdigestzUnsupported proxy_auth_mode %srW�rF)�GET�POST�PUTZHEADZDELETEZOPTIONS�PATCHTzunknown method r�r�zLBody must %sbe None for method %s (unless allow_nonstandard_methods is true)znot r�z!Body must be None for GET request)�cmdrcs|�jkr�jd�dS)Nr)ZIOCMD_RESTARTREADrk)r�)r:�request_bufferrr�ioctl�s
z6CurlAsyncHTTPClient._curl_setup_request.<locals>.ioctlzUnsupported auth_mode %sz%s %s (username: %r)z%s %sz,ssl_options not supported in curl_httpclient)r�r�r�)^r$r"ZURLrZurlrXZ
HTTPHEADERZget_allZHEADERFUNCTION�	functools�partial�_curl_header_callback�header_callbackr{r�bytes�	bytearray�int�writeZ
WRITEFUNCTIONZFOLLOWLOCATIONZfollow_redirectsZ	MAXREDIRSZ
max_redirectsZconnect_timeoutriZCONNECTTIMEOUT_MSZrequest_timeoutZ
TIMEOUT_MSZ
user_agentZ	USERAGENTZnetwork_interfaceZ	INTERFACEZdecompress_response�ENCODINGZ
proxy_hostZ
proxy_portZPROXYZ	PROXYPORTZproxy_usernameZproxy_passwordrZencode_username_passwordZPROXYUSERPWDZproxy_auth_modeZ	PROXYAUTHZHTTPAUTH_BASICZHTTPAUTH_DIGEST�
ValueErrorZunsetoptZ
validate_certZSSL_VERIFYPEERZSSL_VERIFYHOSTZca_certsZCAINFOZ
allow_ipv6Z	IPRESOLVEZIPRESOLVE_V4ZIPRESOLVE_WHATEVERZHTTPGETr�ZUPLOADZNOBODY�set�values�methodZ
CUSTOMREQUESTZallow_nonstandard_methods�KeyErrorZbodyrrZREADFUNCTION�readZ
IOCTLFUNCTIONZ
POSTFIELDSIZEr}Z
INFILESIZEZ
auth_usernameZ
auth_passwordZ	auth_modeZHTTPAUTHZUSERPWDrq�debugZclient_certZSSLCERTZ
client_keyZSSLKEYZssl_options�	threadingZactive_countZNOSIGNALZprepare_curl_callback)rr:r;rYrXr~ZcredentialsZcurl_optionsZcustom_methods�oZ
body_expectedZbody_presentr�Zuserpwdr)r:r;r�rrrb>s�




 




	z'CurlAsyncHTTPClient._curl_setup_request)rXr��header_line_bytesrcCs�t|jd��}|dk	r$|jj||�|j�}|jd�rr|j�ytj|�\}}}d|}Wntj	k
rpdSX|szdS|j
|�dS)N�latin1zHTTP/zX-Http-Reason: %s)r�decoder7r|�rstrip�
startswith�clearrZparse_response_start_lineZHTTPInputErrorZ
parse_line)rrXr�r�Zheader_line�__rgrrrr�s
z)CurlAsyncHTTPClient._curl_header_callback)�
debug_type�	debug_msgrcCszd}|dkr&t|�}tjd|j��nP|dkr\t|�}x>|j�D]}tjd|||�q@Wn|d	krvtjd
|||�dS)
N�I�<�>rz%srWrz%s %s�z%s %r)r�r�r�r�r�)rWr)rrqr��strip�
splitlines)rr�r�Zdebug_types�linerrrru'szCurlAsyncHTTPClient._curl_debug)rN)NN)!�__name__�
__module__�__qualname__r�r
�strrr!r9rrrr@r�r&r%rHrJr/rPr?r"r2rUrnrrrr`rbr�ru�
__classcell__rr)r5rr0s6
&
1Orc@seZdZeedd�dd�ZdS)rjN)�errno�messagercCstj|d|�||_dS)NiW)r	�__init__r�)rr�r�rrrr�5szCurlError.__init__)r�r�r�r�r�r�rrrrrj4srj�__main__)&�__doc__r*r�rrr"r�r>�iorZtornadorrZtornado.escaperrZtornado.httpclientrrr	r
rZtornado.logrZtypingr
rrrZ
TYPE_CHECKINGrrrZ	getLoggerrqrrjr�Z	configurerrrr�<module>s4