%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�7��r�dZddlmZddlmZmZmZddlmZddl	m
Z
mZmZddl
mZddlmZmZddlmZGd	�d
ej(�ZGd�de�ZGd
�d�ZGd�deej0�ZGd�deej0�ZGd�deej0�ZGd�dej0�Zy)z.
Test case for L{twisted.protocols.loopback}.
�)�implementer)�defer�
interfaces�reactor)�Deferred)�IAddress�
IPullProducer�
IPushProducer)�Protocol)�basic�loopback)�unittestc�$�eZdZd�Zd�Zd�Zd�Zy)�SimpleProtocolc�R�tj�|_g|_g|_y�N)rr�conn�lines�connLost��selfs �</usr/lib/python3/dist-packages/twisted/test/test_loopback.py�__init__zSimpleProtocol.__init__s���N�N�$��	���
���
�c�:�|jjd�yr)r�callbackrs r�connectionMadezSimpleProtocol.connectionMades���	�	���4� rc�:�|jj|�yr)r�append�r�lines  r�lineReceivedzSimpleProtocol.lineReceiveds���
�
���$�rc�:�|jj|�yr)rr)r�reasons  r�connectionLostzSimpleProtocol.connectionLosts���
�
���V�$rN)�__name__�
__module__�__qualname__rrr"r%�rrrrs���
!� �%rrc��eZdZdZd�Zy)�DoomProtocolrc��|xjdz
c_|jdkr|jd|jfz�tj||�|jddk(r|j
j
�yy)N��sHello %d����Hello 3)�i�sendLinerr"r�	transport�loseConnectionr s  rr"zDoomProtocol.lineReceived&sh�����!����6�6�A�:�
�M�M�+����	�1�2��#�#�D�$�/��:�:�b�>�Z�'��N�N�)�)�+�(rN)r&r'r(r1r"r)rrr+r+#s��	�A�,rr+c��eZdZd�Zd�Zy)�LoopbackTestCaseMixinc������t��t���fd�}�jj|����fd�}tj�j
���}|j|�|S)Nc�\���jd��jj�y)N�THIS IS LINE ONE!)r2r3r4��result�ss �r�	sendALinez<LoopbackTestCaseMixin.testRegularFunction.<locals>.sendALine6s ���
�J�J�+�,�
�K�K�&�&�(rc�����j�jdg��jt�j�d��jt�j�d�y)Nr9r-��assertEqualr�lenr��ignored�cr<rs ���r�checkz8LoopbackTestCaseMixin.testRegularFunction.<locals>.check<sK������Q�W�W�';�&<�=����S����_�a�0����S����_�a�0r)rr�addCallbackr�
maybeDeferred�loopbackFunc�rr=rE�drDr<s`   @@r�testRegularFunctionz)LoopbackTestCaseMixin.testRegularFunction2s^���������	)�	
�����9�%�	1�

���� 1� 1�1�a�8��	�
�
�e���rc������t��t���fd�}�jj|����fd�}tj�j
���}|j|�|S)Nc�(���jd�y)N�	DOOM LINE)r2r:s �rr=z=LoopbackTestCaseMixin.testSneakyHiddenDoom.<locals>.sendALineIs���
�J�J�|�$rc����j�jgd���j�jgd���jt�j�d��jt�j�d�y)N)�Hello 1�Hello 2r0)rNrPrQr0r-r?rBs ���rrEz9LoopbackTestCaseMixin.testSneakyHiddenDoom.<locals>.checkNsb������Q�W�W�&J�K�������K�
�
���S����_�a�0����S����_�a�0r)r+rrFrrGrHrIs`   @@r�testSneakyHiddenDoomz*LoopbackTestCaseMixin.testSneakyHiddenDoomEs\����N���N��	%�	
�����9�%�	1�
���� 1� 1�1�a�8��	�
�
�e���rN)r&r'r(rKrRr)rrr6r61s���&rr6c��eZdZeej
�Zd�Zd�Zd�Z	d�Z
dd�Zd�Zd�Z
d�Zd	�Zdd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zy)�LoopbackAsyncTestsc���Gd�dt�}|�}|�}tj||�|j|j�|j|j�y)z}
        Test that the client and server protocol both have makeConnection
        invoked on them by loopbackAsync.
        c��eZdZdZd�Zy)�<LoopbackAsyncTests.test_makeConnection.<locals>.TestProtocolNc��||_yr)r3�rr3s  r�makeConnectionzKLoopbackAsyncTests.test_makeConnection.<locals>.TestProtocol.makeConnectiong�	��!*��r)r&r'r(r3rZr)rr�TestProtocolrWds���I�
+rr\N)rr
�
loopbackAsync�assertIsNotNoner3)rr\�server�clients    r�test_makeConnectionz&LoopbackAsyncTests.test_makeConnection^sV��	+�8�	+����������v�v�.����V�-�-�.����V�-�-�.rc����Gd�dt�}|r#|�}t�x}|_t�}n"t�}|�}t�x}|_tj||���fd�}|j|�S)zJ
        Test one of the permutations of client/server host/peer.
        c��eZdZd�Zy)�6LoopbackAsyncTests._hostpeertest.<locals>.TestProtocolc�f�tj||�|jj|�yr)rrZ�onConnectionrrYs  rrZzELoopbackAsyncTests._hostpeertest.<locals>.TestProtocol.makeConnectionvs&���'�'��i�8��!�!�*�*�9�5rN)r&r'r(rZr)rrr\rdus��
6rr\c�p��t|���}�jtj|��yr)�getattr�
assertTruer�
providedBy)r3�host�getrs  ��r�	connectedz3LoopbackAsyncTests._hostpeertest.<locals>.connected�s+���*�7�9�c�*�,�D��O�O�H�/�/��5�6r)rrrfr
r]rF)rrl�
testServerr\r_rJr`rms``      r�
_hostpeertestz LoopbackAsyncTests._hostpeertestpst���
	6�8�	6�
�!�^�F�&.�j�0�A��#��Z�F��Z�F�!�^�F�&.�j�0�A��#����v�v�.�	7��}�}�Y�'�'rc�&�|jdd�S)z�
        Test that the server gets a transport with a properly functioning
        implementation of L{ITransport.getHost}.
        �getHostT�rors r�test_serverHostz"LoopbackAsyncTests.test_serverHost�s��
�!�!�)�T�2�2rc�&�|jdd�S)zG
        Like C{test_serverHost} but for L{ITransport.getPeer}
        �getPeerTrrrs r�test_serverPeerz"LoopbackAsyncTests.test_serverPeer�s���!�!�)�T�2�2rc�&�|jdd�S)z�
        Test that the client gets a transport with a properly functioning
        implementation of L{ITransport.getHost}.
        rqFrr)rrls  r�test_clientHostz"LoopbackAsyncTests.test_clientHost�s��
�!�!�)�U�3�3rc�&�|jdd�S)zH
        Like C{test_clientHost} but for L{ITransport.getPeer}.
        ruFrrrs r�test_clientPeerz"LoopbackAsyncTests.test_clientPeer�s���!�!�)�U�3�3rc���Gd�dt�}G�fd�dt�}|r |�}|�}t�x}|_n|�}t�x}|_|�}tj||�|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��eZdZdZd�Zy)�9LoopbackAsyncTests._greetingtest.<locals>.GreeteeProtocolrc��|xj|z
c_|jdk(r|jjd�yy�N�bytes)�bytes�receivedr�rr�s  r�dataReceivedzFLoopbackAsyncTests._greetingtest.<locals>.GreeteeProtocol.dataReceived�s3���
�
�e�#�
��:�:��)��M�M�*�*�4�0�*rN�r&r'r(r�r�r)rr�GreeteeProtocolr}�s���E�
1rr�c���eZdZ�fd�Zy)�9LoopbackAsyncTests._greetingtest.<locals>.GreeterProtocolc����dk(r|jjd�y|jjddg�y)N�writer�sbytses)r3r��
writeSequence�rr�s �rrzHLoopbackAsyncTests._greetingtest.<locals>.GreeterProtocol.connectionMade�s3����G�#��N�N�(�(��2��N�N�0�0�&�%��ArN�r&r'r(r�r�s�r�GreeterProtocolr��s	���
Brr�)rrr�r
r])rr�rnr�r�r_r`rJs `      r�
_greetingtestz LoopbackAsyncTests._greetingtest�ss���	1�h�	1�	B�h�	B��$�&�F�$�&�F�"*�*�,�A���$�&�F�"*�*�,�A���$�&�F����v�v�.��rc�&�|jdd�S)z�
        Test that on a connection where the client speaks first, the server
        receives the bytes sent by the client.
        r�F�r�rs r�test_clientGreetingz&LoopbackAsyncTests.test_clientGreeting�s��
�!�!�'�5�1�1rc�&�|jdd�S)zz
        Like C{test_clientGreeting}, but use C{writeSequence} instead of
        C{write} to issue the greeting.
        r�Fr�rs r�test_clientGreetingSequencez.LoopbackAsyncTests.test_clientGreetingSequence�s��
�!�!�/�5�9�9rc�&�|jdd�S)z�
        Test that on a connection where the server speaks first, the client
        receives the bytes sent by the server.
        r�Tr�r�s  r�test_serverGreetingz&LoopbackAsyncTests.test_serverGreeting�s��
�!�!�'�4�0�0rc�&�|jdd�S)zz
        Like C{test_serverGreeting}, but use C{writeSequence} instead of
        C{write} to issue the greeting.
        r�Tr�rs r�test_serverGreetingSequencez.LoopbackAsyncTests.test_serverGreetingSequence�s��
�!�!�/�4�8�8rc������tdd�D�cgc]}d|fz��
c}�G��fd�dt�}G���fd�dt�}|��|��t��_t	j
����jScc}w)Nr�
s%dc���eZdZ��fd�Zy)�;LoopbackAsyncTests._producertest.<locals>.ProducingProtocolc�|���t���|_|jj|j�yr)�list�producer�startr3)r�
producerClass�	toProduces ��rrzJLoopbackAsyncTests._producertest.<locals>.ProducingProtocol.connectionMade�s)��� -�d�9�o� >��
��
�
�#�#�D�N�N�3rNr�)r�r�s��r�ProducingProtocolr��s���
4rr�c� ��eZdZdZ���fd�Zy)�;LoopbackAsyncTests._producertest.<locals>.ReceivingProtocolrc���|xj|z
c_|jdj��k(r|jj��f�yy)Nr)r��joinr�r)r�datar`r_r�s  ���rr�zHLoopbackAsyncTests._producertest.<locals>.ReceivingProtocol.dataReceived�sB����
�
�d�"�
��:�:����)�!4�4��M�M�*�*�F�F�+;�<�5rNr�)r`r_r�s���r�ReceivingProtocolr��s
����E�
=rr�)�rangerrr�r
r])rr�r1r�r�r`r_r�s `   @@@r�
_producertestz LoopbackAsyncTests._producertest�sv���+0��B�<�8�a�U�a�T�\�8�	�	4��	4�
	=�	=��	=�#�$��"�$��"�*������v�v�.������)9s�
Bc���tt�Gd�d��}�j|�}�fd�}|j|�|S)zO
        Test a push producer registered against a loopback transport.
        c�(�eZdZdZd�Zd�Zd�Zd�Zy)�:LoopbackAsyncTests.test_pushProducer.<locals>.PushProducerFc��||_yr�r��rr�s  rrzCLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.__init__r[rc��d|_y�NT)�resumedrs r�resumeProducingzJLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.resumeProducings	��#��rc�V�||_|j|d�|j�yr�)�consumer�registerProducer�_produceAndSchedule�rr�s  rr�z@LoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.start
s%�� (��
��)�)�$��5��(�(�*rc��|jrU|jj|jjd��t	j
d|j�y|jj�y�Nr)r�r�r��popr�	callLaterr��unregisterProducerrs rr�zNLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer._produceAndSchedulesP���>�>��M�M�'�'����(:�(:�1�(=�>��%�%�a��)A�)A�B��M�M�4�4�6rN)r&r'r(r�rr�r�r�r)rr�PushProducerr�s���G�
+�
$�
+�

7rr�c�\��|\}}�j|jjd�y)Nz0Streaming producer should not have been resumed.)�assertFalser�r�)�resultsr`r_rs   �r�finishedz6LoopbackAsyncTests.test_pushProducer.<locals>.finisheds+���&��V�V�������'�'�B�
r)rr
r�rF)rr�rJr�s`   r�test_pushProducerz$LoopbackAsyncTests.test_pushProducer�sK���

�]�	#�	7�	7�
$�	7�*
���|�,��	�	
�
�
�h���rc�\�tt�Gd�d��}|j|�S)zO
        Test a pull producer registered against a loopback transport.
        c��eZdZd�Zd�Zd�Zy)�:LoopbackAsyncTests.test_pullProducer.<locals>.PullProducerc��||_yrr�r�s  rrzCLoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.__init__)r[rc�J�||_|jj|d�y)NF)r�r�r�s  rr�z@LoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.start,s�� (��
��
�
�.�.�t�U�;rc��|jj|jjd��|js|jj	�yyr�)r�r�r�r�r�rs rr�zJLoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.resumeProducing0s?���
�
�#�#�D�N�N�$6�$6�q�$9�:��~�~��M�M�4�4�6�&rN)r&r'r(rr�r�r)rr�PullProducerr�'s��
+�
<�
7rr�)rr	r�)rr�s  r�test_pullProducerz$LoopbackAsyncTests.test_pullProducer"s3��

�]�	#�	7�	7�
$�	7��!�!�,�/�/rc����Gd�dt�}Gd�dt�}|�}|��tj�|�}��fd�}|j|�|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��eZdZd�Zy)�9LoopbackAsyncTests.test_writeNotReentrant.<locals>.Serverc�:�|jjd�yr)r3r�r�s  rr�zFLoopbackAsyncTests.test_writeNotReentrant.<locals>.Server.dataReceived?s�����$�$�X�.rN)r&r'r(r�r)rr�Serverr�>s��
/rr�c�"�eZdZdZd�Zd�Zd�Zy)�9LoopbackAsyncTests.test_writeNotReentrant.<locals>.ClientFc�D�tjd|j�yr�)rr��gors rrzHLoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.connectionMadeEs���!�!�!�T�W�W�-rc�H�|jjd�d|_y)N�fooT)r3r��readyrs rr�z<LoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.goHs�����$�$�V�,�!��
rc�Z�|j|_|jj�yr)r��wasReadyr3r4r�s  rr�zFLoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.dataReceivedLs�� $�
�
��
����-�-�/rN)r&r'r(r�rr�r�r)rr�Clientr�Bs���E�
.�
"�
0rr�c�<���j�j�yr)rir�)rCr`rs ��r�
cbFinishedz=LoopbackAsyncTests.test_writeNotReentrant.<locals>.cbFinishedTs����O�O�F�O�O�,r)rr
r]rF)rr�r�r_rJr�r`s`     @r�test_writeNotReentrantz)LoopbackAsyncTests.test_writeNotReentrant7sU���	/�X�	/�	0�X�	0��������"�"�6�6�2��	-�	
�
�
�j�!��rc�������g��fd�}t��t��tj��|�}�j�g��jjd��jjd��jjd��jjd��jj
�����fd�}|j|�|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.
        c�x��g}|r"|j|j��|r�"�j||f�yr)rrl)�queue�targetr��	pumpCallss   �r�dummyPolicyz7LoopbackAsyncTests.test_pumpPolicy.<locals>.dummyPolicybs4����E�����U�Y�Y�[�)�����f�e�_�-rr��bar�baz�quuxc�>���j��gd�f�ddgfg�y)N)r�r�Nr�r�)r@)rCr`r�rr_s ����r�
cbCompletez6LoopbackAsyncTests.test_pumpPolicy.<locals>.cbCompletets.��������1�2�V�f�f�=M�4N�O�	
r)rr
r]r@r3r�r4rF)rr�r�r�r`r�r_s`   @@@r�test_pumpPolicyz"LoopbackAsyncTests.test_pumpPolicyZs�����	�	.��������)�)�&�&�+�F������B�'������v�&������v�&������v�&������w�'����'�'�)�	�	���Z�(��rc� �g}t�}|j|_tj�}|jd�|jd�|jd�tj||�|j|ddg�y)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)rrr�r
�_LoopbackQueue�put�identityPumpPolicyr@�rr�r`r�s    r�test_identityPumpPolicyz*LoopbackAsyncTests.test_identityPumpPolicysr��
�����#�l�l����'�'�)��
�	�	�&��
�	�	�&��
�	�	�$���#�#�E�6�2������� 0�1rc��g}t�}|j|_tj�}|jd�|jd�|jd�tj||�|j|dg�y)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)rrr�r
r�r��collapsingPumpPolicyr@r�s    r�test_collapsingPumpPolicyz,LoopbackAsyncTests.test_collapsingPumpPolicy�so�������#�l�l����'�'�)��
�	�	�&��
�	�	�&��
�	�	�$���%�%�e�V�4�������,rN)rqr�)r&r'r(�staticmethodr
r]rHrarorsrvrxrzr�r�r�r�r�r�r�r�r�r�r�r�r)rrrTrT[sp���� 6� 6�7�L�/�$(�63�3�4�4�!�F2�:�1�9��.%�N0�*!�F#�J2�"-rrTc�0�eZdZeej
�Zy)�LoopbackTCPTestsN)r&r'r(r�r
�loopbackTCPrHr)rrr�r��s���� 4� 4�5�Lrr�c�\�eZdZeej
�Zeje	d��dZ
yy)�LoopbackUNIXTestsNz-Current reactor does not support UNIX sockets)r&r'r(r�r
�loopbackUNIXrHr�IReactorUNIXr�skipr)rrr�r��s1���� 5� 5�6�L��z���w��-�5�>��6rr�c�2�eZdZdZGd�de�Zd�Zd�Zy)�LoopbackRelayTestz>
    Test for L{twisted.protocols.loopback.LoopbackRelay}
    c��eZdZdZdZd�Zy)�LoopbackRelayTest.ReceiverzF
        Simple Receiver class used for testing LoopbackRelay
        rc�.�|xj|z
c_y)z)Accumulate received data for verificationN)r�)rr�s  rr�z'LoopbackRelayTest.Receiver.dataReceived�s���I�I���IrN)r&r'r(�__doc__r�r�r)rr�Receiverr�s��	���	rrc�"�|j�}tj|�}|jd�|jd�|j	|j
d�|j
�|j	|j
d�y)z8Test to verify that the write function works as expectedsabcsdefrsabcdefN)rr
�
LoopbackRelayr�r@r��clearBuffer�r�receiver�relays   r�
test_writezLoopbackRelayTest.test_write�si���=�=�?���&�&�x�0��
���F��
���F���������,�
����������	�2rc�*�|j�}tj|�}|jgd��|jgd��|j	|j
d�|j
�|j	|j
d�y)z@Test to verify that the writeSequence function works as expected)sThe squick sbrown sfox )sjumps sover sthe lazy dogrs+The quick brown fox jumps over the lazy dogN)rr
rr�r@r�rr	s   r�test_writeSequencez$LoopbackRelayTest.test_writeSequence�sp���=�=�?���&�&�x�0��
���D�E�
���B�C��������,�
����������(V�WrN)r&r'r(rrrrrr)rrrr�s���	�8�	�3�XrrN)r�zope.interfacer�twisted.internetrrr�twisted.internet.deferr�twisted.internet.interfacesrr	r
�twisted.internet.protocolr�twisted.protocolsrr
�
twisted.trialr�LineReceiverrr+r6�TestCaserTr�r�rr)rr�<module>rs����
'�7�7�+�N�N�.�-�"�
%�U�'�'�
%� ,�>�,�'�'�TE-�.��0A�0A�E-�P
6�,�h�.?�.?�6�?�-�x�/@�/@�?�"X��)�)�"Xr

Zerion Mini Shell 1.0