+
    Dfj7                     t   R t ^ RIHt ^ RIHtHtHt ^ RIHt ^ RI	H
t
HtHt ^ RIHt ^ RIHtHt ^ RIHt  ! R R	]P(                  4      t ! R
 R]4      t ! R R4      t ! R R]]P0                  4      t ! R R]]P0                  4      t ! R R]]P0                  4      t ! R R]P0                  4      tR# )z.
Test case for L{twisted.protocols.loopback}.
)implementer)defer
interfacesreactor)Deferred)IAddressIPullProducerIPushProducer)Protocol)basicloopback)unittestc                   8   a  ] tR t^t o R tR tR tR tRtV t	R# )SimpleProtocolc                V    \         P                  ! 4       V n        . V n        . V n        R # N)r   r   connlinesconnLostselfs   &</usr/lib/python3/dist-packages/twisted/test/test_loopback.py__init__SimpleProtocol.__init__   s    NN$	
    c                <    V P                   P                  R 4       R # r   )r   callbackr   s   &r   connectionMadeSimpleProtocol.connectionMade   s    		4 r   c                <    V P                   P                  V4       R # r   )r   appendr   lines   &&r   lineReceivedSimpleProtocol.lineReceived   s    

$r   c                <    V P                   P                  V4       R # r   )r   r    )r   reasons   &&r   connectionLostSimpleProtocol.connectionLost   s    V$r   )r   r   r   N)
__name__
__module____qualname____firstlineno__r   r   r#   r'   __static_attributes____classdictcell____classdict__s   @r   r   r      s     
! % %r   r   c                   *   a  ] tR t^#t o ^ tR tRtV tR# )DoomProtocolc                2   V ;P                   ^,          un         V P                   ^8  d$   V P                  RV P                   3,          4       \        P                  W4       V P                  R,          R8X  d   V P
                  P                  4        R# R# )   s   Hello %d   Hello 3N)isendLiner   r#   r   	transportloseConnectionr!   s   &&r   r#   DoomProtocol.lineReceived&   sf    !66A: MM+	12##D/::b>Z'NN))+ (r    N)r)   r*   r+   r,   r7   r#   r-   r.   r/   s   @r   r2   r2   #   s     	A, ,r   r2   c                   ,   a  ] tR t^1t o R tR tRtV tR# )LoopbackTestCaseMixinc                   a aa \        4       o\        4       oV3R  lpSP                  P                  V4       VVV 3R lp\        P                  ! S P
                  SS4      pVP                  V4       V# )c                 ^   < SP                  R 4       SP                  P                  4        R# s   THIS IS LINE ONE!N)r8   r9   r:   resultss   &r   	sendALine<LoopbackTestCaseMixin.testRegularFunction.<locals>.sendALine6   s     JJ+,KK&&(r   c                    < SP                  SP                  R .4       SP                  \        SP                  4      ^4       SP                  \        SP                  4      ^4       R# rA   assertEqualr   lenr   ignoredcrD   r   s   &r   check8LoopbackTestCaseMixin.testRegularFunction.<locals>.check<   sK    QWW';&<=S_a0S_a0r   )r   r   addCallbackr   maybeDeferredloopbackFuncr   rE   rN   drM   rD   s   f   @@r   testRegularFunction)LoopbackTestCaseMixin.testRegularFunction2   s^    	) 	
9%	1
  1 11a8	er   c                   a aa \        4       o\        4       oV3R  lpSP                  P                  V4       VVV 3R lp\        P                  ! S P
                  SS4      pVP                  V4       V# )c                 *   < SP                  R 4       R# )	   DOOM LINEN)r8   rB   s   &r   rE   =LoopbackTestCaseMixin.testSneakyHiddenDoom.<locals>.sendALineI   s    JJ|$r   c                   < SP                  SP                  . RO4       SP                  SP                  . RO4       SP                  \        SP                  4      ^4       SP                  \        SP                  4      ^4       R# )   Hello 1N)r\      Hello 2r5   )rY   r\   r]   r5   rH   rK   s   &r   rN   9LoopbackTestCaseMixin.testSneakyHiddenDoom.<locals>.checkN   sb    QWW&JKK S_a0S_a0r   )r2   r   rP   r   rQ   rR   rS   s   f   @@r   testSneakyHiddenDoom*LoopbackTestCaseMixin.testSneakyHiddenDoomE   s\    NN	% 	
9%	1  1 11a8	er   r<   N)r)   r*   r+   r,   rU   r_   r-   r.   r/   s   @r   r>   r>   1   s     & r   r>   c                      a  ] tR t^[t o ]! ]P                  4      tR tR t	R t
R tRR ltR tR tR tR	 tRR
 ltR tR tR tR tR tR tR tR tRtV tR# )LoopbackAsyncTestsc                     ! R R\         4      pV! 4       pV! 4       p\        P                  ! W#4       V P                  VP                  4       V P                  VP                  4       R# )ze
Test that the client and server protocol both have makeConnection
invoked on them by loopbackAsync.
c                   *   a  ] tR t^dt o RtR tRtV tR# )<LoopbackAsyncTests.test_makeConnection.<locals>.TestProtocolNc                    Wn         R # r   r9   r   r9   s   &&r   makeConnectionKLoopbackAsyncTests.test_makeConnection.<locals>.TestProtocol.makeConnectiong       !*r   rg   )r)   r*   r+   r,   r9   ri   r-   r.   r/   s   @r   TestProtocolre   d   s     I+ +r   rl   N)r
   r   loopbackAsyncassertIsNotNoner9   )r   rl   serverclients   &   r   test_makeConnection&LoopbackAsyncTests.test_makeConnection^   sT    	+8 	+ v.V--.V--.r   c                  a a  ! R R\         4      pV'       d#   V! 4       p\        4       ;qTn        \        4       pM!\        4       pV! 4       p\        4       ;qVn        \        P                  ! WF4       VV 3R lpVP                  V4      # )z:
Test one of the permutations of client/server host/peer.
c                   &   a  ] tR t^ut o R tRtV tR# )6LoopbackAsyncTests._hostpeertest.<locals>.TestProtocolc                h    \         P                  ! W4       V P                  P                  V4       R # r   )r
   ri   onConnectionr   rh   s   &&r   ri   ELoopbackAsyncTests._hostpeertest.<locals>.TestProtocol.makeConnectionv   s$    ''8!!**95r   r<   N)r)   r*   r+   r,   ri   r-   r.   r/   s   @r   rl   ru   u   s     6 6r   rl   c                 t   < \        V S4      ! 4       pSP                  \        P                  ! V4      4       R # r   )getattr
assertTruer   
providedBy)r9   hostgetr   s   & r   	connected3LoopbackAsyncTests._hostpeertest.<locals>.connected   s)    9c*,DOOH//56r   )r
   r   rw   r   rm   rP   )r   r~   
testServerrl   ro   rT   rp   r   s   ff&     r   _hostpeertest LoopbackAsyncTests._hostpeertestp   sn    
	68 	6
 !^F&.j0A#ZFZF!^F&.j0A#v.	7 }}Y''r   c                &    V P                  RR4      # )zl
Test that the server gets a transport with a properly functioning
implementation of L{ITransport.getHost}.
getHostTr   r   s   &r   test_serverHost"LoopbackAsyncTests.test_serverHost   s    
 !!)T22r   c                &    V P                  RR4      # )z7
Like C{test_serverHost} but for L{ITransport.getPeer}
getPeerTr   r   s   &r   test_serverPeer"LoopbackAsyncTests.test_serverPeer   s     !!)T22r   c                &    V P                  RR4      # )zl
Test that the client gets a transport with a properly functioning
implementation of L{ITransport.getHost}.
r   Fr   )r   r~   s   &&r   test_clientHost"LoopbackAsyncTests.test_clientHost   s    
 !!)U33r   c                &    V P                  RR4      # )z8
Like C{test_clientHost} but for L{ITransport.getPeer}.
r   Fr   r   s   &r   test_clientPeer"LoopbackAsyncTests.test_clientPeer   s     !!)U33r   c                   a  ! R R\         4      p ! V3R lR\         4      pV'       d    V! 4       pV! 4       p\        4       ;qvn        MV! 4       p\        4       ;qun        V! 4       p\        P                  ! WV4       V# )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                   *   a  ] tR t^t o RtR tRtV tR# )9LoopbackAsyncTests._greetingtest.<locals>.GreeteeProtocolr   c                    V ;P                   V,          un         V P                   R 8X  d   V P                  P                  R4       R# R#    bytesN)bytesreceivedr   r   r   s   &&r   dataReceivedFLoopbackAsyncTests._greetingtest.<locals>.GreeteeProtocol.dataReceived   s3    

e#
::)MM**40 *r   r<   Nr)   r*   r+   r,   r   r   r-   r.   r/   s   @r   GreeteeProtocolr      s     E1 1r   r   c                   .   <a  ] tR t^t o V3R ltRtV tR# )9LoopbackAsyncTests._greetingtest.<locals>.GreeterProtocolc                   < SR 8X  d   V P                   P                  R4       R# V P                   P                  RR.4       R# )writer   s   byts   esN)r9   r   writeSequencer   r   s   &r   r   HLoopbackAsyncTests._greetingtest.<locals>.GreeterProtocol.connectionMade   s3    G#NN((2NN00&%Ar   r<   Nr)   r*   r+   r,   r   r-   r.   )r0   r   s   @r   GreeterProtocolr      s     B Br   r   )r
   r   r   r   rm   )r   r   r   r   r   ro   rp   rT   s   &f&     r   _greetingtest LoopbackAsyncTests._greetingtest   sm    	1h 	1	Bh 	B $&F$&F"**,A$&F"**,A$&Fv.r   c                &    V P                  RR4      # )zl
Test that on a connection where the client speaks first, the server
receives the bytes sent by the client.
r   Fr   r   s   &r   test_clientGreeting&LoopbackAsyncTests.test_clientGreeting   s    
 !!'511r   c                &    V P                  RR4      # )zb
Like C{test_clientGreeting}, but use C{writeSequence} instead of
C{write} to issue the greeting.
r   Fr   r   s   &r   test_clientGreetingSequence.LoopbackAsyncTests.test_clientGreetingSequence   s    
 !!/599r   c                &    V P                  RR4      # )zl
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_serverGreeting&LoopbackAsyncTests.test_serverGreeting   s    
 !!'400r   c                &    V P                  RR4      # )zb
Like C{test_serverGreeting}, but use C{writeSequence} instead of
C{write} to issue the greeting.
r   Tr   r   s   &r   test_serverGreetingSequence.LoopbackAsyncTests.test_serverGreetingSequence   s    
 !!/488r   c                *  aaaa \        ^ ^
4       Uu. uF  pRV3,          NK  	  upo ! VV3R lR\        4      p ! VVV3R lR\        4      pV! 4       oV! 4       o\        4       Sn        \        P
                  ! SS4       SP                  # u upi )    s   %dc                   0   <a  ] tR t^t o VV3R ltRtV tR# );LoopbackAsyncTests._producertest.<locals>.ProducingProtocolc                ~   < S! \        S4      4      V n        V P                  P                  V P                  4       R # r   )listproducerstartr9   )r   producerClass	toProduces   &r   r   JLoopbackAsyncTests._producertest.<locals>.ProducingProtocol.connectionMade   s)     -d9o >##DNN3r   )r   Nr   )r0   r   r   s   @r   ProducingProtocolr      s     4 4r   r   c                   6   <a  ] tR t^t o RtVVV3R ltRtV tR# );LoopbackAsyncTests._producertest.<locals>.ReceivingProtocolr   c                   < V ;P                   V,          un         V P                   R P                  S4      8X  d    V P                  P                  SS34       R# R# )r   N)r   joinr   r   )r   datarp   ro   r   s   &&r   r   HLoopbackAsyncTests._producertest.<locals>.ReceivingProtocol.dataReceived   sB    

d"
::)!44MM**FF+;< 5r   r<   Nr   )r0   rp   ro   r   s   @r   ReceivingProtocolr      s     E= =r   r   )ranger
   r   r   r   rm   )r   r   r7   r   r   rp   ro   r   s   &f   @@@r   _producertest LoopbackAsyncTests._producertest   s    +0B<8<aUaT\\<8		4 	4 	4
	= 	= 	= #$"$"*vv.) 9s   Bc                   a  \        \        4       ! R R4      4       pS P                  V4      pV 3R lpVP                  V4       V# )z?
Test a push producer registered against a loopback transport.
c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	:LoopbackAsyncTests.test_pushProducer.<locals>.PushProducer   Fc                    Wn         R # r   r   r   r   s   &&r   r   CLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.__init__  rk   r   c                    R V n         R# TN)resumedr   s   &r   resumeProducingJLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.resumeProducing  s	    #r   c                V    Wn         VP                  V R 4       V P                  4        R# r   )consumerregisterProducer_produceAndScheduler   r   s   &&r   r   @LoopbackAsyncTests.test_pushProducer.<locals>.PushProducer.start
  s#     ())$5((*r   c                   V P                   '       dX   V P                  P                  V P                   P                  ^ 4      4       \        P
                  ! ^ V P                  4       R# V P                  P                  4        R# r   N)r   r   r   popr   	callLaterr   unregisterProducerr   s   &r   r   NLoopbackAsyncTests.test_pushProducer.<locals>.PushProducer._produceAndSchedule  sR    >>>MM''(:(:1(=>%%a)A)ABMM446r   )r   r   r   N)r)   r*   r+   r,   r   r   r   r   r   r-   r.   r/   s   @r   PushProducerr      s#     G+$+
7 7r   r   c                 \   < V w  rSP                  VP                  P                  R 4       R# )z0Streaming producer should not have been resumed.N)assertFalser   r   )resultsrp   ro   r   s   &  r   finished6LoopbackAsyncTests.test_pushProducer.<locals>.finished  s)    &V''Br   )r   r	   r   rP   )r   r   rT   r   s   f   r   test_pushProducer$LoopbackAsyncTests.test_pushProducer   sK    
 
]	#	7 	7 
$	7* |,	 	
hr   c                \    \        \        4       ! R R4      4       pV P                  V4      # )z?
Test a pull producer registered against a loopback transport.
c                   2   a  ] tR tRt o R tR tR tRtV tR# ):LoopbackAsyncTests.test_pullProducer.<locals>.PullProduceri'  c                    Wn         R # r   r   r   s   &&r   r   CLoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.__init__)  rk   r   c                J    Wn         V P                   P                  V R 4       R# )FN)r   r   r   s   &&r   r   @LoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.start,  s     (..tU;r   c                    V P                   P                  V P                  P                  ^ 4      4       V P                  '       g   V P                   P	                  4        R# R# r   )r   r   r   r   r   r   s   &r   r   JLoopbackAsyncTests.test_pullProducer.<locals>.PullProducer.resumeProducing0  sA    ##DNN$6$6q$9:~~~MM446 &r   )r   r   N)	r)   r*   r+   r,   r   r   r   r-   r.   r/   s   @r   PullProducerr   '  s     +<7 7r   r   )r   r   r   )r   r   s   & r   test_pullProducer$LoopbackAsyncTests.test_pullProducer"  s3    
 
]	#	7 	7 
$	7 !!,//r   c                   a a  ! R R\         4      p ! R R\         4      pV! 4       pV! 4       o\        P                  ! SV4      pVV 3R lpVP                  V4       V# )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                   &   a  ] tR tRt o R tRtV tR# )9LoopbackAsyncTests.test_writeNotReentrant.<locals>.Serveri>  c                <    V P                   P                  R 4       R# r   )r9   r   r   s   &&r   r   FLoopbackAsyncTests.test_writeNotReentrant.<locals>.Server.dataReceived?  s    $$X.r   r<   N)r)   r*   r+   r,   r   r-   r.   r/   s   @r   Serverr   >  s     / /r   r   c                   6   a  ] tR tRt o RtR tR tR tRtV t	R# )9LoopbackAsyncTests.test_writeNotReentrant.<locals>.ClientiB  Fc                H    \         P                  ! ^ V P                  4       R# r   )r   r   gor   s   &r   r   HLoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.connectionMadeE  s    !!!TWW-r   c                J    V P                   P                  R 4       RV n        R# )   fooTN)r9   r   readyr   s   &r   r  <LoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.goH  s    $$V,!
r   c                \    V P                   V n        V P                  P                  4        R # r   )r  wasReadyr9   r:   r   s   &&r   r   FLoopbackAsyncTests.test_writeNotReentrant.<locals>.Client.dataReceivedL  s     $

--/r   )r  r  N)
r)   r*   r+   r,   r  r   r  r   r-   r.   r/   s   @r   Clientr  B  s     E."0 0r   r  c                 >   < SP                  SP                  4       R # r   )r{   r  )rL   rp   r   s   &r   
cbFinished=LoopbackAsyncTests.test_writeNotReentrant.<locals>.cbFinishedT  s    OOFOO,r   )r
   r   rm   rP   )r   r   r  ro   rT   r  rp   s   f     @r   test_writeNotReentrant)LoopbackAsyncTests.test_writeNotReentrant7  sU    	/X 	/	0X 	0 ""662	- 	
j!r   c                  a aaa . oV3R lp\        4       o\        4       o\        P                  ! SSV4      pS P                  S. 4       SP                  P                  R4       SP                  P                  R4       SP                  P                  R4       SP                  P                  R4       SP                  P                  4        VVV V3R lpVP                  V4       V# )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                    < . pV '       d"   VP                  V P                  4       4       K)  SP                  W34       R # r   )r    r~   )queuetargetr   	pumpCallss   && r   dummyPolicy7LoopbackAsyncTests.test_pumpPolicy.<locals>.dummyPolicyb  s-    EUYY[)f_-r   r     bar   baz   quuxc                 @   < SP                  SS. RO3SRR.3.4       R# )r  Nr  r  )r  r  N)rI   )rL   rp   r  r   ro   s   &r   
cbComplete6LoopbackAsyncTests.test_pumpPolicy.<locals>.cbCompletet  s.     12Vff=M4NO	r   )r
   r   rm   rI   r9   r   r:   rP   )r   r  r   r  rp   r  ro   s   f   @@@r   test_pumpPolicy"LoopbackAsyncTests.test_pumpPolicyZ  s     		. ))&&+FB'v&v&v&w''')	 	 	Z(r   c                $   . p\        4       pVP                  Vn        \        P                  ! 4       pVP                  R4       VP                  R4       VP                  R4       \        P                  ! W24       V P                  VRR.4       R# )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
   r    r   r   _LoopbackQueueputidentityPumpPolicyrI   r   r   rp   r  s   &   r   test_identityPumpPolicy*LoopbackAsyncTests.test_identityPumpPolicy  sp    
 #ll'')		&		&		$##E2 01r   c                "   . p\        4       pVP                  Vn        \        P                  ! 4       pVP                  R4       VP                  R4       VP                  R4       \        P                  ! W24       V P                  VR.4       R# )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  Ns   foobar)r
   r    r   r   r#  r$  collapsingPumpPolicyrI   r&  s   &   r   test_collapsingPumpPolicy,LoopbackAsyncTests.test_collapsingPumpPolicy  sm     #ll'')		&		&		$%%e4,r   r<   N)r   )r   )r)   r*   r+   r,   staticmethodr   rm   rR   rq   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r'  r+  r-   r.   r/   s   @r   rb   rb   [   sx      6 67L/$(63344!F2:19.%N0*!F#J2"- -r   rb   c                   :    ] tR tRt]! ]P                  4      tRtR# )LoopbackTCPTestsi  r<   N)	r)   r*   r+   r,   r-  r   loopbackTCPrR   r-   r<   r   r   r/  r/    s     4 45Lr   r/  c                   p    ] tR tRt]! ]P                  4      t]P                  ! ]
R4      f   RtRtR# RtR# )LoopbackUNIXTestsi  Nz-Current reactor does not support UNIX socketsr<   )r)   r*   r+   r,   r-  r   loopbackUNIXrR   r   IReactorUNIXr   skipr-   r<   r   r   r2  r2    s/     5 56Lw-5> 6r   r2  c                   F   a  ] tR tRt o Rt ! R R]4      tR tR tRt	V t
R# )	LoopbackRelayTesti  z6
Test for L{twisted.protocols.loopback.LoopbackRelay}
c                   .   a  ] tR tRt o RtRtR tRtV tR# )LoopbackRelayTest.Receiveri  z6
Simple Receiver class used for testing LoopbackRelay
r   c                8    V ;P                   V,          un         R# )z)Accumulate received data for verificationN)r   )r   r   s   &&r   r   'LoopbackRelayTest.Receiver.dataReceived  s    IIIr   r<   N)	r)   r*   r+   r,   __doc__r   r   r-   r.   r/   s   @r   Receiverr9    s     	 	 	r   r=  c                &   V P                  4       p\        P                  ! V4      pVP                  R4       VP                  R4       V P	                  VP
                  R4       VP                  4        V P	                  VP
                  R4       R# )z8Test to verify that the write function works as expecteds   abcs   defr   s   abcdefN)r=  r   LoopbackRelayr   rI   r   clearBufferr   receiverrelays   &  r   
test_writeLoopbackRelayTest.test_write  si    ==?&&x0FF,	2r   c                .   V P                  4       p\        P                  ! V4      pVP                  . RO4       VP                  . RO4       V P	                  VP
                  R4       VP                  4        V P	                  VP
                  R4       R# )z@Test to verify that the writeSequence function works as expectedr   s+   The quick brown fox jumps over the lazy dogN)s   The s   quick s   brown s   fox )s   jumps s   over s   the lazy dog)r=  r   r?  r   rI   r   r@  rA  s   &  r   test_writeSequence$LoopbackRelayTest.test_writeSequence  sp    ==?&&x0DEBC,(VWr   r<   N)r)   r*   r+   r,   r<  r
   r=  rD  rG  r-   r.   r/   s   @r   r7  r7    s'     	8 	3X Xr   r7  N)r<  zope.interfacer   twisted.internetr   r   r   twisted.internet.deferr   twisted.internet.interfacesr   r   r	   twisted.internet.protocolr
   twisted.protocolsr   r   twisted.trialr   LineReceiverr   r2   r>   TestCaserb   r/  r2  r7  r<   r   r   <module>rR     s   
 ' 7 7 + N N . - "%U'' % ,> ,' 'TE-.0A0A E-P
6,h.?.? 6?-x/@/@ ?"X)) "Xr   