%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_protocols.cpython-312.pyc

�

Ϫ�f���&�dZddlmZmZmZmZddlmZmZddl	m
Z
ddlmZddl
mZGd�dej�ZGd	�d
ej"�ZGd�dej&�ZGd
�dej�ZGd�dej�Zy)z+
Test cases for twisted.protocols package.
�)�address�defer�protocol�reactor)�portforward�wire)�	iterbytes)�
proto_helpers)�unittestc�(�eZdZdZd�Zd�Zd�Zd�Zy)�	WireTestsz
    Test wire protocols.
    c�`�tj�}tj�}|j	|�|jd�|jd�|jd�|jd�|jd�|j
|j�d�y)zT
        Test wire.Echo protocol: send some data and check it send it back.
        �hello�world�how�are�youshelloworldhowareyouN)r
�StringTransportr�Echo�makeConnection�dataReceived�assertEqual�value��self�t�as   �=/usr/lib/python3/dist-packages/twisted/test/test_protocols.py�	test_echozWireTests.test_echos~��
�)�)�+���I�I�K��	�����	���x� �	���x� �	���v��	���v��	���v���������$:�;�c��tj�}tj�}|j	|�|j|j
�d�y)z)
        Test wire.Who protocol.
        sroot
N)r
rr�Whorrrrs   r�test_whozWireTests.test_who"sA��
�)�)�+���H�H�J��	������������K�0r c��tj�}tj�}|j	|�|j|j
�d�y)z*
        Test wire.QOTD protocol.
        s'An apple a day keeps the doctor away.
N)r
rr�QOTDrrrrs   r�	test_QOTDzWireTests.test_QOTD+sB��
�)�)�+���I�I�K��	������������$P�Qr c�`�tj�}tj�}|j	|�|jd�|jd�|jd�|jd�|jd�|j
|j�d�y)z-
        Test wire.Discard protocol.
        rrrrrr N)r
rr�Discardrrrrrs   r�test_discardzWireTests.test_discard4s}��
�)�)�+���L�L�N��	�����	���x� �	���x� �	���v��	���v��	���v���������C�(r N)�__name__�
__module__�__qualname__�__doc__rr#r&r)�r rr
r
s���<�1�R�)r r
c��eZdZdZd�Zy)�TestableProxyClientFactoryz�
    Test proxy client factory that keeps the last created protocol instance.

    @ivar protoInstance: the last instance of the protocol.
    @type protoInstance: L{portforward.ProxyClient}
    c�T�tjj||�}||_|S)zE
        Create the protocol instance and keeps track of it.
        )r�ProxyClientFactory�
buildProtocol�
protoInstance�r�addr�protos   rr3z(TestableProxyClientFactory.buildProtocolKs)���.�.�<�<�T�4�H��"����r N�r*r+r,r-r3r.r rr0r0Cs���r r0c��eZdZdZd�Zy)�TestableProxyFactoryal
    Test proxy factory that keeps the last created protocol instance.

    @ivar protoInstance: the last instance of the protocol.
    @type protoInstance: L{portforward.ProxyServer}

    @ivar clientFactoryInstance: client factory used by C{protoInstance} to
        create forward connections.
    @type clientFactoryInstance: L{TestableProxyClientFactory}
    c���tjj�|�}t��_�fd�|_|�_|S)z�
        Create the protocol instance, keeps track of it, and makes it use
        C{clientFactoryInstance} as client factory.
        c����jS�N)�clientFactoryInstance�rs�r�<lambda>z4TestableProxyFactory.buildProtocol.<locals>.<lambda>hs
���d�.H�.H�r )r�ProxyFactoryr3r0r>�clientProtocolFactoryr4r5s`  rr3z"TestableProxyFactory.buildProtocol`s=���
�(�(�6�6�t�T�B��%?�%A��"�&H��#�"����r Nr8r.r rr:r:Ts��	�
r r:c�(�eZdZdZd�Zd�Zd�Zd�Zy)�PortforwardingTestsz
    Test port forwarding.
    c�v�tj�|_tj�|_g|_yr=)rr�serverProtocolr�Protocol�clientProtocol�	openPortsr?s r�setUpzPortforwardingTests.setUprs(��"�i�i�k���&�/�/�1�����r c��	|jjjj�	|jj
j}|jj�	|jjj�	|jjj�tj|jD�cgc]!}tj|j���#c}�S#t$rY��wxYw#t$rY��wxYw#t$rY��wxYw#t$rY��wxYwcc}wr=)
�proxyServerFactoryr4�	transport�loseConnection�AttributeErrorr>rHrFr�
gatherResultsrI�
maybeDeferred�
stopListening)r�pi�ps   r�tearDownzPortforwardingTests.tearDownws��	��#�#�1�1�;�;�J�J�L�	��(�(�>�>�L�L�B��L�L�'�'�)�	����)�)�8�8�:�	����)�)�8�8�:��"�"�;?�>�>�J�a�U�
 �
 ����
1�J�
�	
���	��	��
�	��	���	��	���	��	��
KsL�.C?�:D�,$D�$D,�&D;�?	D�
D�	D�D�	D)�(D)�,	D8�7D8c�����	�tj�}�fd�|_tjd|d��}�jj|�t
d|j�j��_	tjd�jd��}�jj|�d�g�	tj�����	�fd�}|�j_
��fd�}|�j_tj�}�fd�|_tj d|j�j|��S)	z=
        Test port forwarding through Echo protocol.
        c����jSr=)rFr?s�rr@z6PortforwardingTests.test_portforward.<locals>.<lambda>�s
���T�-@�-@�r r�	127.0.0.1)�	interfacei�c�����jt|��t���k\r6�jdj	��d�z��jd�yy)Nr �x)�extendr	�lenr�join�callback)�data�d�nBytes�receivedrs ����r�testDataReceivedz>PortforwardingTests.test_portforward.<locals>.testDataReceived�sM����O�O�I�d�O�,��8�}��&�� � ����(�!3�T�F�]�C��
�
�4� �'r c�V���jjjd�z�y)Nr[)rHrM�write)rbrs��r�testConnectionMadez@PortforwardingTests.test_portforward.<locals>.testConnectionMade�s!������)�)�/�/��v�
�>r c����jSr=)rHr?s�rr@z6PortforwardingTests.test_portforward.<locals>.<lambda>�s
����)<�)<�r )r�
ServerFactoryr�	listenTCPrI�appendr:�getHost�portrLr�DeferredrHr�connectionMade�
ClientFactory�
connectTCP)
r�realServerFactory�realServerPort�proxyServerPortrdrg�
clientFactoryrarbrcs
`      @@@r�test_portforwardz$PortforwardingTests.test_portforward�s���%�2�2�4��%@��"� �*�*�1�.?�;�W�������n�-�"6���/�/�1�6�6�#
���"�+�+�
�t�&�&�+�
��	
�����o�.������N�N���	!�,<����(�	?�.@����*� �.�.�0�
�!<�
�����;��(?�(?�(A�(F�(F�
�V��r c��tjddd�}tjdd�j	|�}tj�}||_tj�}|j|�|jt|j�d�|jd\}}}}}	|j|tj�|j	|�}
tj�}|
j|�|j|j |�|j|j |�|j#|j$�|j#|j$�y)zm
        The proxy client registers itself as a producer of the proxy server and
        vice versa.
        �TCPrXr�N)r�IPv4AddressrrAr3r
�
MemoryReactorrrrrr]�
tcpClients�assertIsInstancer2�assertIs�producer�
assertTrue�	streaming)rr6�serverr�serverTransport�hostrmru�timeout�_�client�clientTransports            r�test_registerProducersz*PortforwardingTests.test_registerProducers�s4���"�"�5�+�q�9���)�)�+�q�9�G�G��M�� �-�-�/�� ���(�7�7�9�����o�.�	
����W�/�/�0�!�4�07�0B�0B�1�0E�-��d�M�7�A����m�[�-K�-K�L��,�,�T�2��'�7�7�9�����o�.�	
�
�
�o�.�.��@��
�
�o�.�.��@�����1�1�2�����1�1�2r N)r*r+r,r-rJrUrvr�r.r rrDrDms����

�,&�P!3r rDc��eZdZdZd�Zy)�StringTransportTestszA
    Test L{proto_helpers.StringTransport} helper behaviour.
    c�n�tj�}|jt|jd�y)zY
        Test that L{proto_helpers.StringTransport} doesn't accept unicode data.
        �fooN)r
r�assertRaises�	TypeErrorrf)r�ss  r�test_noUnicodez#StringTransportTests.test_noUnicode�s(��
�)�)�+�����)�Q�W�W�e�4r N)r*r+r,r-r�r.r rr�r��s���5r r�N)r-�twisted.internetrrrr�twisted.protocolsrr�twisted.python.compatr	�twisted.testr
�
twisted.trialr�TestCaser
r2r0rAr:rDr�r.r r�<module>r�s|���?�>�/�+�&�"�1)��!�!�1)�h��!?�!?��"�;�3�3��2i3�(�+�+�i3�X
5�8�,�,�
5r 

Zerion Mini Shell 1.0