Ë
    oj¦  ã                   ó&  — d Z ddlmZmZmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ  G d„ dej                  «      Z G d	„ d
ej"                  «      Z G d„ dej&                  «      Z G d„ dej                  «      Z G d„ dej                  «      Zy)z+
Test cases for twisted.protocols package.
é    )ÚaddressÚdeferÚprotocolÚreactor)ÚportforwardÚwire)Ú	iterbytes)Úproto_helpers)Úunittestc                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)Ú	WireTestsz
    Test wire protocols.
    c                 ó`  — t        j                  «       }t        j                  «       }|j	                  |«       |j                  d«       |j                  d«       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  «       d«       y)zT
        Test wire.Echo protocol: send some data and check it send it back.
        ó   helloó   worldó   howó   areó   yous   helloworldhowareyouN)r
   ÚStringTransportr   ÚEchoÚmakeConnectionÚdataReceivedÚassertEqualÚvalue©ÚselfÚtÚas      ú=/usr/lib/python3/dist-packages/twisted/test/test_protocols.pyÚ	test_echozWireTests.test_echo   s~   € ô ×)Ñ)Ó+ˆÜ�I‰I‹KˆØ	×Ñ˜ÔØ	�‰�xÔ Ø	�‰�xÔ Ø	�‰�vÔØ	�‰�vÔØ	�‰�vÔØ×Ñ˜Ÿ™›Ð$:Õ;ó    c                 ó¶   — t        j                  «       }t        j                  «       }|j	                  |«       | j                  |j                  «       d«       y)z)
        Test wire.Who protocol.
        s   root
N)r
   r   r   ÚWhor   r   r   r   s      r   Útest_whozWireTests.test_who"   sA   € ô ×)Ñ)Ó+ˆÜ�H‰H‹JˆØ	×Ñ˜ÔØ×Ñ˜Ÿ™› KÕ0r    c                 ó¶   — t        j                  «       }t        j                  «       }|j	                  |«       | j                  |j                  «       d«       y)z*
        Test wire.QOTD protocol.
        s'   An apple a day keeps the doctor away.
N)r
   r   r   ÚQOTDr   r   r   r   s      r   Ú	test_QOTDzWireTests.test_QOTD+   sB   € ô ×)Ñ)Ó+ˆÜ�I‰I‹KˆØ	×Ñ˜ÔØ×Ñ˜Ÿ™›Ð$PÕQr    c                 ó`  — t        j                  «       }t        j                  «       }|j	                  |«       |j                  d«       |j                  d«       |j                  d«       |j                  d«       |j                  d«       | j                  |j                  «       d«       y)z-
        Test wire.Discard protocol.
        r   r   r   r   r   r    N)r
   r   r   ÚDiscardr   r   r   r   r   s      r   Útest_discardzWireTests.test_discard4   s}   € ô ×)Ñ)Ó+ˆÜ�L‰L‹NˆØ	×Ñ˜ÔØ	�‰�xÔ Ø	�‰�xÔ Ø	�‰�vÔØ	�‰�vÔØ	�‰�vÔØ×Ñ˜Ÿ™› CÕ(r    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r#   r&   r)   © r    r   r   r      s   „ ñò<ò1òRó)r    r   c                   ó   — e Zd ZdZd„ Zy)Ú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   — t         j                  j                  | |«      }|| _        |S )zE
        Create the protocol instance and keeps track of it.
        )r   ÚProxyClientFactoryÚbuildProtocolÚprotoInstance©r   ÚaddrÚprotos      r   r3   z(TestableProxyClientFactory.buildProtocolK   s)   € ô ×.Ñ.×<Ñ<¸TÀ4ÓHˆØ"ˆÔØˆr    N©r*   r+   r,   r-   r3   r.   r    r   r0   r0   C   s   „ ñór    r0   c                   ó   — e Zd ZdZd„ Zy)Ú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                 óˆ   ‡ — t         j                  j                  ‰ |«      }t        «       ‰ _        ˆ fd„|_        |‰ _        |S )z‡
        Create the protocol instance, keeps track of it, and makes it use
        C{clientFactoryInstance} as client factory.
        c                  ó   •— ‰ j                   S ©N)ÚclientFactoryInstance©r   s   €r   ú<lambda>z4TestableProxyFactory.buildProtocol.<locals>.<lambda>h   s   ø€ ¨d×.HÑ.H€ r    )r   ÚProxyFactoryr3   r0   r>   ÚclientProtocolFactoryr4   r5   s   `  r   r3   z"TestableProxyFactory.buildProtocol`   s=   ø€ ô
 ×(Ñ(×6Ñ6°t¸TÓBˆÜ%?Ó%AˆÔ"ã&HˆÔ#Ø"ˆÔØˆr    Nr8   r.   r    r   r:   r:   T   s   „ ñ	ó
r    r:   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚPortforwardingTestsz
    Test port forwarding.
    c                 óv   — t        j                  «       | _        t        j                  «       | _        g | _        y r=   )r   r   ÚserverProtocolr   ÚProtocolÚclientProtocolÚ	openPortsr?   s    r   ÚsetUpzPortforwardingTests.setUpr   s(   € Ü"Ÿi™i›kˆÔÜ&×/Ñ/Ó1ˆÔØˆ�r    c                 ó€  — 	 | j                   j                  j                  j                  «        	 | j                   j
                  j                  }|j                  j                  «        	 | j                  j                  j                  «        	 | j                  j                  j                  «        t        j                  | j                  D �cg c]!  }t        j                  |j                  «      ‘Œ# c}«      S # t        $ r Y ŒÚw xY w# t        $ r Y Œ®w xY w# t        $ r Y Œ˜w xY w# t        $ r Y Œ‚w xY wc c}w r=   )ÚproxyServerFactoryr4   Ú	transportÚloseConnectionÚAttributeErrorr>   rH   rF   r   ÚgatherResultsrI   ÚmaybeDeferredÚstopListening)r   ÚpiÚps      r   ÚtearDownzPortforwardingTests.tearDownw   s  € ð	Ø×#Ñ#×1Ñ1×;Ñ;×JÑJÔLð	Ø×(Ñ(×>Ñ>×LÑLˆBØ�L‰L×'Ñ'Ô)ð	Ø×Ñ×)Ñ)×8Ñ8Ô:ð	Ø×Ñ×)Ñ)×8Ñ8Ô:ô ×"Ñ"Ø;?¿>¹>ÖJ°aŒU× Ñ  §¡Õ1ÒJó
ð 	
øô ò 	Ùð	ûô
 ò 	Ùð	ûô ò 	Ùð	ûô ò 	Ùð	üò KsL   ‚.C? ±:D Á,$D Â$D, Ã&D;Ã?	DÄ
DÄ	DÄDÄ	D)Ä(D)Ä,	D8Ä7D8c                 ó¦  ‡ ‡‡‡	— t        j                  «       }ˆ fd„|_         t        j                  d|d¬«      }‰ j                  j                  |«       t        d|j                  «       j                  «      ‰ _	        t        j                  d‰ j                  d¬«      }‰ j                  j                  |«       dŠg Š	t        j                  «       Šˆˆˆ	ˆ fd„}|‰ j                  _        ˆˆ fd„}|‰ j                  _        t        j                  «       }ˆ fd„|_         t        j                   d|j                  «       j                  |«       ‰S )	z=
        Test port forwarding through Echo protocol.
        c                  ó   •— ‰ j                   S r=   )rF   r?   s   €r   r@   z6PortforwardingTests.test_portforward.<locals>.<lambda>’   s   ø€ ¨T×-@Ñ-@€ r    r   ú	127.0.0.1)Ú	interfaceiè  c                 óÂ   •— ‰j                  t        | «      «       t        ‰«      ‰k\  r6‰j                  dj	                  ‰«      d‰z  «       ‰j                  d «       y y )Nr    ó   x)Úextendr	   Úlenr   ÚjoinÚcallback)ÚdataÚdÚnBytesÚreceivedr   s    €€€€r   ÚtestDataReceivedz>PortforwardingTests.test_portforward.<locals>.testDataReceived¡   sM   ø€ Ø�O‰OœI d›OÔ,Ü�8‹} Ò&Ø× Ñ  §¡¨(Ó!3°T¸F±]ÔCØ—
‘
˜4Õ ð 'r    c                  óV   •— ‰j                   j                  j                  d‰ z  «       y )Nr[   )rH   rM   Úwrite)rb   r   s   €€r   ÚtestConnectionMadez@PortforwardingTests.test_portforward.<locals>.testConnectionMade©   s!   ø€ Ø×Ñ×)Ñ)×/Ñ/°°v±Õ>r    c                  ó   •— ‰ j                   S r=   )rH   r?   s   €r   r@   z6PortforwardingTests.test_portforward.<locals>.<lambda>¯   s   ø€ ¨×)<Ñ)<€ r    )r   ÚServerFactoryr   Ú	listenTCPrI   Úappendr:   ÚgetHostÚportrL   r   ÚDeferredrH   r   ÚconnectionMadeÚClientFactoryÚ
connectTCP)
r   ÚrealServerFactoryÚrealServerPortÚproxyServerPortrd   rg   ÚclientFactoryra   rb   rc   s
   `      @@@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                 óø  — t        j                  ddd«      }t        j                  dd«      j	                  |«      }t        j                  «       }||_        t        j                  «       }|j                  |«       | j                  t        |j                  «      d«       |j                  d   \  }}}}}	| j                  |t        j                  «       |j	                  |«      }
t        j                  «       }|
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.
        ÚTCPrX   r   é   N)r   ÚIPv4Addressr   rA   r3   r
   ÚMemoryReactorr   r   r   r   r]   Ú
tcpClientsÚassertIsInstancer2   ÚassertIsÚproducerÚ
assertTrueÚ	streaming)r   r6   Úserverr   ÚserverTransportÚhostrm   ru   Ú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-   rJ   rU   rv   r‰   r.   r    r   rD   rD   m   s   „ ñòò

ò,&óP!3r    rD   c                   ó   — e Zd ZdZd„ Zy)ÚStringTransportTestszA
    Test L{proto_helpers.StringTransport} helper behaviour.
    c                 ón   — t        j                  «       }| j                  t        |j                  d«       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    r   r‹   r‹   Ù   s   „ ñó5r    r‹   N)r-   Útwisted.internetr   r   r   r   Útwisted.protocolsr   r   Útwisted.python.compatr	   Útwisted.testr
   Útwisted.trialr   ÚTestCaser   r2   r0   rA   r:   rD   r‹   r.   r    r   ú<module>r˜      s|   ðñ÷ ?Ó >ß /Ý +Ý &Ý "ô1)�×!Ñ!ô 1)ôh ×!?Ñ!?ô ô"˜;×3Ñ3ô ô2i3˜(×+Ñ+ô i3ôX
5˜8×,Ñ,õ 
5r    