%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/protocols/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/protocols/__pycache__/basic.cpython-312.pyc

�

Ϫ�f�{��&�dZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
mZddlmZd�Zd	e_dZGd
�de�ZGd�d
e�ZGd�dej.�ZGd�dej.�ZGd�d�ZGd�dej.e�ZGd�de�ZGd�d�ZGd�dej.e�ZGd�de�Z Gd�de�Z!Gd �d!e�Z"Gd"�d#�Z#e
e
jH�Gd$�d%��Z%y)&zN
Basic protocols, such as line-oriented, netstring, and int prefixed strings.
�N)�BytesIO)�calcsize�pack�unpack)�implementer)�defer�
interfaces�protocol)�logc�n�djtt|��jd�d|dg�S)N��ascii�:�,)�join�str�len�encode)�datas �9/usr/lib/python3/dist-packages/twisted/protocols/basic.py�_formatNetstringrs-���8�8�S��T��^�*�*�7�3�T�4��F�G�Gr
z_
Convert some C{bytes} into netstring format.

@param data: C{bytes} that will be reformatted.
c��eZdZdZy)�NetstringParseErrorz=
    The incoming data is not in valid Netstring format.
    N��__name__�
__module__�__qualname__�__doc__�r
rrr)���r
rc��eZdZdZy)�IncompleteNetstringz2
    Not enough data to complete a netstring.
    Nrrr
rr"r"/r r
r"c���eZdZdZdZejd�Zejd�ZdZ	dZ
dZdZe
d	�\ZZd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!y)�NetstringReceiveraM

    A protocol that sends and receives netstrings.

    See U{http://cr.yp.to/proto/netstrings.txt} for the specification of
    netstrings. Every netstring starts with digits that specify the length
    of the data. This length specification is separated from the data by
    a colon. The data is terminated with a comma.

    Override L{stringReceived} to handle received netstrings. This
    method is called with the netstring payload as a single argument
    whenever a complete netstring is received.

    Security features:
        1. Messages are limited in size, useful if you don't want
           someone sending you a 500MB netstring (change C{self.MAX_LENGTH}
           to the maximum length you wish to accept).
        2. The connection is lost if an illegal message is received.

    @ivar MAX_LENGTH: Defines the maximum length of netstrings that can be
        received.
    @type MAX_LENGTH: C{int}

    @ivar _LENGTH: A pattern describing all strings that contain a netstring
        length specification. Examples for length specifications are C{b'0:'},
        C{b'12:'}, and C{b'179:'}. C{b'007:'} is not a valid length
        specification, since leading zeros are not allowed.
    @type _LENGTH: C{re.Match}

    @ivar _LENGTH_PREFIX: A pattern describing all strings that contain
        the first part of a netstring length specification (without the
        trailing comma). Examples are '0', '12', and '179'. '007' does not
        start a netstring length specification, since leading zeros are
        not allowed.
    @type _LENGTH_PREFIX: C{re.Match}

    @ivar _PARSING_LENGTH: Indicates that the C{NetstringReceiver} is in
        the state of parsing the length portion of a netstring.
    @type _PARSING_LENGTH: C{int}

    @ivar _PARSING_PAYLOAD: Indicates that the C{NetstringReceiver} is in
        the state of parsing the payload portion (data and trailing comma)
        of a netstring.
    @type _PARSING_PAYLOAD: C{int}

    @ivar brokenPeer: Indicates if the connection is still functional
    @type brokenPeer: C{int}

    @ivar _state: Indicates if the protocol is consuming the length portion
        (C{PARSING_LENGTH}) or the payload (C{PARSING_PAYLOAD}) of a netstring
    @type _state: C{int}

    @ivar _remainingData: Holds the chunk of data that has not yet been consumed
    @type _remainingData: C{string}

    @ivar _payload: Holds the payload portion of a netstring including the
        trailing comma
    @type _payload: C{BytesIO}

    @ivar _expectedPayloadSize: Holds the payload size plus one for the trailing
        comma.
    @type _expectedPayloadSize: C{int}
    韆s(0|[1-9]\d*)(:)s
(0|[1-9]\d*)$zBThe received netstring does not start with a length specification.zpThe length specification of the received netstring cannot be represented in Python - it causes an OverflowError!zQThe received netstring is longer than the maximum %s specified by self.MAX_LENGTHz4The received netstring is not terminated by a comma.�c��tjj||�d|_d|_t�|_|j|_d|_	d|_
y)z+
        Initializes the protocol.
        r
rN)r
�Protocol�makeConnection�_remainingData�_currentPayloadSizer�_payload�_PARSING_LENGTH�_state�_expectedPayloadSize�
brokenPeer)�self�	transports  rr)z NetstringReceiver.makeConnection�sO��	���(�(��y�9�!���#$�� ��	��
��*�*���$%��!���r
c�L�|jjt|��y)a1
        Sends a netstring.

        Wraps up C{string} by adding length information and a
        trailing comma; writes the result to the transport.

        @param string: The string to send.  The necessary framing (length
            prefix, etc) will be added.
        @type string: C{bytes}
        N)r2�writer�r1�strings  r�
sendStringzNetstringReceiver.sendString�s��	
�����-�f�5�6r
c���|xj|z
c_|jr	|j�|jr�yy#t$rYyt$r|j	�YywxYw)a=
        Receives some characters of a netstring.

        Whenever a complete netstring is received, this method extracts
        its payload and calls L{stringReceived} to process it.

        @param data: A chunk of data representing a (possibly partial)
            netstring
        @type data: C{bytes}
        N)r*�_consumeDatar"r�_handleParseError�r1rs  r�dataReceivedzNetstringReceiver.dataReceived�se��	
���t�#���!�!�
��!�!�#��!�!��'�
��&�
��&�&�(��
�s�A�	A(�
A(�'A(c��t��)a^
        Override this for notification when each complete string is received.

        @param string: The complete string which was received with all
            framing (length prefix, etc) removed.
        @type string: C{bytes}

        @raise NotImplementedError: because the method has to be implemented
            by the child class.
        ��NotImplementedErrorr5s  r�stringReceivedz NetstringReceiver.stringReceived�s
��"�#�#r
c�l�tjtj|j��dzS)z�
        Calculate and return the string size of C{self.MAX_LENGTH}.

        @return: The size of the string representation for C{self.MAX_LENGTH}
        @rtype: C{float}
        �)�math�ceil�log10�
MAX_LENGTH�r1s r�_maxLengthSizez NetstringReceiver._maxLengthSize�s%���y�y����D�O�O�4�5��9�9r
c���|j|jk(r |j�|j�|j|jk(r|j�yy)a0
        Consumes the content of C{self._remainingData}.

        @raise IncompleteNetstring: if C{self._remainingData} does not
            contain enough data to complete the current netstring.
        @raise NetstringParseError: if the received data do not
            form a valid netstring.
        N)r.r-�_consumeLength�_prepareForPayloadConsumption�_PARSING_PAYLOAD�_consumePayloadrGs rr9zNetstringReceiver._consumeData�sQ���;�;�$�.�.�.����!��.�.�0��;�;�$�/�/�/�� � �"�0r
c��|jj|j�}|s|j�t	��|j|�y)aL
        Consumes the length portion of C{self._remainingData}.

        @raise IncompleteNetstring: if C{self._remainingData} contains
            a partial length specification (digits without trailing
            comma).
        @raise NetstringParseError: if the received data do not form a valid
            netstring.
        N)�_LENGTH�matchr*� _checkPartialLengthSpecificationr"�_processLength)r1�lengthMatchs  rrJz NetstringReceiver._consumeLength�sD���l�l�(�(��)<�)<�=����1�1�3�%�'�'����K�(r
c��|jj|j�}|st|j��|jd�}|j
|�y)aB
        Makes sure that the received data represents a valid number.

        Checks if C{self._remainingData} represents a number smaller or
        equal to C{self.MAX_LENGTH}.

        @raise NetstringParseError: if C{self._remainingData} is no
            number or is too big (checked by L{_extractLength}).
        rBN)�_LENGTH_PREFIXrPr*r�_MISSING_LENGTH�group�_extractLength)r1�partialLengthMatch�lengthSpecifications   rrQz2NetstringReceiver._checkPartialLengthSpecification�sU��"�0�0�6�6�t�7J�7J�K��!�%�d�&:�&:�;�;�0�6�6�q�9�����/�0r
c��|jd�}|jd�}|jd|}|j|�dz|_|j|d|_y)aY
        Processes the length definition of a netstring.

        Extracts and stores in C{self._expectedPayloadSize} the number
        representing the netstring size.  Removes the prefix
        representing the length specification from
        C{self._remainingData}.

        @raise NetstringParseError: if the received netstring does not
            start with a number or the number is bigger than
            C{self.MAX_LENGTH}.
        @param lengthMatch: A regular expression match object matching
            a netstring length specification
        @type lengthMatch: C{re.Match}
        rBr&N)�endr*rXr/)r1rS�endOfNumber�startOfData�lengthStrings     rrRz NetstringReceiver._processLengths_�� "�o�o�a�(��!�o�o�a�(���*�*�<�K�8��$(�$7�$7��$E��$I��!�"�1�1�+�,�?��r
c��|j|�t|�}||jkDr#t|j|jfz��|S)ay
        Attempts to extract the length information of a netstring.

        @raise NetstringParseError: if the number is bigger than
            C{self.MAX_LENGTH}.
        @param lengthAsString: A chunk of data starting with a length
            specification
        @type lengthAsString: C{bytes}
        @return: The length of the netstring
        @rtype: C{int}
        )�_checkStringSize�intrFr�	_TOO_LONG)r1�lengthAsString�lengths   rrXz NetstringReceiver._extractLengthsH��	
���n�-��^�$���D�O�O�#�%�d�n�n����7I�&I�J�J��
r
c��t|�|j�kDr#t|j|jfz��y)a>
        Checks the sanity of lengthAsString.

        Checks if the size of the length specification exceeds the
        size of the string representing self.MAX_LENGTH. If this is
        not the case, the number represented by lengthAsString is
        certainly bigger than self.MAX_LENGTH, and a
        NetstringParseError can be raised.

        This method should make sure that netstrings with extremely
        long length specifications are refused before even attempting
        to convert them to an integer (which might trigger a
        MemoryError).
        N)rrHrrcrF)r1rds  rraz"NetstringReceiver._checkStringSize)s:���~���!4�!4�!6�6�%�d�n�n����7I�&I�J�J�7r
c��|j|_d|_|jj	d�|jj�y)zW
        Sets up variables necessary for consuming the payload of a netstring.
        rN)rLr.r+r,�seek�truncaterGs rrKz/NetstringReceiver._prepareForPayloadConsumption;s;���+�+���#$�� ��
�
���1���
�
��� r
c���|j�|j|jkr
t��|j	�|j
|_|j�y)a�
        Consumes the payload portion of C{self._remainingData}.

        If the payload is complete, checks for the trailing comma and
        processes the payload. If not, raises an L{IncompleteNetstring}
        exception.

        @raise IncompleteNetstring: if the payload received so far
            contains fewer characters than expected.
        @raise NetstringParseError: if the payload does not end with a
        comma.
        N)�_extractPayloadr+r/r"�_checkForTrailingCommar-r.�_processPayloadrGs rrMz!NetstringReceiver._consumePayloadDsR��	
�����#�#�d�&?�&?�?�%�'�'��#�#�%��*�*������r
c��|j�rg|j|jz
}|jj	|j
d|�|j
|d|_|j|_y|jj	|j
�|xjt
|j
�z
c_d|_y)a
        Extracts payload information from C{self._remainingData}.

        Splits C{self._remainingData} at the end of the netstring.  The
        first part becomes C{self._payload}, the second part is stored
        in C{self._remainingData}.

        If the netstring is not yet complete, the whole content of
        C{self._remainingData} is moved to C{self._payload}.
        Nr
)�_payloadCompleter/r+r,r4r*r)r1�remainingPayloadSizes  rrkz!NetstringReceiver._extractPayloadXs���� � �"�#'�#<�#<�t�?W�?W�#W� ��M�M���� 3� 3�4I�5I� J�K�"&�"5�"5�6J�6K�"L�D��'+�'@�'@�D�$��M�M���� 3� 3�4��$�$��D�,?�,?�(@�@�$�"%�D�r
c�`�t|j�|jz|jk\S)a

        Checks if enough data have been received to complete the netstring.

        @return: C{True} iff the received data contain at least as many
            characters as specified in the length section of the
            netstring
        @rtype: C{bool}
        )rr*r+r/rGs rroz"NetstringReceiver._payloadCompletems0��
��#�#�$�t�'?�'?�?��(�(�
)�	
r
c�\�|j|jj�dd�y)z�
        Processes the actual payload with L{stringReceived}.

        Strips C{self._payload} of the trailing comma and calls
        L{stringReceived} with the result.
        N���)r@r,�getvaluerGs rrmz!NetstringReceiver._processPayload{s&��	
���D�M�M�2�2�4�S�b�9�:r
c�n�|jj�dddk7rt|j��y)z�
        Checks if the netstring has a trailing comma at the expected position.

        @raise NetstringParseError: if the last payload character is
            anything but a comma.
        rsNr)r,rtr�_MISSING_COMMArGs rrlz(NetstringReceiver._checkForTrailingComma�s6���=�=�!�!�#�B�C�(�D�0�%�d�&9�&9�:�:�1r
c�F�|jj�d|_y)zQ
        Terminates the connection and sets the flag C{self.brokenPeer}.
        rBN)r2�loseConnectionr0rGs rr:z#NetstringReceiver._handleParseError�s��	
���%�%�'���r
N)"rrrrrF�re�compilerOrUrV�	_OVERFLOWrcrv�ranger-rLr)r7r<r@rHr9rJrQrRrXrarKrMrkrormrlr:rr
rr$r$5s���=�~�J��b�j�j�,�-�G��R�Z�Z� 1�2�N�	P��	��	'��L�N�).�a��%�O�%�
�7��*$�:�
#�)� 1� @�.�$K�$!��(&�*
�;�;�r
r$c�4�eZdZdZdZdZdZd�Zd�Zd�Z	d�Z
y	)
�LineOnlyReceivera�
    A protocol that receives only lines.

    This is purely a speed optimisation over LineReceiver, for the
    cases that raw mode is known to be unnecessary.

    @cvar delimiter: The line-ending delimiter to use. By default this is
                     C{b'\r\n'}.
    @cvar MAX_LENGTH: The maximum length of a line to allow (If a
                      sent line is longer than this, the connection is dropped).
                      Default is 16384.
    r
�
�@c��|j|zj|j�}|jd�|_|D]V}|jj
ryt
|�|jkDr|j|�cS|j|��Xt
|j�|jkDr|j|j�Sy)zF
        Translates bytes into lines, and calls lineReceived.
        rsN)
�_buffer�split�	delimiter�popr2�
disconnectingrrF�lineLengthExceeded�lineReceived)r1r�lines�lines    rr<zLineOnlyReceiver.dataReceived�s�������$�+�+�D�N�N�;���y�y��}����
	(�D��~�~�+�+�
��4�y�4�?�?�*��.�.�t�4�4��!�!�$�'�
	(��t�|�|��t���.��*�*�4�<�<�8�8�/r
c��t��z�
        Override this for when each line is received.

        @param line: The line which was received with the delimiter removed.
        @type line: C{bytes}
        r>�r1r�s  rr�zLineOnlyReceiver.lineReceived��
��"�!r
c�P�|jj||jf�S�z�
        Sends a line to the other end of the connection.

        @param line: The line to send, not including the delimiter.
        @type line: C{bytes}
        )r2�
writeSequencer�r�s  r�sendLinezLineOnlyReceiver.sendLine�s"���~�~�+�+�T�4�>�>�,B�C�Cr
c�6�|jj�S)z�
        Called when the maximum line length has been reached.
        Override if it needs to be dealt with in some special way.
        �r2rxr�s  rr�z#LineOnlyReceiver.lineLengthExceeded�s��
�~�~�,�,�.�.r
N)rrrrr�r�rFr<r�r�r�rr
rr~r~�s-����G��I��J�9�("�D�/r
r~c�"�eZdZdZd�Zd�Zd�Zy)�_PauseableMixinFc�F�d|_|jj�y�NT)�pausedr2�pauseProducingrGs rr�z_PauseableMixin.pauseProducing�s��������%�%�'r
c�h�d|_|jj�|jd�y)NFr
)r�r2�resumeProducingr<rGs rr�z_PauseableMixin.resumeProducing�s'��������&�&�(����#�r
c�F�d|_|jj�yr�)r�r2�
stopProducingrGs rr�z_PauseableMixin.stopProducing�s��������$�$�&r
N)rrrr�r�r�r�rr
rr�r��s��
�F�(��
'r
r�c�V�eZdZdZdZdZdZdZdZd�Z	d�Z
dd	�Zd
�Zd�Z
d�Zd
�Zd�Zy)�LineReceivera�
    A protocol that receives lines and/or raw data, depending on mode.

    In line mode, each line that's received becomes a callback to
    L{lineReceived}.  In raw data mode, each chunk of raw data becomes a
    callback to L{LineReceiver.rawDataReceived}.
    The L{setLineMode} and L{setRawMode} methods switch between the two modes.

    This is useful for line-oriented protocols such as IRC, HTTP, POP, etc.

    @cvar delimiter: The line-ending delimiter to use. By default this is
                     C{b'\r\n'}.
    @cvar MAX_LENGTH: The maximum length of a line to allow (If a
                      sent line is longer than this, the connection is dropped).
                      Default is 16384.
    rBr
Frr�c�.�|jdc}|_|S)zs
        Clear buffered data.

        @return: All of the cleared buffered data.
        @rtype: C{bytes}
        r
)r�)r1�bs  r�clearLineBufferzLineReceiver.clearLineBuffer�s���,�,����4�<��r
c��|jr|xj|z
c_y	d|_|xj|z
c_|j�r$|j�s|jr�	|jj	|j
d�\}|_t
|�}||jkDr;||j
z|jz}d|_|j|�d|_S|j|�}|s"|jrN|jjr8|d|_S|j}d|_|j|�}|r	|d|_S|jr|js��d|_y#t$rpt
|j�|jt
|j
�zk\r.|jdc}|_|j|�cYd|_SYd|_ywxYw#d|_wxYw)z�
        Protocol.dataReceived.
        Translates bytes into lines, and calls lineReceived (or
        rawDataReceived, depending on mode.)
        NTrBr
F)�_busyReceivingr�r��	line_moder�r�rrFr�r�r2r��
ValueError�rawDataReceived)r1rr��
lineLength�exceeded�whys      rr<zLineReceiver.dataReceived	s�������L�L�D� �L��	(�"&�D���L�L�D� �L��,�,�t�{�{��>�>�'�-1�\�\�-?�-?����PQ�-R�*��d�l�&)��Y�
�%����7�'+�d�n�n�'<�t�|�|�'K�H�+.�D�L�#'�#:�#:�8�#D�#(�D��#�/�/��5���$�.�.�T�^�^�5Q�5Q�#&�#(�D��
 �<�<�D�#&�D�L��.�.�t�4�C��"�"'�D��3�,�,�t�{�{�2#(�D���+&���t�|�|�,����3�t�~�~�CV�1V�W�15���s�.�D�$�,�#'�#:�#:�4�#@�@�$#(�D��#�"#(�D��+��*#(�D��sJ�AG5�'.E9�A
G5�*6G5�('G5�G5�9A&G2�G5�(G5�1G2�2G5�5	G>c�8�d|_|r|j|�Sy)a�
        Sets the line-mode of this receiver.

        If you are calling this from a rawDataReceived callback,
        you can pass in extra unhandled data, and that data will
        be parsed for lines.  Further data received will be sent
        to lineReceived rather than rawDataReceived.

        Do not pass extra data if calling this function from
        within a lineReceived callback.
        rBN)r�r<)r1�extras  r�setLineModezLineReceiver.setLineMode1s$�������$�$�U�+�+�r
c��d|_y)z�
        Sets the raw mode of this receiver.
        Further data received will be sent to rawDataReceived rather
        than lineReceived.
        rN)r�rGs r�
setRawModezLineReceiver.setRawModeAs����r
c��t�)z>
        Override this for when raw data is received.
        r>r;s  rr�zLineReceiver.rawDataReceivedIs
��"�!r
c��t�r�r>r�s  rr�zLineReceiver.lineReceivedOr�r
c�R�|jj||jz�Sr�)r2r4r�r�s  rr�zLineReceiver.sendLineXs"���~�~�#�#�D�4�>�>�$9�:�:r
c�6�|jj�S)aw
        Called when the maximum line length has been reached.
        Override if it needs to be dealt with in some special way.

        The argument 'line' contains the remainder of the buffer, starting
        with (at least some part) of the line which is too long. This may
        be more than one line, or may be only the initial portion of the
        line.
        r�r�s  rr�zLineReceiver.lineLengthExceededas���~�~�,�,�.�.r
N)r
)rrrrr�r�r�r�rFr�r<r�r�r�r�r�r�rr
rr�r��sK���"�I��G��N��I��J��&(�P,� �"�"�;�
/r
r�c��eZdZdZy)�StringTooLongErrorzZ
    Raised when trying to send a string too long for a length prefixed
    protocol.
    Nrrr
rr�r�ns��r
r�c��eZdZdZdd�Zy)�_RecvdCompatHackaK
    Emulates the to-be-deprecated C{IntNStringReceiver.recvd} attribute.

    The C{recvd} attribute was where the working buffer for buffering and
    parsing netstrings was kept.  It was updated each time new data arrived and
    each time some of that data was parsed and delivered to application code.
    The piecemeal updates to its string value were expensive and have been
    removed from C{IntNStringReceiver} in the normal case.  However, for
    applications directly reading this attribute, this descriptor restores that
    behavior.  It only copies the working buffer when necessary (ie, when
    accessed).  This avoids the cost for applications not using the data.

    This is a custom descriptor rather than a property, because we still need
    the default __set__ behavior in both new-style and old-style subclasses.
    Nc�4�|j|jdS�N)�_unprocessed�_compatibilityOffset)r1�oself�types   r�__get__z_RecvdCompatHack.__get__�s���!�!�%�"<�"<�">�?�?r
r�)rrrrr�rr
rr�r�us
��� @r
r�c�B�eZdZdZdZdZdZe�Zd�Z	d�Z
d�Zd�Zy	)
�IntNStringReceivera,
    Generic class for length prefixed protocols.

    @ivar _unprocessed: bytes received, but not yet broken up into messages /
        sent to stringReceived.  _compatibilityOffset must be updated when this
        value is updated so that the C{recvd} attribute can be generated
        correctly.
    @type _unprocessed: C{bytes}

    @ivar structFormat: format used for struct packing/unpacking. Define it in
        subclass.
    @type structFormat: C{str}

    @ivar prefixLength: length of the prefix, in bytes. Define it in subclass,
        using C{struct.calcsize(structFormat)}
    @type prefixLength: C{int}

    @ivar _compatibilityOffset: the offset within C{_unprocessed} to the next
        message to be parsed. (used to generate the recvd attribute)
    @type _compatibilityOffset: C{int}
    r%r
rc��t�)z�
        Override this for notification when each complete string is received.

        @param string: The complete string which was received with all
            framing (length prefix, etc) removed.
        @type string: C{bytes}
        r>r5s  rr@z!IntNStringReceiver.stringReceived�s
��"�!r
c�8�|jj�y)a
        Callback invoked when a length prefix greater than C{MAX_LENGTH} is
        received.  The default implementation disconnects the transport.
        Override this.

        @param length: The length prefix which was received.
        @type length: C{int}
        Nr�)r1res  r�lengthLimitExceededz&IntNStringReceiver.lengthLimitExceeded�s��	
���%�%�'r
c�f�|j|z}d}|j}|j}||_t|�||zk\r�|js�||z}t||||�\}||jkDr ||_||_|j|�y||z}t|�|krnz|||}	|}||_|j|	�d|jvr/|jjd�}||_dx|_}|r��yt|�||zk\r
|js��||d|_d|_y)zL
        Convert int prefixed strings into calls to stringReceived.
        rN�recvd)r��prefixLength�structFormatrr�rrFr�r�r@�__dict__r�)
r1r�alldata�
currentOffsetr��fmt�messageStartre�
messageEnd�packets
          rr<zIntNStringReceiver.dataReceived�sO���#�#�d�*���
��(�(������#����'�l�}�|�;�<�T�[�[�(�<�7�L��s�G�M�,�$G�H�I�V�����'�$+��!�,9��)��(�(��0��%��.�J��7�|�j�(���\�*�5�F�&�M�(5�D�%�����'�
�$�-�-�'��-�-�+�+�G�4��$+��!�<=�=��)�M����9�'�l�}�|�;�<�T�[�[�B$�M�N�3���$%��!r
c�
�t|�dd|jzzk\r*tdt|��ddd|jzz����|jj	t|jt|��|z�y)z�
        Send a prefixed string to the other end of the connection.

        @param string: The string to send.  The necessary framing (length
            prefix, etc) will be added.
        @type string: C{bytes}
        r&�zTry to send z bytes whereas maximum is N)rr�r�r2r4rr�r5s  rr7zIntNStringReceiver.sendString�su���v�;�!��D�$5�$5� 5�6�6�$��v�;��a�$�*;�*;�&;� <�>��
�	
�����T�$�"3�"3�S��[�A�F�J�Kr
N)
rrrrrFr�r�r�r�r@r�r<r7rr
rr�r��s9���,�J��L���
��E�"�	(�/&�b
Lr
r�c�$�eZdZdZdZee�Zy)�Int32StringReceiverz�
    A receiver for int32-prefixed strings.

    An int32 string is a string prefixed by 4 bytes, the 32-bit length of
    the string encoded in network byte order.

    This class publishes the same interface as NetstringReceiver.
    z!IN�rrrrr�rr�rr
rr�r�������L��L�)�Lr
r�c�$�eZdZdZdZee�Zy)�Int16StringReceiverz�
    A receiver for int16-prefixed strings.

    An int16 string is a string prefixed by 2 bytes, the 16-bit length of
    the string encoded in network byte order.

    This class publishes the same interface as NetstringReceiver.
    z!HNr�rr
rr�r�
r�r
r�c�$�eZdZdZdZee�Zy)�Int8StringReceiverz�
    A receiver for int8-prefixed strings.

    An int8 string is a string prefixed by 1 byte, the 8-bit length of
    the string.

    This class publishes the same interface as NetstringReceiver.
    z!BNr�rr
rr�r�r�r
r�c��eZdZdZdZd�Zy)�StatefulStringProtocola�
    A stateful string protocol.

    This is a mixin for string protocols (L{Int32StringReceiver},
    L{NetstringReceiver}) which translates L{stringReceived} into a callback
    (prefixed with C{'proto_'}) depending on state.

    The state C{'done'} is special; if a C{proto_*} method returns it, the
    connection will be closed immediately.

    @ivar state: Current state of the protocol. Defaults to C{'init'}.
    @type state: C{str}
    �initc�
�	d|jz}t||�}||�|_|jdk(r|jj�yy#t$r$tjd|jd�YywxYw)a�
        Choose a protocol phase function and call it.

        Call back to the appropriate protocol phase; this begins with
        the function C{proto_init} and moves on to C{proto_*} depending on
        what each C{proto_*} function returns.  (For example, if
        C{self.proto_init} returns 'foo', then C{self.proto_foo} will be the
        next function called when a protocol message is received.
        �proto_�done�callbackz	not foundN)�state�getattrr2rx�AttributeErrorr�msg)r1r6�pto�statehandlers    rr@z%StatefulStringProtocol.stringReceived:su��	0��T�Z�Z�'�C�"�4��-�L�&�f�-�D�J��z�z�V�#����-�-�/�$��	�	9��G�G�J��
�
�K�8�	9�s�A�*B�BN)rrrrr�r@rr
rr�r�)s���
�E�0r
r�c�6�eZdZdZdZdZdZd	d�Zd�Zd�Z	d�Z
y)
�
FileSendera
    A producer that sends the contents of a file to a consumer.

    This is a helper for protocols that, at some point, will take a
    file-like object, read its contents, and write them out to the network,
    optionally performing some transformation on the bytes in between.
    r��Nc��||_||_||_tj�x|_}|jj
|d�|S)a�
        Begin transferring a file

        @type file: Any file-like object
        @param file: The file object to read data from

        @type consumer: Any implementor of IConsumer
        @param consumer: The object to write data to

        @param transform: A callable taking one string argument and returning
        the same.  All bytes read from the file are passed through this before
        being written to the consumer.

        @rtype: C{Deferred}
        @return: A deferred whose callback will be invoked when the file has
        been completely written to the consumer. The last byte written to the
        consumer is passed to the callback.
        F)�file�consumer�	transformr�Deferred�deferred�registerProducer)r1r�r�r�r�s     r�beginFileTransferzFileSender.beginFileTransfer^sE��&��	� ��
�"���#(�>�>�#3�3��
���
�
�&�&�t�U�3��r
c��d}|jr%|jj|j�}|sZd|_|jj	�|j
r,|j
j
|j�d|_y|jr|j|�}|jj|�|dd|_y)Nr�rs)
r��read�
CHUNK_SIZEr��unregisterProducerr�r��lastSentr�r4)r1�chunks  rr�zFileSender.resumeProducingys������9�9��I�I�N�N�4�?�?�3�E���D�I��M�M�,�,�.��}�}��
�
�&�&�t�}�}�5� $��
���>�>��N�N�5�)�E��
�
���E�"��b�c�
��
r
c��yr�rrGs rr�zFileSender.pauseProducing�s��r
c�t�|jr,|jjtd��d|_yy)Nz#Consumer asked us to stop producing)r��errback�	ExceptionrGs rr�zFileSender.stopProducing�s-���=�=��M�M�!�!�)�,Q�"R�S� �D�M�r
r�)rrrrr�r�r�r�r�r�r�rr
rr�r�Os,����J��H��H��6#�"
�!r
r�)&rrCry�ior�structrrr�zope.interfacer�twisted.internetrr	r
�twisted.pythonrr�DEBUGr�rr�r"r(r$r~r�r��AssertionErrorr�r�r�r�r�r�r��	IProducerr�rr
r�<module>rs.���
�
��)�)�&�9�8��
H����	
���*���)��^��)�)�^�B=/�x�(�(�=/�@'�'�"D/�8�$�$�o�D/�N���@�@�*rL��*�*�O�rL�j*�,�*�*�,�*�*�+�*�#0�#0�L
�Z�
!�
!�"�@!�@!�#�@!r

Zerion Mini Shell 1.0