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__/wireprotoframing.cpython-39.opt-1.pyc
a

�+�b��@sddlmZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZmZm
Z
mZddlmZmZd	Zd
ZdZdZdZeeed
�ZdZdZdZdZdZdZd	ZdZeeeeeeeed�Z dZ!dZ"dZ#d	Z$e!e"e#e$d�Z%dZ&dZ'e&e'd�Z(dZ)dZ*e)e*d�Z+dZ,dZ-e,e-d�Z.dZ/dZ0e/e0d�Z1ee%ee(ee+eieieiee.ee1iZ2e�3d�Z4dd�Z5e	j6dd�Gdd�de7��Z8e	j6ddd�Gdd �d e7��Z9d!d"�Z:d#d$�Z;d%d&�Z<d'd(�Z=dedfd)d*�Z>d+d,�Z?efd-d.�Z@d/d0�ZAd[d1d2�ZBd3d4�ZCefd5d6�ZDGd7d8�d8e7�ZEGd9d:�d:e7�ZFGd;d<�d<e7�ZGGd=d>�d>e7�ZHGd?d@�d@e7�ZIGdAdB�dBe7�ZJGdCdD�dDeJ�ZKGdEdF�dFe7�ZLGdGdH�dHeL�ZMiZNgZOdIdJ�ZPGdKdL�dLe7�ZQGdMdN�dNeQ�ZRGdOdP�dPeQ�ZSdQdR�ZTdSdTgiZUGdUdV�dVe7�ZVGdWdX�dXe7�ZWGdYdZ�dZe7�ZXdS)\�)�absolute_importN�)�_)�getattr)�attr)�encoding�error�pycompat�util�wireprototypes)�cborutil�
stringutil�i���)sstream-begins
stream-endsencoded�����	)scommand-requestscommand-datascommand-responseserror-responsestext-outputsprogressssender-protocol-settingssstream-settings)snew�continuationsmores	have-data)r�eosz<HHcCsVdd�t�|�D�}g}d}||krL||@rB|�|�|d|��|dK}qd�|�S)zFConvert a numeric flags value to a human value, using a mapping table.cSsi|]\}}||�qS�r)�.0�k�vrr�@/usr/lib64/python3.9/site-packages/mercurial/wireprotoframing.py�
<dictcomp>~�zhumanflags.<locals>.<dictcomp>r�<unknown 0x%02x>�|)r	�	iteritems�append�get�join)�mapping�valueZnamemap�flags�valrrr�
humanflags|s
r)T)�slotsc@s@eZdZdZe��Ze��Ze��Ze��Z	e��Z
e��ZdS)�frameheaderz&Represents the data in a frame header.N)�__name__�
__module__�__qualname__�__doc__r�ib�length�	requestid�streamid�streamflags�typeidr'rrrrr+�sr+F)r*�reprc@sNeZdZdZe��Ze��Ze��Ze��Z	e��Z
e��Zej
dd��ZdS)�framezRepresents a parsed frame.cCshd|j}t�t�D]\}}||jkr|}q0qdt|j�|j|jtt	|j
�|tt�|ji�|j
�fS)NrsHframe(size=%d; request=%d; stream=%d; streamflags=%s; type=%s; flags=%s))r5r	r!�FRAME_TYPES�len�payloadr2r3r)�STREAM_FLAGSr4�FRAME_TYPE_FLAGSr#r')�self�typename�namer&rrr�__repr__�s


���zframe.__repr__N)r,r-r.r/rr0r2r3r4r5r'r:rZ	strmethodr@rrrrr7�sr7cCshttt|��}t�dt|��}|dd�|dd�<t�d|d|||�|d>|B|d<||dd�<|S)	z#Assemble a frame into a byte array.z<Irr�<HBBrrrN)�	bytearray�FRAME_HEADER_SIZEr9�struct�pack�	pack_into)r2r3r4r5r'r:r7�lrrr�	makeframe�s	rHc	Cs|�dd�}|\}}}}}}t|�}t|�}d}|�d�D]&}	|	tvrT|t|	O}q:|t|	�O}q:|tvrtt|}nt|�}d}
t|}|�d�D]&}	|	|vr�|
||	O}
q�|
t|	�O}
q�|�d�r�d�t�t	�
|dd����}n
t	�|�}t|||||
|d�S)	a�Create a frame from a human readable string

    Strings have the form:

        <request-id> <stream-id> <stream-flags> <type> <flags> <payload>

    This can be used by user-facing applications and tests for creating
    frames easily without having to type out a bunch of constants.

    Request ID and stream IDs are integers.

    Stream flags, frame type, and flags can be specified by integer or
    named constant.

    Flags can be delimited by `|` to bitwise OR them together.

    If the payload begins with ``cbor:``, the following string will be
    evaluated as Python literal and the resulting object will be fed into
    a CBOR encoder. Otherwise, the payload is interpreted as a Python
    byte string literal.
    � rrr scbor:rN)r2r3r4r5r'r:)
�split�intr;r8r<�
startswithr$r�streamencoder
ZevalpythonliteralZunescapestrrH)�s�fieldsr2r3r4�	frametype�
frameflagsr:Zfinalstreamflags�flagZ
finalflagsZ
validflagsrrr�makeframefromhumanstring�s>

�
�rScCsb|dd|dd|d}t�d|d�\}}}|d}|d	@d
?}|d@}t||||||�S)z�Parse a unified framing protocol frame header from a buffer.

    The header is expected to be in the buffer at offset 0 and the
    buffer is expected to be large enough to hold a full header.
    r�ri@rrArr��r�)rD�unpack_fromr+)�dataZframelengthr2r3r4Z	typeflagsrPrQrrr�parseheader
s
 �rYcCs�tt�}|�|�}|dkrdS|tkr<t�td�||f��t|�}|�|j�}t	|�|jkrzt�td�|jt	|�f��t
|j|j|j
|j|j|�S)z�Read a unified framing protocol frame from a file object.

    Returns a 3-tuple of (type, flags, payload) for the decoded frame or
    None if no frame is available. May raise if a malformed frame is
    seen.
    rNs+received incomplete frame: got %d bytes: %ss'frame length error: expected %d; got %d)rBrC�readintor�AbortrrY�readr1r9r7r2r3r4r5r')Zfh�headerZ	readcount�hr:rrr�	readframe&s*
�����r_ccsd|i}|r||d<|r ||d<d�t�|��}d}d}	|sF|	tO}	n|	tO}	|rZ|	tO}	||||�}
|t|
�7}t|
�|kr�|t|�kr�|	tO}	|j|t	|	|
d�V|	t@s4q�q4|r�|�
t�}d}t|�tkr�t}	nt
}	d}|j|t|	|d�V|r�q�q�d	S)
z�Create frames necessary to transmit a request to run a command.

    This is a generator of bytearrays. Each item represents a frame
    ready to be sent over the wire to a peer.
    �name�args�redirectrr�r2r5r'r:FTN)r$rrM�FLAG_COMMAND_REQUEST_NEW�!FLAG_COMMAND_REQUEST_CONTINUATION� FLAG_COMMAND_REQUEST_EXPECT_DATAr9� FLAG_COMMAND_REQUEST_MORE_FRAMESrH�FRAME_TYPE_COMMAND_REQUESTr\�DEFAULT_MAX_FRAME_SIZE�FLAG_COMMAND_DATA_CONTINUATION�FLAG_COMMAND_DATA_EOS�FRAME_TYPE_COMMAND_DATA)�streamr2�cmd�args�datafh�maxframesize�redirectrX�offsetr'r:�donerrr�createcommandframesHsP
�
�rucCsJd�t�ddi��}|jr2|�|�}d}|s6dSnd}|j|tt||d�S)Nr�statussokTF�r2r5r'r:�encoded)r$rrM�streamsettingssent�encoderH�FRAME_TYPE_COMMAND_RESPONSE�"FLAG_COMMAND_RESPONSE_CONTINUATION)rmr2�overallrxrrr�createcommandresponseokframe�s
�r~ccsh|��}d}||||�}|t|�7}|t|�k}|r>t}nt}|j|t|||dkd�V|rqdqdS)zACreate an empty payload frame representing command end-of-stream.rrrwN)�flushr9�FLAG_COMMAND_RESPONSE_EOSr|rHr{)rmr2rqr:rs�chunkrtr'rrr�createcommandresponseeosframes�s"�r�cCs�d|j|jd�d�}dD](}t||�}|dur||dt�|�<qd�t�|��}|jrh|�	|�}d}nd}|j
|tt||d	�S)
Nrb)surls	mediatype)rv�location)�sizeZ
fullhashesZfullhashseedZserverdercertsZservercadercertsr�rTFrw)
�urlZ	mediatyperr	Zbytestrr$rrMryrzrHr{r|)rmr2�locationrX�ar&r:rxrrr�$createalternatelocationresponseframe�s*��

�r�ccsFdd|id�}|r||dd<d�t�|��}|j|tt|d�VdS)N�error�message)rvr�rarrc)r$rrMrHr{r�)rmr2�messagero�mr}rrr�createcommanderrorresponse�s���r�ccs4d�t�|d|igd���}|j|td|d�VdS)Nr�msg)�typer�rrc)r$rrMrH�FRAME_TYPE_ERROR_RESPONSE)rmr2�msg�errtyper:rrr�createerrorframes���	�r�ccs�g}|D]�\}}}t|t�s$td��|D]}t|t�s(td��q(|D]}	t|	t�sDtd��qD|�dd��d�}dd�|D�}dd�|D�}d	|i}
|r�||
d
<|r�||
d<|�|
�qd�t�|��}t	|�|kr�td
��|j
|td|d�VdS)a�Create a text output frame to render text to people.

    ``atoms`` is a 3-tuple of (formatting string, args, labels).

    The formatting string contains ``%s`` tokens to be replaced by the
    corresponding indexed entry in ``args``. ``labels`` is an iterable of
    formatters to be applied at rendering time. In terms of the ``ui``
    class, each atom corresponds to a ``ui.write()``.
    s!must use bytes formatting stringssmust use bytes for argumentssmust use bytes for labels�ascii�replacecSsg|]}|�dd��d��qS)zutf-8r���decoderz)rr�rrr�
<listcomp>7rz)createtextoutputframe.<locals>.<listcomp>cSsg|]}|�dd��d��qS)r��strictr�)rrGrrrr�:rr�raslabelsrs$cannot encode data in a single framerrcN)�
isinstance�bytes�
ValueErrorr�rzr"r$rrMr9rH�FRAME_TYPE_TEXT_OUTPUT)rmr2ZatomsrqZ	atomdictsZ
formattingro�labels�argZlabelZatomr:rrr�createtextoutputframes8




�r�c@s,eZdZdZefdd�Zdd�Zdd�ZdS)	�bufferingcommandresponseemittera�Helper object to emit command response frames intelligently.

    Raw command response data is likely emitted in chunks much smaller
    than what can fit in a single frame. This class exists to buffer
    chunks until enough data is available to fit in a single frame.

    TODO we'll need something like this when compression is supported.
    So it might make sense to implement this functionality at the stream
    level.
    cCs"||_||_||_g|_d|_dS�Nr)�_stream�
_requestid�_maxsize�_chunks�_chunkssize)r=rmr2rqrrr�__init__]s
z(bufferingcommandresponseemitter.__init__ccs|dur |��D]
}|VqdS|j�|�}|s4dSt|�|jkr�|��D]
}|VqJd}||||j�}|t|�7}|jj|jtt|dd�V|t|�krZdSqZt|�|j	|jkr�|j
�|�|j	t|�7_	dS|��D]
}|Vq�|j
�|�t|�|_	dS)z�Send new data for emission.

        Is a generator of new frames that were derived from the new input.

        If the special input ``None`` is received, flushes all buffered
        data to frames.
        NrT�r5r'r:rx)�_flushr�rzr9r�rHr�r{r|r�r�r")r=rXr7rsr�rrr�sendds<	�z$bufferingcommandresponseemitter.sendccsFd�|j�}g|jdd�<d|_|s(dS|jj|jtt|dd�VdS)NrrTr�)r$r�r�r�rHr�r{r|)r=r:rrrr��s�z&bufferingcommandresponseemitter._flushN)r,r-r.r/rir�r�r�rrrrr�QsDr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�identityencoderz3Encoder for the "identity" stream encoding profile.cCsdS�Nr�r=�uirrrr��szidentityencoder.__init__cCs|Sr�r�r=rXrrrrz�szidentityencoder.encodecCsdS�Nrr�r=rrrr�szidentityencoder.flushcCsdSr�rr�rrr�finish�szidentityencoder.finishN)r,r-r.r/r�rzrr�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�identitydecoderz3Decoder for the "identity" stream encoding profile.cCs|rt�td���dS)Ns6identity decoder received unexpected additional values)rr[r�r=r��	extraobjsrrrr��s�zidentitydecoder.__init__cCs|Sr�rr�rrrr��szidentitydecoder.decodeN)r,r-r.r/r�r�rrrrr��sr�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�zlibencodercCsddl}||_|��|_dSr�)�zlib�_zlib�compressobj�_compressor)r=r�r�rrrr��szzlibencoder.__init__cCs|j�|�Sr��r��compressr�rrrrz�szzlibencoder.encodecCs|j�|jj�Sr�)r�rr��Z_SYNC_FLUSHr�rrrr�szzlibencoder.flushcCs|j�|jj�}d|_|Sr�)r�rr��Z_FINISH�r=�resrrrr��szzlibencoder.finishN�r,r-r.r�rzrr�rrrrr��sr�c@seZdZdd�Zdd�ZdS)�zlibdecodercCs(ddl}|rt�td���|��|_dS)Nrs2zlib decoder received unexpected additional values)r�rr[r�
decompressobj�
_decompressor)r=r�r�r�rrrr��s�zzlibdecoder.__init__cCs$tjst|t�rt|�}|j�|�Sr�)r	Zispy3r�rBr�r��
decompressr�rrrr��szzlibdecoder.decodeN�r,r-r.r�r�rrrrr��s
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�zstdbaseencodercCs,ddlm}||_|j|d�}|��|_dS)Nr��zstd)�level)�r��_zstdZZstdCompressorr�r�)r=r�r�Zcctxrrrr�szzstdbaseencoder.__init__cCs|j�|�Sr�r�r�rrrrz
szzstdbaseencoder.encodecCs|j�|jj�Sr�)r�rr�ZCOMPRESSOBJ_FLUSH_BLOCKr�rrrrszzstdbaseencoder.flushcCs|j�|jj�}d|_|Sr�)r�rr�ZCOMPRESSOBJ_FLUSH_FINISHr�rrrr�szzstdbaseencoder.finishNr�rrrrr�sr�cseZdZ�fdd�Z�ZS)�zstd8mbencodercstt|��d�dS)Nr)�superr�r�r���	__class__rrr�szzstd8mbencoder.__init__�r,r-r.r��
__classcell__rrr�rr�sr�c@seZdZdd�Zdd�ZdS)�zstdbasedecodercCs&ddlm}|j|d�}|��|_dS)Nrr�)Zmax_window_size)r�r�ZZstdDecompressorr�r�)r=�
maxwindowsizer�Zdctxrrrr�"szzstdbasedecoder.__init__cCs|j�|�Sr�)r�r�r�rrrr�(szzstdbasedecoder.decodeNr�rrrrr�!sr�cseZdZ�fdd�Z�ZS)�zstd8mbdecodercs(|rt�td���tt|�jdd�dS)Ns5zstd8mb decoder received unexpected additional valuesi�)r�)rr[rr�r�r�r�r�rrr�-s
�zzstd8mbdecoder.__init__r�rrr�rr�,sr�cCs�trdSzddlm}|jWnty4d}Yn0|rPttftd<t�d�t	t
ftd<t�d�ttftd<t�d�dS)Nrr�szstd-8mbszlib�identity)
�STREAM_ENCODERSr�r��__version__�ImportErrorr�r��STREAM_ENCODERS_ORDERr"r�r�r�r�r�rrr�populatestreamencoders<s



r�c@s"eZdZdZddd�Zdd�ZdS)	rmz5Represents a logical unidirectional series of frames.FcCs||_||_dSr�)r3�_active�r=r3�activerrrr�Vszstream.__init__cCs,d}|js|tO}d|_t||j||||�S)�}Create a frame to be sent out over this stream.

        Only returns the frame instance. Does not actually send it.
        rT)r��STREAM_FLAG_BEGIN_STREAMrHr3)r=r2r5r'r:r4rrrrHZs�zstream.makeframeN)F)r,r-r.r/r�rHrrrrrmSs
rmcs:eZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Z�ZS)�inputstreamz,Represents a stream used for receiving data.Fcstt|�j||d�d|_dS)N�r�)r�r�r��_decoderr�r�rrr�lszinputstream.__init__cCs2|tvrt�td�|��t|d||�|_dS)z�Set the decoder for this stream.

        Receives the stream profile name and any additional CBOR objects
        decoded from the stream encoding settings frame payloads.
        sunknown stream decoder: %srN)r�rr[rr�)r=r�r?r�rrr�
setdecoderpszinputstream.setdecodercCs|js
|S|j�|�Sr�)r�r�r�rrrr�{szinputstream.decodecCs|js
dS|j��Sr�)r�rr�rrrr�szinputstream.flush)F)	r,r-r.r/r�r�r�rr�rrr�rr�is
r�csTeZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zdd
d�Z	dd�Z
�ZS)�outputstreamz*Represents a stream used for sending data.Fcs*tt|�j||d�d|_d|_d|_dS)Nr�F)r�r�r�ry�_encoder�_encodernamer�r�rrr��szoutputstream.__init__cCs6|tvrt�td�|��t|d|�|_||_dS)zTSet the encoder for this stream.

        Receives the stream profile name.
        sunknown stream encoder: %srN)r�rr[rr�r�)r=r�r?rrr�
setencoder�szoutputstream.setencodercCs|js
|S|j�|�Sr�)r�rzr�rrrrz�szoutputstream.encodecCs|js
dS|j��Sr�)r�rr�rrrr�szoutputstream.flushcCs|js
dS|j��dSr�)r�r�r�rrrr��szoutputstream.finishcCs^d}|js|tO}d|_|r4|js,t�d��|tO}|tkrJ|t@rJd|_t||j	||||�S)r�rTs@attempting to send encoded frame without sending stream settings)
r�r�ryr�ProgrammingError�STREAM_FLAG_ENCODING_APPLIED�FRAME_TYPE_STREAM_SETTINGS�!FLAG_STREAM_ENCODING_SETTINGS_EOSrHr3)r=r2r5r'r:rxr4rrrrH�s$����zoutputstream.makeframecCs2|jr|jrdSd�t�|j��}|�|tt|�S)z�Create a stream settings frame for this stream.

        Returns frame data or None if no stream settings frame is needed or has
        already been sent.
        Nr)	r�ryr$rrMr�rHr�r�)r=r2r:rrr�makestreamsettingsframe�s�z$outputstream.makestreamsettingsframe)F)F)r,r-r.r/r�r�rzrr�rHr�r�rrr�rr��s
r�cCs|jdrt�d|j��dS)NrsAserver should only write to even numbered streams; %d is not even)r3rr�)rmrrr�ensureserverstream�s
��r��contentencodingsr�c@s�eZdZdZd(dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	d)dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�ZdS)*�
serverreactora>Holds state of a server handling frame-based protocol requests.

    This class is the "brain" of the unified frame-based protocol server
    component. While the protocol is stateless from the perspective of
    requests/commands, something needs to track which frames have been
    received, what frames to expect, etc. This class is that thing.

    Instances are modeled as a state machine of sorts. Instances are also
    reactionary to external events. The point of this class is to encapsulate
    the state of the connection and the exchange of frames, not to perform
    work. Instead, callers tell this class when something occurs, like a
    frame arriving. If that activity is worthy of a follow-up action (say
    *run a command*), the return value of that handler will say so.

    I/O and CPU intensive operations are purposefully delegated outside of
    this class.

    Consumers are expected to tell instances when events occur. They do so by
    calling the various ``on*`` methods. These methods return a 2-tuple
    describing any follow-up action(s) to take. The first element is the
    name of an action to perform. The second is a data structure (usually
    a dict) specific to that action that contains more information. e.g.
    if the server wants to send frames back to the client, the data structure
    will contain a reference to those frames.

    Valid actions that consumers can be instructed to take are:

    sendframes
       Indicates that frames should be sent to the client. The ``framegen``
       key contains a generator of frames that should be sent. The server
       assumes that all frames are sent to the client.

    error
       Indicates that an error occurred. Consumer should probably abort.

    runcommand
       Indicates that the consumer should run a wire protocol command. Details
       of the command to run are given in the data structure.

    wantframe
       Indicates that nothing of interest happened and the server is waiting on
       more frames from the client before anything interesting can be done.

    noop
       Indicates no additional action is required.

    Known Issues
    ------------

    There are no limits to the number of partially received commands or their
    size. A malicious client could stream command request data and exhaust the
    server's memory.

    Partially received commands are not acted upon when end of input is
    reached. Should the server error if it receives a partial request?
    Should the client send a message to abort a partially transmitted request
    to facilitate graceful shutdown?

    Active requests that haven't been responded to aren't tracked. This means
    that if we receive a command and instruct its dispatch, another command
    with its request ID can come in over the wire and there will be a race
    between who responds to what.
    FcCsR||_||_d|_d|_g|_i|_i|_i|_t�|_	d|_
tt�|_
t�dS)a�Construct a new server reactor.

        ``deferoutput`` can be used to indicate that no output frames should be
        instructed to be sent until input has been exhausted. In this mode,
        events that would normally generate output frames (such as a command
        response being ready) will instead defer instructing the consumer to
        send those frames. This is useful for half-duplex transports where the
        sender cannot receive until all data has been transmitted.
        �initialrN)�_ui�_deferoutput�_state�_nextoutgoingstreamid�_bufferedframegens�_incomingstreams�_outgoingstreams�_receivingcommands�set�_activecommands�_protocolsettingsdecoder�dict�DEFAULT_PROTOCOL_SETTINGS�_sendersettingsr�)r=r�Zdeferoutputrrrr�-s

zserverreactor.__init__cCs�|jds$d|_|�td�|j�S|j|jvr`|jt@sNd|_|�td��St|j�|j|j<|jt@rzd|_t	�
d��|jt@r�|j|j=|j|j
|j|j|jd�}|�|j�}|s�t	�
d|j��||�S)z�Process a frame that has been received off the wire.

        Returns a dict with an ``action`` key that details what action,
        if any, the consumer should take next.
        r�erroreds/received frame with even numbered stream ID: %dsNreceived frame on unknown inactive stream without beginning of stream flag sets8support for decoding stream payloads not yet implemented)r��protocol-settings-receiving�idle�command-receivingrsunhandled state: %s)r3r��_makeerrorresultrr�r4r�r�r�rr��STREAM_FLAG_END_STREAM�_onframeinitial�_onframeprotocolsettings�_onframeidle�_onframecommandreceiving�_onframeerroredr#)r=r7�handlers�methrrr�onframerecvMsB
��
��
�

�zserverreactor.onframerecvcs8t��t�t�rt�������fdd�}��|��S)z�Signal that objects are ready to be sent to the client.

        ``objs`` is an iterable of objects (typically a generator) that will
        be encoded via CBOR and added to frames, which will be sent to the
        client.
        c
3s�d}d}t���}zt��}Wn�tyf|�d�D]
}|Vq6|r\t���D]
}|VqPY�q�Yn�tjy�}z8t��|j|j	�D]
}|Vq�WYd}~�q�WYd}~nbd}~0t
�y}z@t��dt�
|�dd�D]
}|Vq�WYd}~�q�WYd}~n
d}~00�z(t|tj��rb|�r2t�d������}|�rH|Vt��|�Vd}d}Wq|�rrt�d��|�s�����}|�r�|Vt���}|�r�|Vd}t|tj��r�|�|j�D]}|V�q�nft|tj��rt�|j�D]}|�|�D]}|V�q��q�n*t�|�D]}|�|�D]}|V�q&�qWqt
�y�}z<t��d|dd�D]}|V�q`WYd}~�q�WYd}~qd}~00q�j���dS)NFs%s�server�r�s:alternatelocationresponse seen after initial output objectTs(object follows alternatelocationresponse)r��next�
StopIterationr�r�rZWireprotoCommandErrorr�r�Zmessageargs�	Exceptionr�r
�forcebytestrr�rZalternatelocationresponser�r�r�r~ZencodedresponserXZindefinitebytestringresponserZstreamencodebytestringfromiter�chunksrMr��remove)ZemittedZalternatelocationsentZemitter�or7�er���objsr2r=rmrr�
sendframes�s�
�
�"�
$�
��

���

&z?serverreactor.oncommandresponsereadyobjects.<locals>.sendframes)r�r��list�iter�_handlesendframes)r=rmr2rrrrr�oncommandresponsereadyobjects~s

qz+serverreactor.oncommandresponsereadyobjectscs.�jr�jsdifS�fdd�}dd|�ifS)z�Signals that end of input has been received.

        No more frames will be received. All pending activity should be
        completed.
        �noopc3s �jD]}|D]
}|VqqdSr�)r�)�genr7r�rr�makegens
z)serverreactor.oninputeof.<locals>.makegen�
sendframes�framegen)r�r�)r=r"rr�r�
oninputeofs�zserverreactor.oninputeofcCs*|jr|j�|�difSdd|ifSdS)Nr r#r$)r�r�r")r=Zframegenrrrr s�zserverreactor._handlesendframescs&t������fdd�}��|��S)Nc3s,t���dd�D]
}|Vq�j���dS)Nrr)r�r�r�r7�r�r2r=rmrrr,s
�
z/serverreactor.onservererror.<locals>.sendframes�r�r)r=rmr2r�rrr'r�
onservererror)szserverreactor.onservererrorNcs(t�������fdd�}��|��S)zACalled when a command encountered an error before sending output.c3s*t�����D]
}|Vq�j���dSr�)r�r�rr&�ror�r2r=rmrrr:s
�z0serverreactor.oncommanderror.<locals>.sendframesr()r=rmr2r�rorrr*r�oncommanderror6szserverreactor.oncommanderrorcCsT|j}|jd7_t|�}||j|<tD]$}||jdvr*|�|j|�qPq*|S)z�Create a stream to be used for sending data to the client.

        If this is called before protocol settings frames are received, we
        don't know what stream encodings are supported by the client and
        we will default to identity.
        rr�)r�r�r�r�rr�r�)r=r3rNr?rrr�makeoutputstreamDs
zserverreactor.makeoutputstreamcCsdd|ifS)Nr�r�r)r=r�rrrrZs�zserverreactor._makeerrorresultcCs�|j|}|ds"d|_t�d��|j|=|jr8d|_nd|_|d�d�t�|d���d}d|vr~d|_|�t	d	��Sd
|vr�i|d
<|j
�|�d||d|d
|�d�|d
r�|d
��ndd�fS)N�requestdoners,should not be called without requestdone setrr�payloadrr`s$command request missing "name" fieldras
runcommandrb�data)s	requestidscommandrarbr/)
r�r�rr��seekr�	decodeall�getvaluerrr��addr#)r=r2�entry�requestrrr�_makeruncommandresult_s8
����z#serverreactor._makeruncommandresultcCsdd|jifS)Ns	wantframesstate)r�r�rrr�_makewantframeresult�s�z"serverreactor._makewantframeresultcCsP|jt@}|jt@}|r0|r0d|_|�td��S|sL|sLd|_|�td��SdS)NrsGreceived command request frame with both new and continuation flags setsJreceived command request frame with neither new nor continuation flags set)r'rdrer�rr)r=r7�newZcontinuationrrr�_validatecommandrequestframe�s 

����z*serverreactor._validatecommandrequestframecCs\|jtkr$d|_t��|_|�|�S|jtkr>d|_|�|�Sd|_|�	t
d�|j�SdS)NrrrsBexpected sender protocol settings or command request frame; got %d)r5�#FRAME_TYPE_SENDER_PROTOCOL_SETTINGSr�r�bufferingdecoderr�rrhr	rr�r=r7rrrr�s




���zserverreactor._onframeinitialc
CsL|jtkr$d|_|�td�|j�S|jt@}|jt@}|rT|rTd|_|�td��S|sp|spd|_|�td��Sz|j�	|j
�WnBty�}z*d|_|�td�t�
|��WYd}~Sd}~00|r�|��S|j��}d|_|�s�d|_|�td��St|�dk�rd|_|�td��S|d	}d
|v�r>|d
|jd
<d|_|��S)Nrs/expected sender protocol settings frame; got %dsXsender protocol settings frame cannot have both continuation and end of stream flags setsOsender protocol settings frame must have continuation or end of stream flag sets;error decoding CBOR from sender protocol settings frame: %ss8sender protocol settings frame did not contain CBOR datars=sender protocol settings frame contained multiple CBOR valuesrr�r)r5r:r�rrr'�*FLAG_SENDER_PROTOCOL_SETTINGS_CONTINUATION�!FLAG_SENDER_PROTOCOL_SETTINGS_EOSr�r�r:rr
rr7�getavailabler9r)r=r7�more�eosr�decoded�drrrr�sn
��

����	���
���
z&serverreactor._onframeprotocolsettingscCs
|jtkr$d|_|�td�|j�S|�|�}|r6|S|j|jvr\d|_|�td�|j�S|j|jvr�d|_|�td�|j�S|j	t
@}|j	t@}|j	t@}|s�d|_|�td��St
��}|�|j�|d|t|�d�|j|j<|s�|s�|�|j�Sd|_|��S)Nrs&expected command request frame; got %ds#request with ID %d already receiveds$request with ID %d is already actives3received command request frame without new flag set)r.r/r-�
expectingdatar)r5rhr�rrr9r2r�r�r'rdrgrfr
�bytesio�writer:�boolr6r7)r=r7r�r8�
moreframes�
expectingdatar:rrrr	sJ
�
��


��zserverreactor._onframeidlecCs�|jtkr0|jt@r|�|�S|�|�}|r0|S|j|jvrVd|_|�	t
d�|j�S|j|jvr|d|_|�	t
d�|j�S|j|j}|jtk�r&|jt@}t
|jt@�}|dr�d|_|�	t
d��S||dkr�d|_|�	t
d��S|d�|j�|�sd	|d<|�s|�s|�|j�S|��S|jtk�r||d�sVd|_|�	t
d
�|j�S|ddu�rpt��|d<|�||�Sd|_|�	t
d�|j�SdS)
Nrs3received frame for request that is still active: %ds4received frame for request that is not receiving: %dr-sGreceived command request frame when request frames were supposedly donerDs4mismatch between expect data flag and previous framer.TsFreceived command data frame for request that is not expecting data: %dr/s"received unexpected frame type: %d)r5rhr'rdr	r9r2r�r�rrr�rgrGrfrFr:r6r7rlr
rE�_handlecommanddataframe)r=r7r�r4rHrIrrrr
;sv



����
���
����z&serverreactor._onframecommandreceivingcCs^|d�|j�|jt@r"|��S|jt@rF|d�d�|�|j�Sd|_	|�
td��SdS)Nr/rrs command data frame without flags)rFr:r'rjr7rkr0r6r2r�rr)r=r7r4rrrrJ�s

z%serverreactor._handlecommanddataframecCs|�td��S)Nsserver already errored)rrr<rrrr�szserverreactor._onframeerrored)F)N)r,r-r.r/r�rrr%rr)r+r,rr6r7r9rrr	r
rJrrrrrr��s(@
 1	
+L5Nr�c@seZdZdZddd�ZdS)�commandrequestz&Represents a request to run a command.NcCs(||_||_||_||_||_d|_dS)Nspending)r2r?rorprr�state)r=r2r?rorprrrrrr��szcommandrequest.__init__)NN)r,r-r.r/r�rrrrrK�srKc@sTeZdZdZddd�Zddd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�ZdS)�
clientreactora�Holds state of a client issuing frame-based protocol requests.

    This is like ``serverreactor`` but for client-side state.

    Each instance is bound to the lifetime of a connection. For persistent
    connection transports using e.g. TCP sockets and speaking the raw
    framing protocol, there will be a single instance for the lifetime of
    the TCP socket. For transports where there are multiple discrete
    interactions (say tunneled within in HTTP request), there will be a
    separate instance for each distinct interaction.

    Consumers are expected to tell instances when events occur by calling
    various methods. These methods return a 2-tuple describing any follow-up
    action(s) to take. The first element is the name of an action to
    perform. The second is a data structure (usually a dict) specific to
    that action that contains more information. e.g. if the reactor wants
    to send frames to the server, the data structure will contain a reference
    to those frames.

    Valid actions that consumers can be instructed to take are:

    noop
       Indicates no additional action is required.

    sendframes
       Indicates that frames should be sent to the server. The ``framegen``
       key contains a generator of frames that should be sent. The reactor
       assumes that all frames in this generator are sent to the server.

    error
       Indicates that an error occurred. The ``message`` key contains an
       error message describing the failure.

    responsedata
       Indicates a response to a previously-issued command was received.

       The ``request`` key contains the ``commandrequest`` instance that
       represents the request this data is for.

       The ``data`` key contains the decoded data from the server.

       ``expectmore`` and ``eos`` evaluate to True when more response data
       is expected to follow or we're at the end of the response stream,
       respectively.
    FTNcCs`||_||_||_||_d|_d|_d|_d|_td�|_	t
��|_i|_
i|_i|_t�dS)a�Create a new instance.

        ``hasmultiplesend`` indicates whether multiple sends are supported
        by the transport. When True, it is possible to send commands immediately
        instead of buffering until the caller signals an intent to finish a
        send operation.

        ``buffercommands`` indicates whether sends should be buffered until the
        last request has been issued.

        ``clientcontentencoders`` is an iterable of content encoders the client
        will advertise to the server and that the server can use for encoding
        data. If not defined, the client will not advertise content encoders
        to the server.
        TFrN)r��_hasmultiplesend�_buffersends�_clientcontentencoders�_canissuecommands�_cansend�_protocolsettingssent�_nextrequestidr��_outgoingstream�collections�deque�_pendingrequests�_activerequestsr��_streamsettingsdecodersr�)r=r�ZhasmultiplesendZbuffersendsZclientcontentencodersrrrr��s

zclientreactor.__init__cCs�|jst�d��|j}|jd7_t|||||d�}|jrR|j�|�|difS|jsbt�d��|j	std|_d|_|dd|�
|�ifSd	S)
aRequest that a command be executed.

        Receives the command name, a dict of arguments to pass to the command,
        and an optional file object containing the raw data for the command.

        Returns a 3-tuple of (request, action, action data).
        scannot issue new commandsr�rprrr �*sends cannot be performed on this instanceFr#r$N)rQrr�rTrKrOrXr"rRrN�_makecommandframes)r=r?rorprrr2r5rrr�callcommands,

�
�
��zclientreactor.callcommandcsJ�jsdifS�jst�d���js0d�_d�_�fdd�}dd|�ifS)a_Request that all queued commands be sent.

        If any commands are buffered, this will instruct the caller to send
        them over the wire. If no commands are buffered it instructs the client
        to no-op.

        If instances aren't configured for multiple sends, no new command
        requests are allowed after this is called.
        r r\Fc3s,�jr(�j��}��|�D]
}|VqqdSr�)rX�popleftr])r5r7r�rr�
makeframes?s
z/clientreactor.flushcommands.<locals>.makeframesr#r$)rXrRrr�rNrQ)r=r`rr�r�
flushcommands's
��zclientreactor.flushcommandsccs�||j|j<d|_|jsR|jrRd|_d�t�d|ji��}|jj	|jt
t|d�Vt|j|j|j
|j|j|jd�}|D]
}|Vqvd|_dS)	z�Emit frames to issue a command request.

        As a side-effect, update request accounting to reflect its changed
        state.
        ssendingTrr�rcr[ssentN)rYr2rLrSrPr$rrMrUrHr:r>rur?rorprr)r=r5r:r�r7rrrr]Is6�����	z clientreactor._makecommandframescCs|jdr ddtd�|jifS|j|jvrX|jt@sFddtd�ifSt|j�|j|j<|j|j}|jt@r||�|j�|_|jt	@r�|j|j=|j
tkr�|�|�S|j
|jvr�ddtd�|j
ifS|j|j
}d|_t|jt|ji}|�|j
�}|�s
t�d|j
��|||�S)	z�Process a frame that has been received off the wire.

        Returns a 2-tuple of (action, meta) describing further action the
        caller needs to take as a result of receiving this frame.
        rr�r�s.received frame with odd numbered stream ID: %dsEreceived frame on unknown stream without beginning of stream flag sets*received frame for inactive request ID: %ds	receivingsunhandled frame type: %d)r3rr�r4r�r�r�r�r:rr5r��_onstreamsettingsframer2rYrLr{�_oncommandresponseframer��_onerrorresponseframer#rr�)r=r7rmr5rr
rrrrrsV
���

���





���
��zclientreactor.onframerecvc
Csd|jt@}|jt@}|r,|r,ddtd�ifS|sD|sDddtd�ifS|j|jvrdt��}||j|j<|j|j}z|�|j	�Wn>t
y�}z&ddtd�t�|�ifWYd}~Sd}~00|r�difS|�
�}|j|j=|s�ddtd�ifSz(|j|j�|j|d|d	d��Wn@t
�yZ}z&ddtd
�t�|�ifWYd}~Sd}~00difS)Nr�r�sXstream encoding settings frame cannot have both continuation and end of stream flags setsOstream encoding settings frame must have continuation or end of stream flag sets;error decoding CBOR from stream encoding settings frame: %sr s8stream encoding settings frame did not contain CBOR datarrs error setting stream decoder: %s)r'�*FLAG_STREAM_ENCODING_SETTINGS_CONTINUATIONr�rr3rZrr;r�r:rr
rr?r�r�r�)r=r7r@rA�decoderrrBrrrrb�sr

������
����

���
����
z$clientreactor._onstreamsettingsframecCs:|jt@rd|_|j|j=d||jt@|jt@|jd�fS)Nsreceivedsresponsedata)�requests
expectmorerr/)r'r�rLrYr2r|r:)r=r5r7rrrrcs

��z%clientreactor._oncommandresponseframecCs8d|_|j|j=t�|j�d}d||d|dd�fS)Nrrr�r�r�)rgr�r�)rLrYr2rr1r:)r=r5r7r�rrrrd!s
��z#clientreactor._onerrorresponseframe)FTN)NN)r,r-r.r/r�r^rar]rrbrcrdrrrrrM�s1�
)
'")HXrM)N)YZ
__future__rrVrDZi18nrr	rZ
thirdpartyrr�rrr
rZutilsrr
rCrir�rr�r;rhrlr{r�r�ZFRAME_TYPE_PROGRESSr:r�r8rdrergrfZFLAGS_COMMAND_REQUESTrjrkZFLAGS_COMMAND_DATAr|r�ZFLAGS_COMMAND_RESPONSEr=r>ZFLAGS_SENDER_PROTOCOL_SETTINGSrer�ZFLAGS_STREAM_ENCODING_SETTINGSr<�StructZARGUMENT_RECORD_HEADERr)rN�objectr+r7rHrSrYr_rur~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rmr�r�r�r�r�rKrMrrrr�<module>s���������

 B'�
M�
%
�
8n
!U	�5

Youez - 2016 - github.com/yon3zu
LinuXploit