403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /usr/lib64/python3.9/site-packages/mercurial/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /usr/lib64/python3.9/site-packages/mercurial/__pycache__/keepalive.cpython-39.pyc
a

�+�bjl�	@s�dZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZdd	lmZejZejZejZdaGd
d�de�ZGdd
�d
e�ZGdd�deej�ZGdd�dej�Zdd�Zdd�Z Gdd�dej!�Z!dd�Z"dd�Z#d&dd�Z$dd�Z%d'd!d"�Z&e'd#k�r�ddl(Z(ze)ej*d�Z+ej*d$Z,Wn*e-e.f�y�e/d%ej*d�Yn0e&e,e+�dS)(aKAn HTTP handler for urllib2 that supports HTTP 1.1 and keepalive.

>>> import urllib2
>>> from keepalive import HTTPHandler
>>> keepalive_handler = HTTPHandler()
>>> opener = urlreq.buildopener(keepalive_handler)
>>> urlreq.installopener(opener)
>>>
>>> fo = urlreq.urlopen('http://www.python.org')

If a connection to a given host is requested, and all of the existing
connections are still in use, another connection will be opened.  If
the handler tries to use an existing connection but it fails in some
way, it will be closed and removed from the pool.

To remove the handler, simply re-run build_opener with no arguments, and
install that opener.

You can explicitly close connections by using the close_connection()
method of the returned file-like object (described below) or you can
use the handler methods:

  close_connection(host)
  close_all()
  open_connections()

NOTE: using the close_connection and close_all methods of the handler
should be done with care when using multiple threads.
  * there is nothing that prevents another thread from creating new
    connections immediately after connections are closed
  * no checks are done to prevent in-use connections from being closed

>>> keepalive_handler.close_all()

EXTRA ATTRIBUTES AND METHODS

  Upon a status of 200, the object returned has a few additional
  attributes and methods, which should not be used if you want to
  remain consistent with the normal urllib2-returned objects:

    close_connection()  -  close the connection to the host
    readlines()         -  you know, readlines()
    status              -  the return status (i.e. 404)
    reason              -  english translation of status (i.e. 'File not found')

  If you want the best of both worlds, use this inside an
  AttributeError-catching try:

  >>> try: status = fo.status
  >>> except AttributeError: status = None

  Unfortunately, these are ONLY there if status == 200, so it's not
  easy to distinguish between non-200 responses.  The reason is that
  urllib2 tries to do clever things with error codes 301, 302, 401,
  and 407, and it wraps the object upon return.
�)�absolute_import�print_functionN�)�_)�getattr)�hex)�pycompat�urllibcompat�util)�procutilc@sBeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Z	dS)�ConnectionManagerzT
    The connection manager must be able to:
      * keep track of all existing
    cCs&t��|_t�t�|_i|_i|_dS�N)	�	threading�Lock�_lock�collections�defaultdict�list�_hostmap�_connmap�	_readymap��self�r�9/usr/lib64/python3.9/site-packages/mercurial/keepalive.py�__init__us
zConnectionManager.__init__cCsN|j��z2|j|�|�||j|<||j|<W|j��n|j��0dSr
)r�acquirer�appendrr�release)r�host�
connection�readyrrr�add{s

zConnectionManager.addcCs~|j��zbz|j|}Wnty,Yn40|j|=|j|=|j|�|�|j|s`|j|=W|j��n|j��0dSr
)rrr�KeyErrorrr�remover)rr rrrrr$�s


zConnectionManager.removecCs&z||j|<Wnty Yn0dSr
)rr#)rr r!rrr�	set_ready�szConnectionManager.set_readycCsZd}|j��z:|j|D] }|j|rd|j|<|}q<qW|j��n|j��0|S)NF)rrrrr)rrZconn�crrr�get_ready_conn�s


z ConnectionManager.get_ready_connNcCs |rt|j|�St|j�SdSr
)rr�dict)rrrrr�get_all�szConnectionManager.get_all)N)
�__name__�
__module__�__qualname__�__doc__rr"r$r%r'r)rrrrros	
rc@s`eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
d�Zdd�Z	dd�Z
dd�Zdd�ZdS)�KeepAliveHandlerNcCst�|_||_d|_d|_dS�Nr)r�_cm�_timeout�
requestscount�sentbytescount)r�timeoutrrrr�szKeepAliveHandler.__init__cCsdd�|j����D�S)ztreturn a list of connected hosts and the number of connections
        to each.  [('foo.com:80', 2), ('bar.org', 1)]cSsg|]\}}|t|�f�qSr)�len)�.0rZlirrr�
<listcomp>��z5KeepAliveHandler.open_connections.<locals>.<listcomp>)r0r)�itemsrrrr�open_connections�sz!KeepAliveHandler.open_connectionscCs*|j�|�D]}|j�|�|��qdS)z�close connection(s) to <host>
        host is the host:port spec, as in 'www.cnn.com:8080' as passed in.
        no error occurs if there is no connection to that host.N)r0r)r$�close)rr�hrrr�close_connection�sz!KeepAliveHandler.close_connectioncCs<t�|j���D]&\}}|D]}|j�|�|��qqdS)zclose all open connectionsN)rZ	iteritemsr0r)r$r;)rrZconnsr<rrr�	close_all�szKeepAliveHandler.close_allcCs|j�|d�dS)zetells us that this request is now closed and that the
        connection is ready for another requestTN)r0r%)rZrequestrr rrr�_request_closed�sz KeepAliveHandler._request_closedrcCs|r|��|j�|�dSr
)r;r0r$)rrr r;rrr�_remove_connection�sz#KeepAliveHandler._remove_connectioncCs|�t|�Sr
)�do_open�HTTPConnection)r�reqrrr�	http_open�szKeepAliveHandler.http_openc
Cs�t�|�}|st�d��z�|j�|�}|r`|�|||�}|r>q�|��|j�|�|j�|�}q&|||j	d�}t
r�t
�d|t|��|j�
||d�|�||�|��}Wnvtjy�}z&t�td�t�|j���WYd}~n@d}~0tjtjf�y }zt�|��WYd}~n
d}~00t|dd��r<|j�|�t
�rTt
�d|j|j�||_||_|��|_||_ |j|_!|j"|_#|j|_"|S)	Ns
no host given)r4s"creating new connection to %s (%d)Fsbad HTTP status line: %sZ
will_closeTsSTATUS: %s, %s)$r	Zgethost�urlerr�urlerrorr0r'�_reuse_connectionr;r$r1�DEBUG�info�idr"�_start_transaction�getresponse�httplibZ
BadStatusLinerrZsysbytes�line�socket�error�
HTTPExceptionr�status�reason�_handler�_hostZget_full_url�_url�_connection�code�msg�headers)rZ
http_classrCrr<�r�errrrrrA�sL


�� 
zKeepAliveHandler.do_openc	Cs�z|�||�|��}WnTtjtjfy6d}Yn8trRt�d|t|��|j�	|�|�
��Yn0|dus�|jdkr�tr�t�d|t|��d}ntr�t�d|t|��|S)aGstart the transaction with a re-used connection
        return a response object (r) upon success or None on failure.
        This DOES not close or remove bad connections in cases where
        it returns.  However, if an unexpected exception occurs, it
        will close and remove the connection before re-raising.
        Ns4unexpected exception - closing connection to %s (%d)�	s&failed to re-use connection to %s (%d)sre-using connection to %s (%d))
rKrLrOrPrMrQrHrJr0r$r;�versionrI)rr<rCrr[rrrrGs0
�
�z"KeepAliveHandler._reuse_connectionc
Cs�t|dd�}t�|jj�}|�t|j����|�t|j	����t�dd�|��D��}i}dD] }||vrbd|d|�
dd	�<qbz�t�|�r�t�
|�}|j|��t�|�fi|��d
|vr�|�dd�d
|vr�|�ddt|��n|j|��t�|�fi|��Wn2tj�y<}zt�|��WYd}~n
d}~00|��D]\}	}
|�|	|
��qF|��t�|��r||�|�|jd7_|jt|dd�|7_z0|jjd7_|jjt|dd�|7_Wnt�y�Yn0dS)Nr3rcss|]\}}|��|fVqdSr
)�lower)r6�n�vrrr�	<genexpr>Lr8z6KeepAliveHandler._start_transaction.<locals>.<genexpr>)rzaccept-encodingrZskip_�-rzcontent-typezContent-typez!application/x-www-form-urlencodedzcontent-lengthzContent-lengthz%d)rr
Zsortdict�parentZ
addheaders�update�sortedrZr9Zunredirected_hdrs�replacer	ZhasdataZgetdataZ
putrequestZ
get_methodZgetselectorZ	putheaderr5rOrPrErFZ
endheaders�sendr2r3�AttributeError)rr<rCZ
oldbytescountrZZskipheadersr`�datar\�krarrrrKCs\

�����
 
�
z#KeepAliveHandler._start_transaction)N)r)
r*r+r,rr:r=r>r?r@rDrArGrKrrrrr.�s

92r.c@seZdZdS)�HTTPHandlerN)r*r+r,rrrrrlzsrlc@s�eZdZddd�ZejjZeejdd�Z	dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zddd�Zdd�Zdd�Zddd�Zdd�ZdS)�HTTPResponserNcCsri}tjsd|d<d|d<tjj||f||d�|��|j|_d|_d|_d|_d|_	d|_
d|_d|_d|_
dS)NT�strict�	buffering)�
debuglevel�methodrr8i�)rZispy3rMrmr�filenorX�receivedbytescount�_rbuf�	_rbufsizerTrUrVrW)r�sockrprnrqZextrakwrrrr�s(���zHTTPResponse.__init__�readintocCs4|jr0|j��d|_|jr0|j�||j|j�dSr
)�fpr;rTr?rUrWrrrrr;�s

�zHTTPResponse.closecCs|��dSr
�r;rrrr�_close_conn�szHTTPResponse._close_conncCs"|jj|j|jdd�|��dS)Nrry)rTr@rUrWr;rrrrr=�szHTTPResponse.close_connectioncCs|jSr
)rZrrrrrI�szHTTPResponse.infocCs|jSr
)rVrrrr�geturl�szHTTPResponse.geturlcCs�|jrL|durLt|j�}||kr*||8}n"|jd|�}|j|d�|_|S|j}d|_|�|�}|jt|�7_z|jjt|�7_Wnty�Yn0z|jjjt|�7_Wnty�Yn0||7}|S)Nr8)rtr5�	_raw_readrsrWrirTrd)r�amt�L�srjrrr�read�s*


zHTTPResponse.readcCsX|j}g}|dur�|j��}|�d�}|dkr:|d|�}zt|d�}Wn*tyr|��t�d�	|���Yn0|dkr��q |dur�|�
|�|��nv||kr�|�
|�|��|||_d�	|�S||kr�|�
|�|��|�d�d|_d�	|�S|�
|�|��||8}|�d�d}q
|j��}|�s4�qF|dk�r �qF�q |��d�	|�S)N�;r�r8�s
)�
chunk_leftrx�readline�find�int�
ValueErrorr;rMZIncompleteRead�joinrZ
_safe_read)rr}r��partsrN�irrr�
_read_chunked�sH








zHTTPResponse._read_chunkedcCs4|j�d�}|dkr>|d7}|jd|�}|j|d�|_|S|jdurR|jg}ng}d}|j}|�|�}|spq�|jt|�7_|jjt|�7_z|jj	jt|�7_Wnt
y�Yn0|�|�|�d�}|dkr`q�q`|dkr�d|_d�|�S|d7}|d|d�|_|dd|�|d<d�|�S)N�
rr���r8)
rtr��
_raw_readintorur|rsr5rWrTrdrirr�)rr�rN�chunks�readsize�newrrrr�s>





zHTTPResponse.readlinecCs@d}g}|��}|sq<|�|�|t|�7}|r||krq<q|Sr/)r�rr5)r�sizehint�totalrrNrrr�	readlinesEs
zHTTPResponse.readlinescCs|jdur8|�t|��}|s dS||dt|��<t|�St|�}t|j�}||kr||jd|�|d|�<|j|d�|_|St|�}|�|||��}|j|7_|jj|7_z|jj|7_Wnty�Yn0|j|d|�<|t|j�7}d|_|S)Nrr8)	r�r�r5rt�
memoryviewrsrWrTri)r�dest�resr�Zhave�mvZgotrrrrwRs0

zHTTPResponse.readinto)rrN)N)r)r*r+r,rrMrmr�r|rr�r;rzr=rIr{r�r�r�rwrrrrrm~s
	
 6.

rmc
CsDt|dd�durdS|jdur4|jr.|��ntj�|jdkrLtdt|��z�d}t|dd�}|dur�|jdkrxtd�||�}|r�|j�	|�|j
t|�7_
||�}q�n|j�	|�|j
t|�7_
Wnptj
�y>}zTd}|jdtjk�r"|jtjk�rd|_|��|_d	}|��|�r*�WYd}~n
d}~00dS)
z`Send `str' to the server.

    Shamelessly ripped off from httplib to patch a bad behavior.
    �_broken_pipe_respNrssend:i r�ssending a read()ableTF)rrvZ	auto_openZconnectrMZNotConnectedrp�print�reprZsendallr3r5rOrP�args�errnoZEPIPEZ_HTTPConnection__stateZ_CS_REQ_SENTr�rLr;)r�str�	blocksizer�rjraZreraiserrr�safesendos>




r�cs�fdd�}�jj|_|S)z9Wraps getresponse in cls with a broken-pipe sane version.cs"t|dd�}|dur|S��|�S)Nr�)rrL)rr[��clsrr�safegetresponse�sz(wrapgetresponse.<locals>.safegetresponse)rLr-)r�r�rr�r�wrapgetresponse�s

r�c@s&eZdZeZeZeej	�Z
dd�ZdS)rBcOs*tjj|g|�Ri|��d|_d|_dSr/)rMrBrr3rs)rr��kwargsrrrr�szHTTPConnection.__init__N)r*r+r,rmZresponse_classr�rhr�rMrBrLrrrrrrB�s
rBcCs�tj}d}t��}t�|�t�|�}|��}|��||�}t|dt	|�
��f�t�t��}t�|�t�|�}|��}|��||�}t|dt	|�
��f�t�|�}d}|��}|r�||}q�q�q�|��||�}t|dt	|�
��f�dS)Ns%25s: %ss
normal urllibskeepalive readr8skeepalive readline)
�hashlib�md5�urlreq�buildopener�
installopener�urlopenr�r;r�r�digestrlr�)�urlr��format�opener�fo�foo�m�frrr�
continuity�s2





r�cCs�td||f�tj�d�t��}t�|�t||�}td|�tj�d�t�t��}t�|�t||�}td|�td||�dS)Ns   making %i connections to:
  %ss(  first using the normal urllib handlerss  TIME: %.3f ss(  now using the keepalive handler       s  improvement factor: %.2f)	r�r�stdout�writer�r�r��fetchrl)�Nr�r��t1�t2rrr�comp�s



r�cCs�ddl}g}|��}t|�D]B}|r6|dkr6|�|�t�|�}|��}|��|�t|��q|��|}	d}
|dd�D](}|
d}
||dks|t	d|
|f�q||	S)Nrrs+WARNING: inconsistent length on read %i: %i)
�time�range�sleepr�r�r�r;rr5r�)r�r�Zdelayr�ZlensZ	starttimer�r�r��diff�jrrrr�s"

r�cCs�t}Gdd�dt�}|�atd�t�|�}|��}|��d}td|�|dkr�tj�	d|�tj�
�t�d�|d8}qLtj
�	d	�td
�t�|�}|��}|��||kr�td�ntd�|adS)
Nc@s eZdZdd�ZeZZZdS)z test_timeout.<locals>.FakeLoggercWst||�dSr
)r�)rrYr�rrr�debugsz&test_timeout.<locals>.FakeLogger.debugN)r*r+r,r�rIZwarningrPrrrr�
FakeLoggersr�s-  fetching the file to establish a connection�s;  waiting %i seconds for the server to close the connectionrs
  %2ir�
s!  fetching the file a second times  data are identicals  ERROR: DATA DIFFER)rH�objectr�r�r�r�r;rr�r��flushr�r��stderr)r�Zdbbackupr�r�Zdata1r�Zdata2rrr�test_timeouts.





r��
cCsFtd�t|�td�td�t||�td�td�t|�dS)Ns>performing continuity test (making sure stuff isn't corrupted)r8sperforming speed comparisons#performing dropped-connection check)r�r�r�r�)r�r�rrr�test?s
r��__main__r�s%s <integer> <url>)r)r�)0r-Z
__future__rrrr�r�rO�sysrZi18nrrrZnoder�r	r
ZutilsrrMrEr�rHr�rr.Zhttphandlerrlrmr�r�rBr�r�r�r�r�r*r�r��argvr�r��
IndexErrorr�r�rrrr�<module>sL;?Mr6$
&



Youez - 2016 - github.com/yon3zu
LinuXploit