Ϫf&dZddlmZmZmZmZddlmZmZddl m Z ddl m Z ddl mZGddejZGd d ej"ZGd d ej&ZGd dejZGddejZy)z+ Test cases for twisted.protocols package. )addressdeferprotocolreactor) portforwardwire) iterbytes) proto_helpers)unittestc(eZdZdZdZdZdZdZy) WireTestsz Test wire protocols. c`tj}tj}|j ||j d|j d|j d|j d|j d|j |jdy)zT Test wire.Echo protocol: send some data and check it send it back. helloworldhowareyoushelloworldhowareyouN)r StringTransportrEchomakeConnection dataReceived assertEqualvalueselftas =/usr/lib/python3/dist-packages/twisted/test/test_protocols.py test_echozWireTests.test_echos~  ) ) + IIK  x  x  v v v $:;ctj}tj}|j ||j |j dy)z) Test wire.Who protocol. sroot N)r rrWhorrrrs rtest_whozWireTests.test_who"sA  ) ) + HHJ  K0r ctj}tj}|j ||j |j dy)z* Test wire.QOTD protocol. s'An apple a day keeps the doctor away. N)r rrQOTDrrrrs r test_QOTDzWireTests.test_QOTD+sB  ) ) + IIK  $PQr c`tj}tj}|j ||j d|j d|j d|j d|j d|j |jdy)z- Test wire.Discard protocol. rrrrrr N)r rrDiscardrrrrrs r test_discardzWireTests.test_discard4s}  ) ) + LLN  x  x  v v v C(r N)__name__ __module__ __qualname____doc__rr#r&r)r rr r s <1R )r r ceZdZdZdZy)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} cTtjj||}||_|S)zE Create the protocol instance and keeps track of it. )rProxyClientFactory buildProtocol protoInstanceraddrprotos rr3z(TestableProxyClientFactory.buildProtocolKs)..<z4TestableProxyFactory.buildProtocol..hs d.H.Hr )r ProxyFactoryr3r0r>clientProtocolFactoryr4r5s` rr3z"TestableProxyFactory.buildProtocol`s= ((66tTB%?%A"&H#" r Nr8r.r rr:r:Ts   r r:c(eZdZdZdZdZdZdZy)PortforwardingTestsz Test port forwarding. cvtj|_tj|_g|_yr=)rrserverProtocolrProtocolclientProtocol openPortsr?s rsetUpzPortforwardingTests.setUprs("iik&//1r c |jjjj |jj j}|jj |j jj |jjjtj|jDcgc]!}tj|j#c}S#t$rYwxYw#t$rYwxYw#t$rYwxYw#t$rYwxYwcc}wr=) proxyServerFactoryr4 transportloseConnectionAttributeErrorr>rHrFr gatherResultsrI maybeDeferred stopListening)rpips rtearDownzPortforwardingTests.tearDownws   # # 1 1 ; ; J J L ((>>LLB LL ' ' )     ) ) 8 8 :     ) ) 8 8 :"";?>> JaU  1 J                KsL.C?:D,$D$D,&D;? D  D  DD D)(D), D87D8c tj}fd|_tjd|d}jj |t d|jj_ tjdjd}jj |dg tj fd}|j_ fd}|j_tj}fd|_tj d|jj|S) z= Test port forwarding through Echo protocol. cjSr=)rFr?srr@z6PortforwardingTests.test_portforward..s T-@-@r r 127.0.0.1) interfaceicjt|tk\r6jdj dzj dyy)Nr x)extendr lenrjoincallback)datadnBytesreceivedrs rtestDataReceivedz>PortforwardingTests.test_portforward..testDataReceivedsM OOIdO ,8}&  (!3TF]C 4 'r cVjjjdzy)Nr[)rHrMwrite)rbrsrtestConnectionMadez@PortforwardingTests.test_portforward..testConnectionMades!    ) ) / /v >r cjSr=)rHr?srr@z6PortforwardingTests.test_portforward..s )<)<r )r ServerFactoryr listenTCPrIappendr:getHostportrLrDeferredrHrconnectionMade ClientFactory connectTCP) rrealServerFactoryrealServerPortproxyServerPortrdrg clientFactoryrarbrcs ` @@@rtest_portforwardz$PortforwardingTests.test_portforwards%224%@" **1.?;W n-"6 //166# "++ t&&+  o. NN  ! ,<( ?.@* ..0 !< ;(?(?(A(F(F Vr ctjddd}tjddj |}t j }||_t j}|j||jt|jd|jd\}}}}} |j|tj|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. TCPrXrN)r IPv4AddressrrAr3r MemoryReactorrrrrr] tcpClientsassertIsInstancer2assertIsproducer assertTrue streaming) rr6serverrserverTransporthostrmrutimeout_clientclientTransports rtest_registerProducersz*PortforwardingTests.test_registerProducerss4 ""5+q9))+q9GGM --/ (779o. W//0!4070B0B10E-dM7A m[-K-KL,,T2'779o. o..@ o..@ 112 112r N)r*r+r,r-rJrUrvrr.r rrDrDms  ,&P!3r rDceZdZdZdZy)StringTransportTestszA Test L{proto_helpers.StringTransport} helper behaviour. cntj}|jt|jdy)zY Test that L{proto_helpers.StringTransport} doesn't accept unicode data. fooN)r r assertRaises TypeErrorrf)rss rtest_noUnicodez#StringTransportTests.test_noUnicodes(  ) ) + )QWWe4r N)r*r+r,r-rr.r rrrs 5r rN)r-twisted.internetrrrrtwisted.protocolsrrtwisted.python.compatr twisted.testr twisted.trialr TestCaser r2r0rAr:rDrr.r rrs|?>/+&"1)!!1)h!?!?";332i3(++i3X 58,, 5r