HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_loopback.cpython-38.pyc
U


W[�8�@sdZddlmZmZddlmZddlmZddlm	Z	ddl
mZmZddl
mZddlmZdd	lmZdd
lmZmZmZddl
mZmZGdd
�d
ej�ZGdd�de�ZGdd�d�ZGdd�dee	j�ZGdd�dee	j�ZGdd�dee	j�Z Gdd�de	j�Z!dS)z.
Test case for L{twisted.protocols.loopback}.
�)�division�absolute_import)�implementer)�
intToBytes)�unittest)�basic�loopback)�defer)�Protocol)�Deferred)�IAddress�
IPushProducer�
IPullProducer)�reactor�
interfacesc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�SimpleProtocolcCst��|_g|_g|_dS�N)r	r�conn�lines�connLost��self�r�</usr/lib/python3/dist-packages/twisted/test/test_loopback.py�__init__s
zSimpleProtocol.__init__cCs|j�d�dSr)r�callbackrrrr�connectionMadeszSimpleProtocol.connectionMadecCs|j�|�dSr)r�append�r�linerrr�lineReceived!szSimpleProtocol.lineReceivedcCs|j�|�dSr)rr)r�reasonrrr�connectionLost%szSimpleProtocol.connectionLostN)�__name__�
__module__�__qualname__rrr r"rrrrrsrc@seZdZdZdd�ZdS)�DoomProtocolrcCsT|jd7_|jdkr,|�dt|j��t�||�|jddkrP|j��dS)N��sHello ����Hello 3)�i�sendLinerrr r�	transport�loseConnectionrrrrr ,s
zDoomProtocol.lineReceivedN)r#r$r%r+r rrrrr&*sr&c@seZdZdd�Zdd�ZdS)�LoopbackTestCaseMixincsRt��t���fdd�}�j�|����fdd�}t��j���}|�|�|S)Ncs��d��j��dS)N�THIS IS LINE ONE!)r,r-r.��result��srr�	sendALine=s
z<LoopbackTestCaseMixin.testRegularFunction.<locals>.sendALinecs8���jdg���t�j�d���t�j�d�dS)Nr0r'��assertEqualr�lenr�Zignored��cr4rrr�checkBsz8LoopbackTestCaseMixin.testRegularFunction.<locals>.check)rr�addCallbackr	�
maybeDeferred�loopbackFunc�rr5r<�drr:r�testRegularFunction9s
z)LoopbackTestCaseMixin.testRegularFunctioncsRt��t���fdd�}�j�|����fdd�}t��j���}|�|�|S)Ncs��d�dS)N�	DOOM LINE)r,r1r3rrr5Osz=LoopbackTestCaseMixin.testSneakyHiddenDoom.<locals>.sendALinecsR���jdddg����jddddg���t�j�d���t�j�d�dS)NsHello 1sHello 2r*rCr'r6r9r:rrr<Ss
�z9LoopbackTestCaseMixin.testSneakyHiddenDoom.<locals>.check)r&rr=r	r>r?r@rr:r�testSneakyHiddenDoomKs
z*LoopbackTestCaseMixin.testSneakyHiddenDoomN)r#r$r%rBrDrrrrr/8sr/c@s�eZdZeej�Zdd�Zdd�Zdd�Z	dd�Z
d(d
d�Zdd
�Zdd�Z
dd�Zdd�Zd)dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'S)*�LoopbackAsyncTestscCsDGdd�dt�}|�}|�}t�||�|�|j�|�|j�dS)z}
        Test that the client and server protocol both have makeConnection
        invoked on them by loopbackAsync.
        c@seZdZdZdd�ZdS)z<LoopbackAsyncTests.test_makeConnection.<locals>.TestProtocolNcSs
||_dSr)r-�rr-rrr�makeConnectionjszKLoopbackAsyncTests.test_makeConnection.<locals>.TestProtocol.makeConnection)r#r$r%r-rGrrrr�TestProtocolhsrHN)r
r�
loopbackAsyncZassertIsNotNoner-)rrH�server�clientrrr�test_makeConnectioncsz&LoopbackAsyncTests.test_makeConnectioncsjGdd�dt�}|r.|�}t�}|_t�}nt�}|�}t�}|_t�||���fdd�}|�|�S)zJ
        Test one of the permutations of client/server host/peer.
        c@seZdZdd�ZdS)z6LoopbackAsyncTests._hostpeertest.<locals>.TestProtocolcSst�||�|j�|�dSr)r
rG�onConnectionrrFrrrrGyszELoopbackAsyncTests._hostpeertest.<locals>.TestProtocol.makeConnectionN)r#r$r%rGrrrrrHxsrHcs t|���}��t�|��dSr)�getattr�
assertTruerZ
providedBy)r-Zhost��getrrr�	connected�sz3LoopbackAsyncTests._hostpeertest.<locals>.connected)r
rrMrrIr=)rrQ�
testServerrHrJrArKrRrrPr�
_hostpeertesttsz LoopbackAsyncTests._hostpeertestcCs|�dd�S)z�
        Test that the server gets a transport with a properly functioning
        implementation of L{ITransport.getHost}.
        �getHostT�rTrrrr�test_serverHost�sz"LoopbackAsyncTests.test_serverHostcCs|�dd�S)zG
        Like C{test_serverHost} but for L{ITransport.getPeer}
        �getPeerTrVrrrr�test_serverPeer�sz"LoopbackAsyncTests.test_serverPeerrUcCs|�dd�S)z�
        Test that the client gets a transport with a properly functioning
        implementation of L{ITransport.getHost}.
        rUFrV)rrQrrr�test_clientHost�sz"LoopbackAsyncTests.test_clientHostcCs|�dd�S)zH
        Like C{test_clientHost} but for L{ITransport.getPeer}.
        rXFrVrrrr�test_clientPeer�sz"LoopbackAsyncTests.test_clientPeercsjGdd�dt�}G�fdd�dt�}|rB|�}|�}t�}|_n|�}t�}|_|�}t�||�|S)z�
        Test one of the permutations of write/writeSequence client/server.

        @param write: The name of the method to test, C{"write"} or
            C{"writeSequence"}.
        c@seZdZdZdd�ZdS)z9LoopbackAsyncTests._greetingtest.<locals>.GreeteeProtocol�cSs(|j|7_|jdkr$|j�d�dS�N�bytes)�bytes�receivedr�rr_rrr�dataReceived�s
zFLoopbackAsyncTests._greetingtest.<locals>.GreeteeProtocol.dataReceivedN�r#r$r%r_rbrrrr�GreeteeProtocol�srdcseZdZ�fdd�ZdS)z9LoopbackAsyncTests._greetingtest.<locals>.GreeterProtocolcs*�dkr|j�d�n|j�ddg�dS)N�writer^sbytses)r-re�
writeSequencer�rerrr�szHLoopbackAsyncTests._greetingtest.<locals>.GreeterProtocol.connectionMadeN�r#r$r%rrrgrr�GreeterProtocol�sri)r
rr`rrI)rrerSrdrirJrKrArrgr�
_greetingtest�sz LoopbackAsyncTests._greetingtestcCs|�dd�S)z�
        Test that on a connection where the client speaks first, the server
        receives the bytes sent by the client.
        reF�rjrrrr�test_clientGreeting�sz&LoopbackAsyncTests.test_clientGreetingcCs|�dd�S)zz
        Like C{test_clientGreeting}, but use C{writeSequence} instead of
        C{write} to issue the greeting.
        rfFrkrrrr�test_clientGreetingSequence�sz.LoopbackAsyncTests.test_clientGreetingSequencerecCs|�dd�S)z�
        Test that on a connection where the server speaks first, the client
        receives the bytes sent by the server.
        reTrk)rrerrr�test_serverGreeting�sz&LoopbackAsyncTests.test_serverGreetingcCs|�dd�S)zz
        Like C{test_serverGreeting}, but use C{writeSequence} instead of
        C{write} to issue the greeting.
        rfTrkrrrr�test_serverGreetingSequence�sz.LoopbackAsyncTests.test_serverGreetingSequencecshttttdd����G��fdd�dt�}G���fdd�dt�}|��|��t��_t�����jS)Nr�
cseZdZ��fdd�ZdS)z;LoopbackAsyncTests._producertest.<locals>.ProducingProtocolcs �t���|_|j�|j�dSr)�list�producer�startr-r��
producerClass�	toProducerrr�szJLoopbackAsyncTests._producertest.<locals>.ProducingProtocol.connectionMadeNrhrrtrr�ProducingProtocol�srwcs eZdZdZ���fdd�ZdS)z;LoopbackAsyncTests._producertest.<locals>.ReceivingProtocolr\cs2|j|7_|jd���kr.|j���f�dS)Nr\)r_�joinr`r�r�data�rKrJrvrrrb�szHLoopbackAsyncTests._producertest.<locals>.ReceivingProtocol.dataReceivedNrcrr{rr�ReceivingProtocol�sr|)	rq�mapr�ranger
rr`rrI)rrurwr|r)rKrurJrvr�
_producertest�sz LoopbackAsyncTests._producertestcs<tt�Gdd�dt��}��|�}�fdd�}|�|�|S)zO
        Test a push producer registered against a loopback transport.
        c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)z:LoopbackAsyncTests.test_pushProducer.<locals>.PushProducerFcSs
||_dSr�rv�rrvrrrrszCLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.__init__cSs
d|_dS�NT)�resumedrrrr�resumeProducingszJLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.resumeProducingcSs||_|�|d�|��dSr�)�consumer�registerProducer�_produceAndSchedule�rr�rrrrssz@LoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.startcSs8|jr*|j�|j�d��t�d|j�n
|j��dS�Nr)rvr�re�popr�	callLaterr��unregisterProducerrrrrr�szNLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer._produceAndScheduleN)r#r$r%r�rr�rsr�rrrr�PushProducer
s
r�cs|\}}��|jjd�dS)Nz0Streaming producer should not have been resumed.)ZassertFalserrr�)ZresultsrKrJrrr�finished!s
�z6LoopbackAsyncTests.test_pushProducer.<locals>.finished)rr
�objectrr=)rr�rAr�rrr�test_pushProducers

z$LoopbackAsyncTests.test_pushProducercCs"tt�Gdd�dt��}|�|�S)zO
        Test a pull producer registered against a loopback transport.
        c@s$eZdZdd�Zdd�Zdd�ZdS)z:LoopbackAsyncTests.test_pullProducer.<locals>.PullProducercSs
||_dSrr�r�rrrr0szCLoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.__init__cSs||_|j�|d�dS)NF)r�r�r�rrrrs3sz@LoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.startcSs(|j�|j�d��|js$|j��dSr�)r�rervr�r�rrrrr�7szJLoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.resumeProducingN)r#r$r%rrsr�rrrr�PullProducer.sr�)rrr�r)rr�rrr�test_pullProducer*sz$LoopbackAsyncTests.test_pullProducercsTGdd�dt�}Gdd�dt�}|�}|��t��|�}��fdd�}|�|�|S)z�
        L{loopback.loopbackAsync} does not call a protocol's C{dataReceived}
        method while that protocol's transport's C{write} method is higher up
        on the stack.
        c@seZdZdd�ZdS)z9LoopbackAsyncTests.test_writeNotReentrant.<locals>.ServercSs|j�d�dSr])r-rerarrrrbEszFLoopbackAsyncTests.test_writeNotReentrant.<locals>.Server.dataReceivedN)r#r$r%rbrrrr�ServerDsr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	z9LoopbackAsyncTests.test_writeNotReentrant.<locals>.ClientFcSst�d|j�dSr�)rr��gorrrrrKszHLoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.connectionMadecSs|j�d�d|_dS)N�fooT)r-re�readyrrrrr�Nsz<LoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.gocSs|j|_|j��dSr)r��wasReadyr-r.rarrrrbRszFLoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.dataReceivedN)r#r$r%r�rr�rbrrrr�ClientHsr�cs���j�dSr)rOr�r9�rKrrr�
cbFinishedYsz=LoopbackAsyncTests.test_writeNotReentrant.<locals>.cbFinished)r
rrIr=)rr�r�rJrAr�rr�r�test_writeNotReentrant>s
z)LoopbackAsyncTests.test_writeNotReentrantcs�g��fdd�}t��t��t���|�}���g��j�d��j�d��j�d��j�d��j������fdd�}|�|�|S)	z�
        The callable passed as the value for the C{pumpPolicy} parameter to
        L{loopbackAsync} is called with a L{_LoopbackQueue} of pending bytes
        and a protocol to which they should be delivered.
        cs*g}|r|�|���q��||f�dSr)rrQ)�queue�targetr_)�	pumpCallsrr�dummyPolicyfsz7LoopbackAsyncTests.test_pumpPolicy.<locals>.dummyPolicyr��bar�baz�quuxcs&����dddgf�ddgfg�dS)Nr�r�r�r�)r7r9�rKr�rrJrr�
cbCompletexs
��z6LoopbackAsyncTests.test_pumpPolicy.<locals>.cbComplete)r
rrIr7r-rer.r=)rr�r�r�rr�r�test_pumpPolicy_s

z"LoopbackAsyncTests.test_pumpPolicycCsXg}t�}|j|_t��}|�d�|�d�|�d�t�||�|�|ddg�dS)z�
        L{identityPumpPolicy} is a pump policy which calls the target's
        C{dataReceived} method one for each string in the queue passed to it.
        r�r�N)r
rrbr�_LoopbackQueue�putZidentityPumpPolicyr7�rr_rKr�rrr�test_identityPumpPolicy�s


z*LoopbackAsyncTests.test_identityPumpPolicycCsVg}t�}|j|_t��}|�d�|�d�|�d�t�||�|�|dg�dS)z�
        L{collapsingPumpPolicy} is a pump policy which calls the target's
        C{dataReceived} only once with all of the strings in the queue passed
        to it joined together.
        r�r�Nsfoobar)r
rrbrr�r�ZcollapsingPumpPolicyr7r�rrr�test_collapsingPumpPolicy�s


z,LoopbackAsyncTests.test_collapsingPumpPolicyN)rU)re)r#r$r%�staticmethodrrIr?rLrTrWrYrZr[rjrlrmrnrorr�r�r�r�r�r�rrrrrE_s&

"
$!$rEc@seZdZeej�ZdS)�LoopbackTCPTestsN)r#r$r%r�rZloopbackTCPr?rrrrr��sr�c@s*eZdZeej�Ze�e	d�dkr&dZ
dS)�LoopbackUNIXTestsNz-Current reactor does not support UNIX sockets)r#r$r%r�rZloopbackUNIXr?rZIReactorUNIXr�skiprrrrr��s
r�c@s0eZdZdZGdd�de�Zdd�Zdd�ZdS)	�LoopbackRelayTestz>
    Test for L{twisted.protocols.loopback.LoopbackRelay}
    c@seZdZdZdZdd�ZdS)zLoopbackRelayTest.ReceiverzF
        Simple Receiver class used for testing LoopbackRelay
        r\cCs|j|7_dS)z)Accumulate received data for verificationN)rzryrrrrb�sz'LoopbackRelayTest.Receiver.dataReceivedN)r#r$r%�__doc__rzrbrrrr�Receiver�sr�cCsN|��}t�|�}|�d�|�d�|�|jd�|��|�|jd�dS)z8Test to verify that the write function works as expectedsabcsdefr\sabcdefN)r�r�
LoopbackRelayrer7rz�clearBuffer�rZreceiverZrelayrrr�
test_write�s


zLoopbackRelayTest.test_writecCs\|��}t�|�}|�ddddg�|�dddg�|�|jd�|��|�|jd	�d
S)z@Test to verify that the writeSequence function works as expectedsThe squick sbrown sfox sjumps sover sthe lazy dogr\s+The quick brown fox jumps over the lazy dogN)r�rr�rfr7rzr�r�rrr�test_writeSequence�s

���z$LoopbackRelayTest.test_writeSequenceN)r#r$r%r�r
r�r�r�rrrrr��s
r�N)"r�Z
__future__rrZzope.interfacerZtwisted.python.compatrZ
twisted.trialrZtwisted.protocolsrrZtwisted.internetr	Ztwisted.internet.protocolr
Ztwisted.internet.deferrZtwisted.internet.interfacesrr
rrrZLineReceiverrr&r/ZTestCaserEr�r�r�rrrr�<module>s&'L