+
    üÐj¬  ã                   óÄ  € R t ^ RIt^ RIHt ^ RI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HtHtHtHt ^ R	IHtHt ^ R
IHt ^ RIHt ^ RIHtH t  ^ RI!H"t" ^ RI#H$t$H%t% R t&]! ]4       ! R R4      4       t']! ]]'4       ]! ]4       ! R R4      4       t(]! ]]'4        ! R R]%4      t) ! R R]%4      t* ! R R4      t+RR lt,] 3R lt-Rt. ! R R]$4      t/R# ) zœ
Tests for (new code in) L{twisted.application.internet}.

@var AT_LEAST_ONE_ATTEMPT: At least enough seconds for L{ClientService} to make
    one attempt.
N)Úimplementer)ÚverifyClass)Úinternet)ÚClientServiceÚStreamServerEndpointServiceÚTimerService)Útask)ÚCancelledErrorÚDeferred)ÚIFileDescriptorReceiverÚIHalfCloseableProtocolÚIListeningPortÚIStreamClientEndpointÚIStreamServerEndpoint)ÚFactoryÚProtocol)ÚClock)ÚStringTransport)ÚformatEventÚglobalLogPublisher)ÚFailure)ÚSynchronousTestCaseÚTestCasec                 ó   € R# )zE
A fake target function for testing TimerService which does nothing.
N© r   ó    ÚH/usr/lib/python3/dist-packages/twisted/application/test/test_internet.pyÚfakeTargetFunctionr   )   s   € ñ 	r   c                   óZ   a € ] tR t^0t o RtRtRtRt]! 4       t	^ t
R tR tR tR tRtV tR# )Ú
FakeServeraA  
In-memory implementation of L{IStreamServerEndpoint}.

@ivar result: The L{Deferred} resulting from the call to C{listen}, after
    C{listen} has been called.

@ivar factory: The factory passed to C{listen}.

@ivar cancelException: The exception to errback C{self.result} when it is
    cancelled.

@ivar port: The L{IListeningPort} which C{listen}'s L{Deferred} will fire
    with.

@ivar listenAttempts: The number of times C{listen} has been invoked.

@ivar failImmediately: If set, the exception to fail the L{Deferred}
    returned from C{listen} before it is returned.
Nc                ó$   € \        4       V n        R # ©N)ÚFakePortÚport©Úselfs   &r   Ú__init__ÚFakeServer.__init__L   s   € Ü“JˆŽ	r   c                óì   a € S ;P                   ^,          un         VS n        \        V 3R lR7      S n        S P                  e&   S P                  P                  S P                  4       S P                  # )zÂ
Return a Deferred and store it for future use.  (Implementation of
L{IStreamServerEndpoint}).

@param factory: the factory to listen with

@return: a L{Deferred} stored in L{FakeServer.result}
c                 ó:   <€ V P                  SP                  4      # r!   )ÚerrbackÚcancelException)Údr%   s   &€r   Ú<lambda>Ú#FakeServer.listen.<locals>.<lambda>Z   s   ø€ °1·9±9¸T×=QÑ=QÔ3Rr   )Ú	canceller)ÚlistenAttemptsÚfactoryr
   ÚresultÚfailImmediatelyr*   )r%   r1   s   f&r   ÚlistenÚFakeServer.listenO   sX   ø€ ð 	×Ò˜qÕ ÕØˆŒÜÔ)RÔSˆŒØ×ÑÒ+Ø�K‰K×Ñ × 4Ñ 4Ô5Ø�{‰{Ðr   c                óP   € V P                   P                  V P                  4       R# )z�
Test code should invoke this method after causing C{listen} to be
invoked in order to fire the L{Deferred} previously returned from
C{listen}.
N)r2   Úcallbackr#   r$   s   &r   ÚstartedListeningÚFakeServer.startedListening_   s   € ð 	�‰×Ñ˜TŸY™YÖ'r   c                óP   € V P                   P                  P                  R4       R# )zÛ
Test code should invoke this method after causing C{stopListening} to
be invoked on the port fired from the L{Deferred} returned from
C{listen} in order to cause the L{Deferred} returned from
C{stopListening} to fire.
N)r#   Údeferredr7   r$   s   &r   ÚstoppedListeningÚFakeServer.stoppedListeningg   s   € ð 	�	‰	×Ñ×#Ñ# DÖ)r   )r1   r#   r2   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r2   r1   r3   r	   r+   r0   r&   r4   r8   r<   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r   0   sA   ø‡ € ñð( €FØ€GØ€OÙ$Ó&€OØ€Nòòò (÷*ð *r   r   c                   ó:   a € ] tR t^tt o RtRtR tR tR tRt	V t
R# )r"   zg
Fake L{IListeningPort} implementation.

@ivar deferred: The L{Deferred} returned by C{stopListening}.
Nc                ó8   € \        4       V n        V P                  # )zH
Stop listening.

@return: a L{Deferred} stored in L{FakePort.deferred}
)r
   r;   r$   s   &r   ÚstopListeningÚFakePort.stopListening~   s   € ô !›
ˆŒØ�}‰}Ðr   c                ó   € R # r!   r   r$   s   &r   ÚgetHostÚFakePort.getHost‡   ó   € ár   c                ó   € R # r!   r   r$   s   &r   ÚstartListeningÚFakePort.startListening‹   rN   r   ©r;   )r>   r?   r@   rA   rB   r;   rI   rL   rP   rC   rD   rE   s   @r   r"   r"   t   s%   ø‡ € ñð €Hòò÷ð r   r"   c                   óp   a € ] tR t^“t o 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RtV tR# )ÚEndpointServiceTestsz,
Tests for L{twisted.application.internet}.
c                óŒ   € \        4       V n        \        4       V n        \	        V P                  V P                  4      V n        R# )zX
Construct a stub server, a stub factory, and a
L{StreamServerEndpointService} to test.
N)r   Ú
fakeServerr   r1   r   Úsvcr$   s   &r   ÚsetUpÚEndpointServiceTests.setUp˜   s,   € ô
 %›,ˆŒÜ“yˆŒÜ.¨t¯©ÀÇÁÓMˆŽr   c                óš   € V P                   P                  4        V P                  V P                  V P                  P                  4       R# )zo
L{StreamServerEndpointService.privilegedStartService} calls its
endpoint's C{listen} method with its factory.
N)rW   ÚprivilegedStartServiceÚassertIdenticalr1   rV   r$   s   &r   Útest_privilegedStartServiceÚ0EndpointServiceTests.test_privilegedStartService¡   s2   € ð
 	�‰×'Ñ'Ô)Ø×Ñ˜TŸ\™\¨4¯?©?×+BÑ+BÖCr   Nc                óÂ   € \        4       V P                  n        RV P                  n        T P                  \         T;'       g    V P                  P                  4       R# )aØ  
L{StreamServerEndpointService.startService} should raise synchronously
if the L{Deferred} returned by its wrapped
L{IStreamServerEndpoint.listen} has already fired with an errback and
the L{StreamServerEndpointService}'s C{_raiseSynchronously} flag has
been set.  This feature is necessary to preserve compatibility with old
behavior of L{twisted.internet.strports.service}, which is to return a
service which synchronously raises an exception from C{startService}
(so that, among other things, twistd will not start running).  However,
since L{IStreamServerEndpoint.listen} may fail asynchronously, it is a
bad idea to rely on this behavior.

@param thunk: If specified, a callable to execute in place of
    C{startService}.
TN)ÚZeroDivisionErrorrV   r3   rW   Ú_raiseSynchronouslyÚassertRaisesÚstartService)r%   Úthunks   &&r   Ú(test_synchronousRaiseRaisesSynchronouslyÚ=EndpointServiceTests.test_synchronousRaiseRaisesSynchronously©   sB   € ô  +<Ó*=ˆ�‰Ô'Ø'+ˆ�‰Ô$Ø×ÑÔ+¨U×-KÐ-K°d·h±h×6KÑ6KÖLr   c                óP   € V P                  V P                  P                  4       R# )z³
L{StreamServerEndpointService.privilegedStartService} should behave the
same as C{startService} with respect to
L{EndpointServiceTests.test_synchronousRaiseRaisesSynchronously}.
N)re   rW   r[   r$   s   &r   Útest_synchronousRaisePrivilegedÚ4EndpointServiceTests.test_synchronousRaisePrivileged½   s   € ð 	×5Ñ5°d·h±h×6UÑ6UÖVr   c                óô   € V P                   P                  4        V P                  P                  P	                  \        4       4       V P                  \
        4      pV P                  \        V4      ^4       R# )zÜ
L{StreamServerEndpointService.startService} and
L{StreamServerEndpointService.privilegedStartService} should both log
an exception when the L{Deferred} returned from their wrapped
L{IStreamServerEndpoint.listen} fails.
N)	rW   rc   rV   r2   r*   r`   ÚflushLoggedErrorsÚassertEqualÚlen©r%   Úloggeds   & r   Útest_failReportsErrorÚ*EndpointServiceTests.test_failReportsErrorÅ   sU   € ð 	�‰×ÑÔØ�‰×Ñ×&Ñ&Ô'8Ó':Ô;Ø×'Ñ'Ô(9Ó:ˆØ×Ñœ˜V› aÖ(r   c                ó  € RV P                   n        V P                   P                  4        V P                  P                  P                  \        4       4       V P                  \        4      pV P                  \        V4      ^4       R# )a  
L{StreamServerEndpointService.startService} and
L{StreamServerEndpointService.privilegedStartService} should both log
an exception when the L{Deferred} returned from their wrapped
L{IStreamServerEndpoint.listen} fails asynchronously, even if
C{_raiseSynchronously} is set.
TN)
rW   ra   rc   rV   r2   r*   r`   rk   rl   rm   rn   s   & r   Ú!test_asynchronousFailReportsErrorÚ6EndpointServiceTests.test_asynchronousFailReportsErrorÑ   sa   € ð (,ˆ�‰Ô$Ø�‰×ÑÔØ�‰×Ñ×&Ñ&Ô'8Ó':Ô;Ø×'Ñ'Ô(9Ó:ˆØ×Ñœ˜V› aÖ(r   c                óÌ   € \        4       V P                  n        V P                  P	                  4        V P                  \         4      pV P                  \        V4      ^4       R# )z‡
Without the C{_raiseSynchronously} compatibility flag, failing
immediately has the same behavior as failing later; it logs the error.
N)r`   rV   r3   rW   rc   rk   rl   rm   rn   s   & r   Ú test_synchronousFailReportsErrorÚ5EndpointServiceTests.test_synchronousFailReportsErrorß   sH   € ô
 +<Ó*=ˆ�‰Ô'Ø�‰×ÑÔØ×'Ñ'Ô(9Ó:ˆØ×Ñœ˜V› aÖ(r   c                óæ   € V P                   P                  4        V P                  V P                  V P                  P                  4       V P                  V P                   P                  R4       R# )z£
L{StreamServerEndpointService.startService} sets the C{running} flag,
and calls its endpoint's C{listen} method with its factory, if it
has not yet been started.
TN)rW   rc   r\   r1   rV   rl   Úrunningr$   s   &r   Útest_startServiceUnstartedÚ/EndpointServiceTests.test_startServiceUnstartedé   sL   € ð 	�‰×ÑÔØ×Ñ˜TŸ\™\¨4¯?©?×+BÑ+BÔCØ×Ñ˜Ÿ™×)Ñ)¨4Ö0r   c                óò   € V P                  4        V P                  P                  4        V P                  V P                  P
                  ^4       V P                  V P                  P                  R4       R# )z‚
L{StreamServerEndpointService.startService} sets the C{running} flag,
but nothing else, if the service has already been started.
TN)r]   rW   rc   rl   rV   r0   ry   r$   s   &r   Útest_startServiceStartedÚ-EndpointServiceTests.test_startServiceStartedó   sT   € ð
 	×(Ñ(Ô*Ø�‰×ÑÔØ×Ñ˜Ÿ™×7Ñ7¸Ô;Ø×Ñ˜Ÿ™×)Ñ)¨4Ö0r   c                óú  € V P                   P                  4        V P                  P                  4        V P                   P	                  4        V P                   P                  4       p. pVP                  VP                  4       V P                  \        V4      ^ 4       V P                  P                  4        V P                  \        V4      ^4       V P                  V P                   P                  4       R# )zÃ
L{StreamServerEndpointService.stopService} calls C{stopListening} on
the L{IListeningPort} returned from its endpoint, returns the
C{Deferred} from stopService, and sets C{running} to C{False}.
N)rW   r[   rV   r8   rc   ÚstopServiceÚaddCallbackÚappendrl   rm   r<   ÚassertFalsery   ©r%   r2   Úls   &  r   Útest_stopServiceÚ%EndpointServiceTests.test_stopServiceý   s­   € ð 	�‰×'Ñ'Ô)Ø�‰×(Ñ(Ô*à�‰×ÑÔØ—‘×%Ñ%Ó'ˆØˆØ×Ñ˜1Ÿ8™8Ô$Ø×Ñœ˜Q› Ô#Ø�‰×(Ñ(Ô*Ø×Ñœ˜Q› Ô#Ø×Ñ˜Ÿ™×)Ñ)Ö*r   c                ó  € V P                   P                  4        V P                   P                  4       p. pVP                  VP                  4       V P                  VR.4       V P                  V P                  \        4      . 4       R# )zº
L{StreamServerEndpointService.stopService} cancels the L{Deferred}
returned by C{listen} if it has not yet fired.  No error will be logged
about the cancellation of the listen attempt.
N)rW   r[   r€   ÚaddBothr‚   rl   rk   r	   r„   s   &  r   Ú#test_stopServiceBeforeStartFinishedÚ8EndpointServiceTests.test_stopServiceBeforeStartFinished  sh   € ð 	�‰×'Ñ'Ô)Ø—‘×%Ñ%Ó'ˆØˆØ�‰�q—x‘xÔ Ø×Ñ˜˜T˜FÔ#Ø×Ñ˜×/Ñ/´Ó?ÀÖDr   c                ó`  € \        4       V P                  n        V P                  P	                  4        V P                  P                  4       p. pVP                  VP                  4       V P                  VR.4       V P                  \         4      pV P                  \        V4      ^4       R# )zÁ
L{StreamServerEndpointService.stopService} cancels the L{Deferred}
returned by C{listen} if it has not fired yet.  An error will be logged
if the resulting exception is not L{CancelledError}.
N)r`   rV   r+   rW   r[   r€   r�   r‚   rl   rk   rm   )r%   r2   r…   ÚstoppingErrorss   &   r   Ú test_stopServiceCancelStartErrorÚ5EndpointServiceTests.test_stopServiceCancelStartError  s„   € ô +<Ó*=ˆ�‰Ô'Ø�‰×'Ñ'Ô)Ø—‘×%Ñ%Ó'ˆØˆØ×Ñ˜1Ÿ8™8Ô$Ø×Ñ˜˜T˜FÔ#Ø×/Ñ/Ô0AÓBˆØ×Ñœ˜^Ó,¨aÖ0r   )r1   rV   rW   r!   )r>   r?   r@   rA   rB   rX   r]   re   rh   rp   rs   rv   rz   r}   r†   rŠ   rŽ   rC   rD   rE   s   @r   rT   rT   “   sP   ø‡ € ñòNòDôMò(Wò
)ò)ò)ò1ò1ò+ò$E÷1ð 1r   rT   c                   ó`   a € ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )ÚTimerServiceTestsi,  a	  
Tests for L{twisted.application.internet.TimerService}.

@type timer: L{TimerService}
@ivar timer: service to test

@type clock: L{task.Clock}
@ivar clock: source of time

@type deferred: L{Deferred}
@ivar deferred: deferred returned by L{TimerServiceTests.call}.
c                ó°   € \        ^V P                  4      V n        \        P                  ! 4       ;V n        V P                  n        \        4       V n        R# )z!
Set up a timer service to test.
N)r   ÚcallÚtimerr   r   Úclockr
   r;   r$   s   &r   rX   ÚTimerServiceTests.setUp:  s8   € ô " ! T§Y¡YÓ/ˆŒ
Ü(,¯
ª
«Ð4ˆŒ
�T—Z‘ZÔ%Ü ›
ˆŽr   c                ó   € V P                   # )zb
Function called by L{TimerService} being tested.

@returns: C{self.deferred}
@rtype: L{Deferred}
rR   r$   s   &r   r“   ÚTimerServiceTests.callB  s   € ð �}‰}Ðr   c                óÂ  € V P                   P                  4        V P                  V P                   P                  R4       V P	                  V P                   P
                  \        P                  4       V P                  V P                  V P                   P
                  P                  4       V P                  V P                   P
                  P                  R4       R# )zw
When L{TimerService.startService} is called, it marks itself
as running, creates a L{task.LoopingCall} and starts it.
zService is startedzLoopingCall is startedN)
r”   rc   Ú
assertTruery   ÚassertIsInstanceÚ_loopr   ÚLoopingCallr\   r•   r$   s   &r   Útest_startServiceÚ#TimerServiceTests.test_startServiceK  s�   € ð
 	�
‰
×ÑÔ!Ø�‰˜Ÿ
™
×*Ñ*Ð,@ÔAØ×Ñ˜dŸj™j×.Ñ.´×0@Ñ0@ÔAØ×Ñ˜TŸZ™Z¨¯©×)9Ñ)9×)?Ñ)?Ô@Ø�‰˜Ÿ
™
×(Ñ(×0Ñ0Ð2JÖKr   c                ó    € . pVP                   R/ 3V P                  n        V P                  P                  4        V P	                  R.V4       R# )zQ
When L{TimerService.startService} is called, it calls the function
immediately.
Nr!   )r‚   r”   r“   rc   rl   )r%   r2   s   & r   Ú$test_startServiceRunsCallImmediatelyÚ6TimerServiceTests.test_startServiceRunsCallImmediatelyV  sA   € ð
 ˆØ!Ÿ=™=¨'°2Ð6ˆ�
‰
ŒØ�
‰
×ÑÔ!Ø×Ñ˜$˜ Ö(r   c                ó   a€ \         P                  ! 4       oV3R lpV P                  \        RV4       V P                  P                  4        V P                  SV P                  P                  P                  4       R# )z‘
L{TimerService.startService} uses L{internet._maybeGlobalReactor} to
choose the reactor to pass to L{task.LoopingCall}
uses the global reactor.
c                 ó   <€ S# r!   r   )ÚmaybeReactorÚ
otherClocks   &€r   ÚgetOtherClockÚKTimerServiceTests.test_startServiceUsesGlobalReactor.<locals>.getOtherClockh  s	   ø€ ØÐr   Ú_maybeGlobalReactorN)	r   r   Úpatchr   r”   rc   r\   rœ   r•   )r%   r§   r¦   s   & @r   Ú"test_startServiceUsesGlobalReactorÚ4TimerServiceTests.test_startServiceUsesGlobalReactor`  sX   ø€ ô —Z’Z“\ˆ
õ	ð 	�
‰
”8Ð2°MÔBØ�
‰
×ÑÔ!Ø×Ñ˜Z¨¯©×)9Ñ)9×)?Ñ)?Ö@r   c                ód  € V P                   P                  4        V P                   P                  4       pV P                  V4       V P	                  RV P                   P
                  4       V P                  P                  \        4       4       V P                  V P                  V4      R4       R# )zŽ
When L{TimerService.stopService} is called while a call is in progress.
the L{Deferred} returned doesn't fire until after the call finishes.
TN)r”   rc   r€   ÚassertNoResultrl   ry   r;   r7   Úobjectr\   ÚsuccessResultOf©r%   r,   s   & r   Útest_stopServiceWaitsÚ'TimerServiceTests.test_stopServiceWaitso  s}   € ð
 	�
‰
×ÑÔ!Ø�J‰J×"Ñ"Ó$ˆØ×Ñ˜AÔØ×Ñ˜˜tŸz™z×1Ñ1Ô2Ø�‰×Ñœv›xÔ(Ø×Ñ˜T×1Ñ1°!Ó4°dÖ;r   c                óö   € V P                   P                  4        V P                  P                  \	        4       4       V P                   P                  4       pV P                  V P                  V4      R4       R# )z}
When L{TimerService.stopService} is called while a call isn't in progress.
the L{Deferred} returned has already been fired.
N)r”   rc   r;   r7   r¯   r€   r\   r°   r±   s   & r   Útest_stopServiceImmediatelyÚ-TimerServiceTests.test_stopServiceImmediately{  sU   € ð
 	�
‰
×ÑÔ!Ø�‰×Ñœv›xÔ(Ø�J‰J×"Ñ"Ó$ˆØ×Ñ˜T×1Ñ1°!Ó4°dÖ;r   c                óh  € V P                   P                  4        V P                  P                  \	        \        4       4      4       V P                  \
        4      pV P                  ^\        V4      4       V P                   P                  4       pV P                  V P                  V4      R4       R# )zœ
When function passed to L{TimerService} returns a deferred that errbacks,
the exception is logged, and L{TimerService.stopService} doesn't raise an error.
N)r”   rc   r;   r*   r   r`   rk   rl   rm   r€   r\   r°   )r%   Úerrorsr,   s   &  r   Útest_failedCallLogsErrorÚ*TimerServiceTests.test_failedCallLogsError…  s�   € ð
 	�
‰
×ÑÔ!Ø�‰×ÑœgÔ&7Ó&9Ó:Ô;Ø×'Ñ'Ô(9Ó:ˆØ×Ñ˜œC ›KÔ(Ø�J‰J×"Ñ"Ó$ˆØ×Ñ˜T×1Ñ1°!Ó4°dÖ;r   c                ó  € \        ^\        4      pVP                  4        \        P                  ! V4      pVP                  4        \        P                  ! V4      p\        4       p\        VRV4      pV P                  WE4       R# )zY
When pickling L{internet.TimerService}, it won't pickle
L{internet.TimerService._loop}.
rœ   N©
r   r   rc   ÚpickleÚdumpsr€   Úloadsr¯   Úgetattrr\   ©r%   r”   ÚdumpedTimerÚloadedTimerÚnothingÚvalues   &     r   Ú$test_pickleTimerServiceNotPickleLoopÚ6TimerServiceTests.test_pickleTimerServiceNotPickleLoop‘  sh   € ô ˜QÔ 2Ó3ˆØ×ÑÔÜ—l’l 5Ó)ˆØ×ÑÔÜ—l’l ;Ó/ˆÜ“(ˆÜ˜ W¨gÓ6ˆØ×Ñ˜WÖ,r   c                ó  € \        ^\        4      pVP                  4        \        P                  ! V4      pVP                  4        \        P                  ! V4      p\        4       p\        VRV4      pV P                  WE4       R# )za
When pickling L{internet.TimerService}, it won't pickle
L{internet.TimerService._loopFinished}.
Ú_loopFinishedNr¼   rÁ   s   &     r   Ú,test_pickleTimerServiceNotPickleLoopFinishedÚ>TimerServiceTests.test_pickleTimerServiceNotPickleLoopFinished¡  sh   € ô ˜QÔ 2Ó3ˆØ×ÑÔÜ—l’l 5Ó)ˆØ×ÑÔÜ—l’l ;Ó/ˆÜ“(ˆÜ˜ _°gÓ>ˆØ×Ñ˜WÖ,r   )r•   r;   r”   N)r>   r?   r@   rA   rB   rX   r“   rž   r¡   r«   r²   rµ   r¹   rÆ   rÊ   rC   rD   rE   s   @r   r‘   r‘   ,  sC   ø‡ € ñò#òò	Lò)òAò
<ò<ò
<ò-÷ -ð -r   r‘   c                   ó*   a € ] tR tRt o RtR tRtV tR# )ÚConnectInformationi²  a«  
Information about C{endpointForTesting}

@ivar connectQueue: a L{list} of L{Deferred} returned from C{connect}.  If
    these are not already fired, you can fire them with no value and they
    will trigger building a factory.

@ivar constructedProtocols: a L{list} of protocols constructed.

@ivar passedFactories: a L{list} of L{IProtocolFactory}; the ones actually
    passed to the underlying endpoint / i.e. the reactor.
c                ó0   € . V n         . V n        . V n        R # r!   ©ÚconnectQueueÚconstructedProtocolsÚpassedFactoriesr$   s   &r   r&   ÚConnectInformation.__init__À  s   € ØˆÔØ$&ˆÔ!Ø!ˆÖr   rÏ   N)r>   r?   r@   rA   rB   r&   rC   rD   rE   s   @r   rÍ   rÍ   ²  s   ø‡ € ñ÷"ð "r   rÍ   c                ól   a a€ \        \        4       ! V V3R lR4      4       p\        4       oSV! 4       3# )a(  
Make a sample endpoint for testing.

@param fireImmediately: If true, fire all L{Deferred}s returned from
    C{connect} immedaitely.

@return: a 2-tuple of C{(information, endpoint)}, where C{information} is a
    L{ConnectInformation} describing the operations in progress on
    C{endpoint}.
c                   ó0   <a € ] tR tRt o VV3R ltRtV tR# )Ú.endpointForTesting.<locals>.ClientTestEndpointiÒ  c                óè   <a€ \        4       pSP                  P                  S4       VP                  VV3R  l4       pSP                  P                  V4       S'       d   VP                  R4       V# )c                 ó–   <€ SP                  R 4      pSP                  P                  V4       \        4       pVP	                  V4       V# r!   )ÚbuildProtocolrÑ   r‚   r   ÚmakeConnection)ÚignoredÚprotocolÚ	transportr1   Úinfos   &  €€r   ÚcreateProtocolÚNendpointForTesting.<locals>.ClientTestEndpoint.connect.<locals>.createProtocolØ  sB   ø€ à"×0Ñ0°Ó6�Ø×)Ñ)×0Ñ0°Ô:Ü+Ó-�	Ø×'Ñ'¨	Ô2Ø�r   N)r
   rÒ   r‚   r�   rÐ   r7   )r%   r1   r2   rß   ÚfireImmediatelyrÞ   s   &f  €€r   ÚconnectÚ6endpointForTesting.<locals>.ClientTestEndpoint.connectÔ  s`   ù€ Ü“ZˆFØ× Ñ ×'Ñ'¨Ô0à×Ñõ ó  ð ð ×Ñ×$Ñ$ VÔ,ßØ—‘ Ô%ØˆMr   r   N)r>   r?   r@   rA   râ   rC   rD   )rF   rá   rÞ   s   @€€r   ÚClientTestEndpointrÖ   Ò  s   ù‡ € ÷	ô 	r   rä   )r   r   rÍ   )rá   rä   rÞ   s   f @r   ÚendpointForTestingrå   Æ  s;   ù€ ô Ô&Ó'÷ô ó (ðô$ Ó€DØÑ#Ó%Ð%Ð%r   c                óx   aa€ . oSP                  SP                  4       V P                  VV3R l4       V3R l# )a  
Catch the global log stream.

@param testCase: The test case to add a cleanup to.

@param logPublisher: the log publisher to add and remove observers for.

@return: a 0-argument callable that returns a list of textual log messages
    for comparison.
@rtype: L{list} of L{unicode}
c                  ó:   <€ S P                  SP                  4      # r!   )ÚremoveObserverr‚   )ÚlogPublisherÚlogss   €€r   r-   ÚcatchLogs.<locals>.<lambda>÷  s   ø€  × ;Ñ ;¸D¿K¹KÔ Hr   c                  óD   <€ S U u. uF  p \        V 4      NK  	  up # u up i r!   )r   )Úeventrê   s    €r   r-   rë   ø  s   ø€ ±DÓ9±D¨5”K Ö&±DÒ9ùÒ9s   †)ÚaddObserverr‚   Ú
addCleanup)ÚtestCaseré   rê   s   &f@r   Ú	catchLogsrñ   é  s1   ù€ ð €DØ×Ñ˜TŸ[™[Ô)Ø×ÑÕHÔIÜ9Ð9r   g      Y@c                   óü   a € ] tR tRt o RtRR]R3R ltR tR tR t	R	 t
R
 tR tR tR tR tR tR tR tV 3R lR ltR tR tR tR tR tR tR tR tR tR tR tR tR  t R! t!R" t"R# t#R$ t$R% t%R&t&V t'R'# )(ÚClientServiceTestsiþ  z
Tests for L{ClientService}.
TFc                ón  a aaaaa€ / pVP                  \        4       R7       VP                  V4       VR,          o\        VR7      w  rx. ;oVn         ! VVV3R lR\        4      p	V	! 4       ;Vn        p
\        WŠ3/ VB oVV V3R lpS P                  V4       V'       d   SP                  4        VS3# )a´  
Create a L{ClientService} along with a L{ConnectInformation} indicating
the connections in progress on its endpoint.

@param fireImmediately: Should all of the endpoint connection attempts
    fire synchronously?
@type fireImmediately: L{bool}

@param startService: Should the L{ClientService} be started before
    being returned?
@type startService: L{bool}

@param protocolType: a 0-argument callable returning a new L{IProtocol}
    provider to be used for application-level protocol connections.

@param kw: Arbitrary keyword arguments to be passed on to
    L{ClientService}

@return: a 2-tuple of L{ConnectInformation} (for information about test
    state) and L{ClientService} (the system under test).  The
    L{ConnectInformation} has 2 additional attributes;
    C{applicationFactory} and C{applicationProtocols}, which refer to
    the unwrapped protocol factory and protocol instances passed in to
    L{ClientService} respectively.
©r•   r•   ©rá   c                   ó>   <a a€ ] tR tRt o ZtV VV3R ltRtVtV ;t# )Ú>ClientServiceTests.makeReconnector.<locals>.RememberingFactoryi2  c                ó\   <€ S'       d   R # \         SV `  V4      pSP                  V4       V# r!   )ÚsuperrÙ   r‚   )r%   Úaddrr2   Ú	__class__ÚapplicationProtocolsÚrefuseConnectionss   && €€€r   rÙ   ÚLClientServiceTests.makeReconnector.<locals>.RememberingFactory.buildProtocol5  s+   ø€ ß$ÙÜ™Ñ.¨tÓ4�Ø$×+Ñ+¨FÔ3Ø�r   r   )	r>   r?   r@   rA   rÜ   rÙ   rC   rD   Ú__classcell__)rü   rF   rý   ÚprotocolTyperþ   s   @@€€€r   ÚRememberingFactoryrø   2  s   ú‡ € Ù#ˆH÷÷ r   r  c                  óš   <€ R Sn         SP                  '       d   SP                  4        SP                  S P	                  4       . 4       R # r!   )Ú	_protocolry   r€   rl   ÚgetDelayedCalls)r•   r%   Úservices   €€€r   ÚstopÚ0ClientServiceTests.makeReconnector.<locals>.stop@  s;   ø€ Ø $ˆGÔØ��ˆØ×#Ñ#Ô%ð ×Ñ˜U×2Ñ2Ó4°bÖ9r   )	Úupdater   rå   rý   r   ÚapplicationFactoryr   rï   rc   )r%   rá   rc   r  rþ   ÚkwÚnkwÚcqÚendpointr  r1   r  rý   r•   r  s   f&&ff,      @@@r   ÚmakeReconnectorÚ"ClientServiceTests.makeReconnector  s©   ý€ ðB ˆØ�
‰
œ›ˆ
Ô!Ø�
‰
�2ŒØ�G•ˆÜ)¸/ÔJ‰ˆð :<Ð;Ð˜rÔ6÷	ñ 	¤ô 	ñ +=Ó*>Ð>ˆÔ ä Ñ9°SÑ9ˆ÷	:ð 	�‰˜ÔßØ× Ñ Ô"Ø�7ˆ{Ðr   c                óx   € V P                  RR7      w  rV P                  \        VP                  4      ^4       R# )z<
When the service is started, a connection attempt is made.
Frö   N)r  rl   rm   rÐ   )r%   r  r  s   &  r   rž   Ú$ClientServiceTests.test_startServiceM  s2   € ð ×*Ñ*¸5Ð*ÓA‰ˆØ×Ñœ˜RŸ_™_Ó-¨qÖ1r   c                óø   € V P                  4       w  rVP                  pV P                  VP                  ^ 4       VP                  ^ ,          pVP                  4        V P                  VP                  ^4       R# )zù
Although somewhat obscure, L{IProtocolFactory} includes both C{doStart}
and C{doStop} methods; ensure that when these methods are called on the
factory that was passed to the reactor, the factory that was passed
from the application receives them.
N)r  r
  rl   ÚnumPortsrÒ   ÚdoStart)r%   r  r  ÚfirstAppFactoryÚfirstPassedFactorys   &    r   Útest_startStopFactoryÚ(ClientServiceTests.test_startStopFactoryT  sh   € ð ×*Ñ*Ó,‰ˆØ×/Ñ/ˆØ×Ñ˜×1Ñ1°1Ô5Ø×/Ñ/°Õ2ÐØ×"Ñ"Ô$Ø×Ñ˜×1Ñ1°1Ö5r   c                óD  € V P                  4       w  rVP                  4       pV P                  V4       VP                  ^ ,          pV P	                  VP
                  P                  R4       VP                  \        \        4       4      4       V P                  V4       R# )z˜
When the service is stopped, no further connect attempts are made.  The
returned L{Deferred} fires when all outstanding connections have been
stopped.
TN)r  r€   r®   rÑ   rl   rÝ   ÚdisconnectingÚconnectionLostr   Ú	Exceptionr°   ©r%   r  r  r,   rÜ   s   &    r   Útest_stopServiceWhileConnectedÚ1ClientServiceTests.test_stopServiceWhileConnectedb  s   € ð ×*Ñ*Ó,‰ˆØ×ÑÓ!ˆØ×Ñ˜AÔØ×*Ñ*¨1Õ-ˆØ×Ñ˜×+Ñ+×9Ñ9¸4Ô@Ø×Ñ¤¬	«Ó 4Ô5Ø×Ñ˜QÖr   c                óú  € V P                  4       w  rVP                  4       pV P                  V4       VP                  ^ ,          pV P	                  VP
                  P                  R4       VP                  4        V P                  V4       V P	                  \        VP                  4      ^4       VP                  \        \        R4      4      4       V P	                  \        VP                  4      ^4       R# )z
When L{ClientService} is restarted after having been connected, it
waits to start connecting until after having disconnected.
Tzsynthetic connectionLostN)r  r€   r®   rÑ   rl   rÝ   r  rc   rm   r  r   r  r  s   &    r   Ú#test_startServiceWaitsForDisconnectÚ6ClientServiceTests.test_startServiceWaitsForDisconnectp  sÅ   € ð
 ×*Ñ*Ó,‰ˆØ×ÑÓ!ˆØ×Ñ˜AÔØ×*Ñ*¨1Õ-ˆØ×Ñ˜×+Ñ+×9Ñ9¸4Ô@Ø×ÑÔØ×Ñ˜AÔØ×Ñœ˜R×4Ñ4Ó5°qÔ9Ø×Ñ¤¬	Ð2LÓ(MÓ NÔOØ×Ñœ˜R×4Ñ4Ó5°qÖ9r   c                óh  € V P                  RR7      w  rVP                  ^ ,          P                  R4       VP                  ^ ,          pVP	                  4       pV P                  V4       VP                  4       pV P                  V4       VP                  4        V P                  V4       V P                  V4       V P                  VP                  P                  R4       VP                  \        \        R4      4      4       V P                  V4       VP                  ^,          P                  R4       V P                  \        VP                  4      ^4       V P!                  V P                  V4      VP"                  ^,          4       VP	                  4       pV P                  V4       R# )zý
When L{ClientService} is stopping - that is,
L{ClientService.stopService} has been called, but the L{Deferred} it
returns has not fired yet - calling L{startService} will cause a new
connection to be made, and new calls to L{whenConnected} to succeed.
Frö   NTzsynthetic connection lost)r  rÐ   r7   rÑ   r€   r®   ÚwhenConnectedrc   rl   rÝ   r  r  r   r  r°   rm   r\   rý   )r%   r  r  ÚfirstÚstoppedÚnextProtocolÚsecondStoppeds   &      r   Útest_startServiceWhileStoppingÚ1ClientServiceTests.test_startServiceWhileStopping€  sZ  € ð ×*Ñ*¸5Ð*ÓA‰ˆØ
�‰˜Õ×#Ñ# DÔ)Ø×'Ñ'¨Õ*ˆØ×%Ñ%Ó'ˆØ×Ñ˜GÔ$Ø×,Ñ,Ó.ˆØ×Ñ˜LÔ)Ø×ÑÔØ×Ñ˜LÔ)Ø×Ñ˜GÔ$Ø×Ñ˜Ÿ™×6Ñ6¸Ô=Ø×ÑœW¤YÐ/JÓ%KÓLÔMØ×Ñ˜WÔ%Ø
�‰˜Õ×#Ñ# DÔ)Ø×Ñœ˜R×4Ñ4Ó5°qÔ9Ø×ÑØ× Ñ  Ó.°×0GÑ0GÈÕ0Jô	
ð  ×+Ñ+Ó-ˆØ×Ñ˜MÖ*r   c                óœ  € V P                  RR7      w  rVP                  4       pV P                  V4       V P                  VP	                  4       \
        4       VP                  4        VP                  R,          P                  R4       V P                  VP                  R,          V P                  VP	                  4       4      4       R# )zó
When L{ClientService} is stopped - that is,
L{ClientService.stopService} has been called and the L{Deferred} it
returns has fired - calling L{startService} will cause a new connection
to be made, and new calls to L{whenConnected} to succeed.
Frö   Néÿÿÿÿ)r  r€   r°   ÚfailureResultOfr%  r	   rc   rÐ   r7   r\   rý   )r%   r  r  r'  s   &   r   Útest_startServiceWhileStoppedÚ0ClientServiceTests.test_startServiceWhileStoppedœ  s£   € ð ×*Ñ*¸5Ð*ÓA‰ˆØ×%Ñ%Ó'ˆØ×Ñ˜WÔ%Ø×Ñ˜W×2Ñ2Ó4´nÔEØ×ÑÔØ
�‰˜Õ×$Ñ$ TÔ*Ø×ÑØ×#Ñ# BÕ'¨×)=Ñ)=¸g×>SÑ>SÓ>UÓ)Vö	
r   c                ó4  € \        \        \        4       ! R R\        4      4       pV P	                  VR7      w  r#VP
                  ^ ,          pV P                  \        P                  ! V4      4       V P                  \        P                  ! V4      4       R# )a  
If the protocol objects returned by the factory given to
L{ClientService} provide special "marker" interfaces for their
transport - L{IHalfCloseableProtocol} or L{IFileDescriptorReceiver} -
those interfaces will be provided by the protocol objects passed on to
the reactor.
c                   ó   € ] tR tRtRtRtR# )ÚEClientServiceTests.test_interfacesForTransport.<locals>.FancyProtocoli¶  z!
Provider of various interfaces.
r   N)r>   r?   r@   rA   rB   rC   r   r   r   ÚFancyProtocolr3  ¶  s   † õr   r4  )r  N)r   r   r   r   r  rÑ   rš   Ú
providedBy)r%   r4  r  r  ÚreactorFacings   &    r   Útest_interfacesForTransportÚ.ClientServiceTests.test_interfacesForTransport­  s~   € ô 
Ô+Ô-DÓ	Eô	œHó 	ó 
Fð	ð
 ×*Ñ*¸Ð*ÓF‰ˆØ×/Ñ/°Õ2ˆØ�‰Ô/×:Ò:¸=ÓIÔJØ�‰Ô.×9Ò9¸-ÓHÖIr   c                ó¢  € \        4       pV P                  RVR7      w  r#VP                  ^ ,          P                  \	        4       4       VP                  \        4       V P                  \        VP                  4      ^4       VP                  4       pVP                  ^,          P                  \	        4       4       V P                  V4       R# )zE
When the service is stopped while retrying, the retry is cancelled.
F©rá   r•   N)r   r  rÐ   r*   r  ÚadvanceÚAT_LEAST_ONE_ATTEMPTrl   rm   r€   r°   ©r%   r•   r  r  r,   s   &    r   Útest_stopServiceWhileRetryingÚ0ClientServiceTests.test_stopServiceWhileRetryingÁ  s–   € ô “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ
�‰˜Õ×"Ñ"¤9£;Ô/Ø�‰Ô*Ô+Ø×Ñœ˜RŸ_™_Ó-¨qÔ1Ø×ÑÓ!ˆØ
�‰˜Õ×"Ñ"¤9£;Ô/Ø×Ñ˜QÖr   c                ó  € \        4       pV P                  RVR7      w  r#V P                  \        VP                  4      ^4       V P                  VP                  ^ ,          4       VP                  4       pV P                  V4       R# )z^
When the service is stopped while initially connecting, the connection
attempt is cancelled.
Fr:  N)r   r  rl   rm   rÐ   r®   r€   r°   r=  s   &    r   Útest_stopServiceWhileConnectingÚ2ClientServiceTests.test_stopServiceWhileConnectingÎ  sn   € ô
 “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ×Ñœ˜RŸ_™_Ó-¨qÔ1Ø×Ñ˜BŸO™O¨AÕ.Ô/Ø×ÑÓ!ˆØ×Ñ˜QÖr   c                óf  € \        4       pV P                  VR7      w  r#VP                  4       pV P                  VP	                  4       . 4       V P                  V P                  V4      VP                  ^ ,          4       V P                  VP                  ^ ,          P                  VP                  ^ ,          4       V P                  \        VP                  ^ ,          4      \        VP                  ^ ,          4      4       V P                  R\        VP                  ^ ,          4      4       R# )za
When a client connects, the service keeps a reference to the new
protocol and resets the delay.
rõ   r  N)r   r  r%  rl   r  r\   r°   rý   rÑ   r  ÚassertInÚstrrÒ   )r%   r•   r  r  ÚawaitingProtocols   &    r   Útest_clientConnectedÚ'ClientServiceTests.test_clientConnectedÚ  sû   € ô
 “ˆØ×*Ñ*°Ð*Ó7‰ˆØ"×0Ñ0Ó2ÐØ×Ñ˜×.Ñ.Ó0°"Ô5Ø×ÑØ× Ñ Ð!1Ó2°B×4KÑ4KÈAÕ4Nô	
ð 	×ÑØ×#Ñ# AÕ&×0Ñ0°"×2IÑ2IÈ!Õ2Lô	
ð 	�‰Ü�×'Ñ'¨Õ*Ó+Ü�×'Ñ'¨Õ*Ó+ô	
ð 	�‰Ø Ü�×"Ñ" 1Õ%Ó&ö	
r   c                óÎ  € \        4       pV P                  RVR7      w  r#V P                  \        VP                  4      ^4       VP                  ^ ,          P                  \        \        4       4      4       VP                  4       pV P                  V4       VP                  R 4       VP                  \        4       V P                  \        VP                  4      ^4       R# )zt
When a client connection fails, the service removes its reference
to the protocol and tries again after a timeout.
Fr:  c                 ó,   € V P                  \        4      # r!   )Útrapr	   )rÛ   s   &r   r-   Ú@ClientServiceTests.test_clientConnectionFailed.<locals>.<lambda>ÿ  s   € °·±¼nÔ1Mr   N)r   r  rl   rm   rÐ   r*   r   r  r%  r®   Ú
addErrbackr;  r<  ©r%   r•   r  r  r%  s   &    r   Útest_clientConnectionFailedÚ.ClientServiceTests.test_clientConnectionFailedò  s¬   € ô
 “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ×Ñœ˜RŸ_™_Ó-¨qÔ1Ø
�‰˜Õ×"Ñ"¤7¬9«;Ó#7Ô8Ø×-Ñ-Ó/ˆØ×Ñ˜MÔ*ð 	× Ñ Ñ!MÔNØ�‰Ô*Ô+Ø×Ñœ˜RŸ_™_Ó-¨qÖ1r   c                ó:  € \        4       pV P                  VRR7      w  r#V P                  \        VP                  4      ^4       VP                  ^ ,          P                  R4       V P                  \        VP                  4      ^4       V P                  V P                  VP                  4       4      VP                  ^ ,          4       VP                  ^ ,          P                  \        \        4       4      4       VP                  \        4       V P                  \        VP                  4      ^4       VP                  ^,          P                  R4       V P                  V P                  VP                  4       4      VP                  ^,          4       R# )zf
When a client connection is lost, the service removes its reference
to the protocol and calls retry.
F)r•   rá   N)r   r  rl   rm   rÐ   r7   r\   r°   r%  rý   rÑ   r  r   r  r;  r<  )r%   r•   r  r  s   &   r   Útest_clientConnectionLostÚ,ClientServiceTests.test_clientConnectionLost  s0  € ô
 “ˆØ×*Ñ*°ÈÐ*ÓN‰ˆØ×Ñœ˜RŸ_™_Ó-¨qÔ1Ø
�‰˜Õ×#Ñ# DÔ)Ø×Ñœ˜RŸ_™_Ó-¨qÔ1Ø×ÑØ× Ñ  ×!6Ñ!6Ó!8Ó9¸2×;RÑ;RÐSTÕ;Uô	
ð 	×Ñ Õ"×1Ñ1´'¼)»+Ó2FÔGØ�‰Ô*Ô+Ø×Ñœ˜RŸ_™_Ó-¨qÔ1Ø
�‰˜Õ×#Ñ# DÔ)Ø×ÑØ× Ñ  ×!6Ñ!6Ó!8Ó9¸2×;RÑ;RÐSTÕ;Uö	
r   c                ó   <€ V ^8„  d   QhRR/# )é   ÚreturnNr   )ÚformatrF   s   "€r   Ú__annotate__ÚClientServiceTests.__annotate__  s   ø€ ÷ $+ñ $+¨dñ $+r   c                óŠ  a a€ \        4       pS P                  V V3R l4       S P                  VRRR7      w  r#S P                  \	        VP
                  4      ^4       VP
                  P                  ^ 4      P                  R4       S P                  \	        VP
                  4      ^ 4       VP                  4       oS P                  S4       VP                  \        4       S P                  \	        VP
                  4      ^4       VP
                  P                  ^ 4      P                  R4       S P                  S4       R# )z�
When the client factory refuses connections by returning None from
buildProtocol, the factory keeps attempting new connections.
c                  ó0   <€ S P                  S\        4      # r!   )r.  r	   )r%   r%  s   €€r   r-   ÚAClientServiceTests.test_clientConnectionRefused.<locals>.<lambda>"  s   ø€  × 4Ñ 4°]ÄNÔ Sr   FT)r•   rá   rþ   N)r   rï   r  rl   rm   rÐ   Úpopr7   r%  r®   r;  r<  rN  s   f   @r   Útest_clientConnectionRefusedÚ/ClientServiceTests.test_clientConnectionRefused  sû   ù€ ô
 “ˆð
 	�‰ÕSÔTØ×*Ñ*ØØ!à"ð	 +ó 
‰ˆð 	×Ñœ˜RŸ_™_Ó-¨qÔ1à
�‰×Ñ˜AÓ×'Ñ'¨Ô-à×Ñœ˜RŸ_™_Ó-¨qÔ1à×-Ñ-Ó/ˆà×Ñ˜MÔ*ð 	�‰Ô*Ô+à×Ñœ˜RŸ_™_Ó-¨qÔ1à
�‰×Ñ˜AÓ×'Ñ'¨Ô-à×Ñ˜MÖ*r   c                óF  € \        4       pV P                  VR7      w  r#VP                  4       pVP                  ^ ,          P	                  \        \        4       4      4       V P                  VP                  4       \        4       V P                  VP                  4       R# )z˜
When a client connection is lost while the service is stopping, the
protocol stopping deferred is called and the reference to the protocol
is removed.
rõ   N)r   r  r€   rÑ   r  r   ÚIndentationErrorr.  r%  r	   rš   Úcalledr=  s   &    r   Ú&test_clientConnectionLostWhileStoppingÚ9ClientServiceTests.test_clientConnectionLostWhileStopping>  sy   € ô “ˆØ×*Ñ*°Ð*Ó7‰ˆØ×ÑÓ!ˆØ
×Ñ Õ"×1Ñ1´'Ô:JÓ:LÓ2MÔNØ×Ñ˜W×2Ñ2Ó4´nÔEØ�‰˜Ÿ™Ö!r   c                ó   € V P                  RRR7      w  rV P                  \        VP                  4      ^ 4       VP	                  4        V P                  \        VP                  4      ^4       \        V 4      pVP	                  4        V P                  \        VP                  4      ^4       V P                  RV! 4       ^ ,          4       R# )z 
If L{ClientService} is started when it's already started, it will log a
complaint and do nothing else (in particular it will not make
additional connections).
F)rá   rc   z$Duplicate ClientService.startServiceN)r  rl   rm   rÐ   rc   rñ   rD  )r%   r  r  Úmessagess   &   r   Útest_startTwiceÚ"ClientServiceTests.test_startTwiceK  sœ   € ð ×*Ñ*¸5ÈuÐ*ÓU‰ˆØ×Ñœ˜RŸ_™_Ó-¨qÔ1Ø×ÑÔØ×Ñœ˜RŸ_™_Ó-¨qÔ1Ü˜T“?ˆØ×ÑÔØ×Ñœ˜RŸ_™_Ó-¨qÔ1Ø�‰Ð<¹h»jÈ½mÖLr   c                ó@  € \        4       pV P                  RVR7      w  r#VP                  4       pVP                  4       pVP                  ^R7      pV P                  V4       V P                  V4       V P                  V4       VP                  ^ ,          P                  R4       V P                  V4      pV P                  V4      pV P                  V4      p	V P                  Wx4       V P                  Wy4       V P                  WrP                  ^ ,          4       R# )zc
L{ClientService.whenConnected} returns a L{Deferred} that fires when a
connection is established.
Fr:  ©ÚfailAfterFailuresN)	r   r  r%  r®   rÐ   r7   r°   r\   rý   )
r%   r•   r  r  ÚaÚbÚcÚresultAÚresultBÚresultCs
   &         r   Útest_whenConnectedLaterÚ*ClientServiceTests.test_whenConnectedLaterZ  s÷   € ô
 “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ×!Ñ!Ó#ˆØ×!Ñ!Ó#ˆØ×!Ñ!°AÐ!Ó6ˆØ×Ñ˜AÔØ×Ñ˜AÔØ×Ñ˜AÔØ
�‰˜Õ×#Ñ# DÔ)Ø×&Ñ& qÓ)ˆØ×&Ñ& qÓ)ˆØ×&Ñ& qÓ)ˆØ×Ñ˜WÔ.Ø×Ñ˜WÔ.Ø×Ñ˜W×&=Ñ&=¸aÕ&@ÖAr   c                óZ  € \        4       pV P                  RVR7      w  r#VP                  4       pVP                  ^R7      pVP                  ^R7      pVP                  ^R7      pV P                  V4       V P                  V4       V P                  V4       V P                  V4       \	        \        4       4      pVP                  ^ ,          P                  V4       V P                  V4       V P                  V P                  V\
        4      V4       V P                  V4       V P                  V4       VP                  \        4       V P                  \        VP                  4      ^4       V P                  V4       V P                  V4       V P                  V4       \	        \        4       4      p	VP                  ^,          P                  V	4       V P                  V4       V P                  V P                  V\
        4      V	4       V P                  V4       \        p
VP                  V
4       V P                  \        VP                  4      ^4       V P                  V4       V P                  V4       VP                  ^,          P                  R4       V P                  V4      pV P                  V4      pV P                  W¼4       V P                  W²P                   ^ ,          4       VP                  ^R7      pV P                  V4      pV P                  W¾4       R# )zy
L{ClientService.whenConnected} returns a L{Deferred} that fails, if
asked, when some number of connections have failed.
Fr:  rj  N)r   r  r%  r®   r   r  rÐ   r*   r\   r.  r;  r<  rl   rm   r7   r°   rý   )r%   r•   r  r  Úa0Úa1Úa2Úa3Úf1Úf2ÚAT_LEAST_TWO_ATTEMPTSÚresultA0ÚresultA3Úa4ÚresultA4s   &              r   Útest_whenConnectedFailsÚ*ClientServiceTests.test_whenConnectedFailso  s�  € ô
 “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ×"Ñ"Ó$ˆØ×"Ñ"°QÐ"Ó7ˆØ×"Ñ"°QÐ"Ó7ˆØ×"Ñ"°QÐ"Ó7ˆØ×Ñ˜BÔØ×Ñ˜BÔØ×Ñ˜BÔØ×Ñ˜BÔä”Y“[Ó!ˆØ
�‰˜Õ×"Ñ" 2Ô&à×Ñ˜BÔØ×Ñ˜T×1Ñ1°"´iÓ@À"ÔEØ×Ñ˜BÔØ×Ñ˜BÔà�‰Ô*Ô+Ø×Ñœ˜RŸ_™_Ó-¨qÔ1à×Ñ˜BÔØ×Ñ˜BÔØ×Ñ˜BÔä”Y“[Ó!ˆØ
�‰˜Õ×"Ñ" 2Ô&à×Ñ˜BÔØ×Ñ˜T×1Ñ1°"´iÓ@À"ÔEØ×Ñ˜BÔä 4ÐØ�‰Ð+Ô,Ø×Ñœ˜RŸ_™_Ó-¨qÔ1à×Ñ˜BÔØ×Ñ˜BÔà
�‰˜Õ×#Ñ# DÔ)à×'Ñ'¨Ó+ˆØ×'Ñ'¨Ó+ˆØ×Ñ˜XÔ0Ø×Ñ˜X×'>Ñ'>¸qÕ'AÔBð ×"Ñ"°QÐ"Ó7ˆØ×'Ñ'¨Ó+ˆØ×Ñ˜XÖ0r   c                óÜ  € \        4       pV P                  RVR7      w  r#VP                  4       pVP                  4       pVP                  ^R7      pV P                  V4       V P                  V4       V P                  V4       VP	                  4        VP                  \        4       V P                  V\        4       V P                  V\        4       V P                  V\        4       R# )zn
L{ClientService.whenConnected} returns a L{Deferred} that fails when
L{ClientService.stopService} is called.
Fr:  rj  N)	r   r  r%  r®   r€   r;  r<  r.  r	   )r%   r•   r  r  rl  rm  rn  s   &      r   Útest_whenConnectedStopServiceÚ0ClientServiceTests.test_whenConnectedStopService©  sÄ   € ô
 “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ×!Ñ!Ó#ˆØ×!Ñ!Ó#ˆØ×!Ñ!°AÐ!Ó6ˆØ×Ñ˜AÔØ×Ñ˜AÔØ×Ñ˜AÔØ×ÑÔØ�‰Ô*Ô+Ø×Ñ˜Q¤Ô/Ø×Ñ˜Q¤Ô/Ø×Ñ˜Q¤Ö/r   c                ó,  € \        4       pV P                  RVR7      w  r#VP                  P                  ^ 4      P	                  \        R4      4       VP                  4       pV P                  VP                  4       . 4       V P                  V4       R# )z®
When L{ClientService.stopService} is called while waiting between
connection attempts, the pending reconnection attempt is cancelled and
the service is stopped immediately.
Fr:  úno connectionN)
r   r  rÐ   r]  r*   r  r€   rl   r  r°   r=  s   &    r   Útest_retryCancelledÚ&ClientServiceTests.test_retryCancelled¼  sy   € ô “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ
�‰×Ñ˜AÓ×&Ñ&¤y°Ó'AÔBØ×ÑÓ!ˆØ×Ñ˜×.Ñ.Ó0°"Ô5Ø×Ñ˜QÖr   c                ó¦   € \        4       pV P                  RRVR7      w  r#VP                  4       pV P                  V P	                  V4      4       R# )z†
Calling L{ClientService.stopService} before
L{ClientService.startService} returns a L{Deferred} that has
already fired with L{None}.
F)rá   rc   r•   N©r   r  r€   ÚassertIsNoner°   )r%   r•   Ú_r  r,   s   &    r   Ú"test_stopServiceBeforeStartServiceÚ5ClientServiceTests.test_stopServiceBeforeStartServiceÉ  sR   € ô “ˆØ×)Ñ)Ø!°¸Uð *ó 
‰
ˆð ×ÑÓ!ˆØ×Ñ˜$×.Ñ.¨qÓ1Ö2r   c                ó¶  € \        4       pV P                  RVR7      w  r#VP                  4       pVP                  ^ ,          P	                  \        R4      4       VP                  4        VP                  4       pV P                  V P                  V4      P                  \        4       V P                  V P                  V4      P                  \        4       R# )z¢
L{ClientService.whenConnected} returns a L{Deferred} that
errbacks with L{CancelledError} if
L{ClientService.stopService} is called between connection
attempts.
Fr:  r†  N)r   r  r%  rÐ   r*   r  r€   r›   r.  rÅ   r	   )r%   r•   r  r  ÚbeforeErrbackAndStopÚafterErrbackAndStops   &     r   Ú'test_whenConnectedErrbacksOnStopServiceÚ:ClientServiceTests.test_whenConnectedErrbacksOnStopServiceÖ  s¶   € ô “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆØ&×4Ñ4Ó6Ðð 	�‰˜Õ×"Ñ"¤9¨_Ó#=Ô>à×ÑÔØ%×3Ñ3Ó5Ðà×ÑØ× Ñ Ð!5Ó6×<Ñ<¼nô	
ð 	×ÑØ× Ñ Ð!4Ó5×;Ñ;¼^ö	
r   c                ór  € \        4       pV P                  RVR7      w  r#VP                  ^ ,          P                  R4       VP	                  4       pVP	                  4       pVP
                  ^ ,          P                  \        \        4       4      4       V P                  V4       V P                  V4       R# )zÅ
Calling L{ClientService.stopService} twice after it has
connected (that is, stopping it while it is disconnecting)
returns a L{Deferred} each time that fires when the
disconnection has completed.
Fr:  N)
r   r  rÐ   r7   r€   rÑ   r  r   ra  r°   ©r%   r•   r  r  ÚfirstStopDeferredÚsecondStopDeferreds   &     r   Ú"test_stopServiceWhileDisconnectingÚ5ClientServiceTests.test_stopServiceWhileDisconnectingï  s›   € ô “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆà
�‰˜Õ×#Ñ# DÔ)ð $×/Ñ/Ó1Ðà$×0Ñ0Ó2Ðð 	×Ñ Õ"×1Ñ1´'Ô:JÓ:LÓ2MÔNà×ÑÐ.Ô/Ø×ÑÐ/Ö0r   c                ó’  € \        4       pV P                  RVR7      w  r#VP                  ^ ,          P                  R4       VP	                  4       pVP                  4        VP	                  4       pVP                  ^ ,          P                  \        \        4       4      4       V P                  V4       V P                  V4       R# )z’
Calling L{ClientService.stopService} after calling a
reconnection attempt returns a L{Deferred} that fires when the
disconnection has completed.
Fr:  N)r   r  rÐ   r7   r€   rc   rÑ   r  r   ra  r°   r•  s   &     r   Útest_stopServiceWhileRestartingÚ2ClientServiceTests.test_stopServiceWhileRestarting  s§   € ô “ˆØ×*Ñ*¸5ÈÐ*ÓN‰ˆà
�‰˜Õ×#Ñ# DÔ)ð $×/Ñ/Ó1Ðà×ÑÔà$×0Ñ0Ó2Ðð 	×Ñ Õ"×1Ñ1´'Ô:JÓ:LÓ2MÔNà×ÑÐ.Ô/Ø×ÑÐ/Ö0r   c                ó  € \        4       pV P                  RVR7      w  r#VP                  4       pVP                  4       pV P                  V P	                  V4      4       V P                  V P	                  V4      4       R# )zv
Calling L{ClientService.stopService} on a stopped service
returns a L{Deferred} that has already fired with L{None}.
Fr:  NrŠ  )r%   r•   rŒ  r  r–  r—  s   &     r   Ú test_stopServiceOnStoppedServiceÚ3ClientServiceTests.test_stopServiceOnStoppedService  st   € ô
 “ˆØ×)Ñ)¸%ÀuÐ)ÓM‰
ˆØ#×/Ñ/Ó1ÐØ$×0Ñ0Ó2Ðà×Ñ˜$×.Ñ.Ð/@ÓAÔBØ×Ñ˜$×.Ñ.Ð/AÓBÖCr   c                óv   a€ ^ .oV3R lpV P                  VRR7      w  r#V P                  ^S^ ,          4       R# )zn
The C{prepareConnection} callable is called after
L{ClientService.startService} once the connection is made.
c                 ó2   <€ S^ ;;,          ^,          uu&   R# ©é    Nr   ©Ú_protoÚpreparess   &€r   ÚprepareConnectionÚ[ClientServiceTests.test_prepareConnectionCalledWhenServiceStarts.<locals>.prepareConnection2  ó   ø€ Ø�Q�K˜1Õ�Kr   T)r§  rc   N)r  rl   )r%   r§  r  r  r¦  s   &   @r   Ú-test_prepareConnectionCalledWhenServiceStartsÚ@ClientServiceTests.test_prepareConnectionCalledWhenServiceStarts+  sE   ø€ ð
 �3ˆõ	ð ×*Ñ*Ø/¸dð +ó 
‰ˆð 	×Ñ˜˜H Q�KÖ(r   c                ó”   a€ . oV3R lpV P                  VR7      w  r#V P                  VP                  ^ ,          S^ ,          4       R# )zN
The C{prepareConnection} callable is passed the connected protocol
instance.
c                 ó*   <€ SP                  V 4       R # r!   ©r‚   )ÚprotoÚnewProtocolss   &€r   r§  ÚVClientServiceTests.test_prepareConnectionCalledWithProtocol.<locals>.prepareConnectionA  s   ø€ Ø×Ñ Ö&r   ©r§  N)r  r\   rÑ   )r%   r§  r  r  r°  s   &   @r   Ú(test_prepareConnectionCalledWithProtocolÚ;ClientServiceTests.test_prepareConnectionCalledWithProtocol:  sL   ø€ ð
 ˆõ	'ð ×*Ñ*Ø/ð +ó 
‰ˆð 	×Ñ˜R×4Ñ4°QÕ7¸Àa½ÖIr   c                ó‚  a€ ^ .oV3R lp\        4       pV P                  VRVR7      w  r4VP                  ^ ,          P                  \	        R4      4       V P                  ^ S^ ,          4       VP                  \        4       VP                  ^,          P                  R4       V P                  ^S^ ,          4       R# )zN
The C{prepareConnection} callback is invoked only once a connection is
made.
c                 ó2   <€ S^ ;;,          ^,          uu&   R# r¢  r   r¤  s   &€r   r§  Ú]ClientServiceTests.test_prepareConnectionCalledAfterConnectionMade.<locals>.prepareConnectionP  r©  r   F)r§  rá   r•   zconnection attempt failedN)	r   r  rÐ   r*   r  rl   r;  r<  r7   ©r%   r§  r•   r  r  r¦  s   &    @r   Ú/test_prepareConnectionCalledAfterConnectionMadeÚBClientServiceTests.test_prepareConnectionCalledAfterConnectionMadeI  s£   ø€ ð
 �3ˆõ	ô “ˆØ×*Ñ*Ø/ÀÈeð +ó 
‰ˆð 	�‰˜Õ×"Ñ"¤9Ð-HÓ#IÔJØ×Ñ˜˜H Q�KÔ(à�‰Ô*Ô+Ø
�‰˜Õ×#Ñ# DÔ)à×Ñ˜˜H Q�KÖ(r   c                óJ  a€ ^ .oV3R lp\        4       pV P                  WR7      w  r4V P                  ^S^ ,          4       VP                  ^ ,          P	                  \        \        4       4      4       VP                  \        4       V P                  ^S^ ,          4       R# )zi
The C{prepareConnection} callback is invoked each time a connection is
made, including on reconnection.
c                 ó2   <€ S^ ;;,          ^,          uu&   R# r¢  r   r¤  s   &€r   r§  ÚUClientServiceTests.test_prepareConnectionCalledOnReconnect.<locals>.prepareConnectiong  r©  r   ©r§  r•   N)	r   r  rl   rÑ   r  r   ra  r;  r<  r¸  s   &    @r   Ú'test_prepareConnectionCalledOnReconnectÚ:ClientServiceTests.test_prepareConnectionCalledOnReconnect`  s�   ø€ ð
 �3ˆõ	ô “ˆØ×*Ñ*Ø/ð +ó 
‰ˆð 	×Ñ˜˜H Q�KÔ(ð 	×Ñ Õ"×1Ñ1´'Ô:JÓ:LÓ2MÔNØ�‰Ô*Ô+à×Ñ˜˜H Q�KÖ(r   c                ó²   a€ \        4       oV3R lpV P                  VR7      w  r#V P                  VP                  4       4      pV P	                  SV4       R# )a  
The C{prepareConnection} return value is ignored when it does not
indicate a failure. Even though the callback participates in the
internal new-connection L{Deferred} chain for error propagation
purposes, any successful result does not affect the ultimate return
value.
c                 ó   <€ S# r!   r   )r¯  Úsentinels   &€r   r§  ÚVClientServiceTests.test_prepareConnectionReturnValueIgnored.<locals>.prepareConnection‚  s   ø€ ØˆOr   r²  N)r¯   r  r°   r%  ÚassertNotIdentical)r%   r§  r  r  r2   rÃ  s   &    @r   Ú(test_prepareConnectionReturnValueIgnoredÚ;ClientServiceTests.test_prepareConnectionReturnValueIgnoredw  sR   ø€ ô “8ˆõ	ð ×*Ñ*Ð=NÐ*ÓO‰ˆà×%Ñ% g×&;Ñ&;Ó&=Ó>ˆØ×Ñ ¨&Ö1r   c                ó   aa€ . o\        4       oVV3R lpV P                  VR7      w  r#VP                  4       pV P                  V4       SP	                  R4       V P                  VP                  ^ ,          V P                  V4      4       R# )zw
The C{prepareConnection} callable returns a deferred and calls to
L{ClientService.whenConnected} wait until it fires.
c                 ó*   <€ SP                  V 4       S# r!   r®  )r¯  ÚnewProtocolDeferredr°  s   &€€r   r§  ÚVClientServiceTests.test_prepareConnectionReturningADeferred.<locals>.prepareConnection’  s   ø€ Ø×Ñ Ô&Ø&Ð&r   r²  N)r
   r  r%  r®   r7   r\   rý   r°   )r%   r§  r  r  ÚwhenConnectedDeferredrÊ  r°  s   &    @@r   Ú(test_prepareConnectionReturningADeferredÚ;ClientServiceTests.test_prepareConnectionReturningADeferredŠ  s…   ù€ ð
 ˆÜ&›jÐö	'ð ×*Ñ*Ð=NÐ*ÓO‰ˆà '× 5Ñ 5Ó 7ÐØ×ÑÐ1Ô2à×$Ñ$ TÔ*à×ÑØ×#Ñ# AÕ&¨×(<Ñ(<Ð=RÓ(Sö	
r   c                ób  € \        4       pR pV P                  W!R7      w  r4VP                  ^R7      pV P                  V4       VP	                  \
        4       V P                  V4       VP	                  \
        4       V P                  \        V P                  V4      P                  4       R# )z[
The connection attempt counts as a failure when the
C{prepareConnection} callable throws.
c                 ó   € \        4       hr!   )ra  )r¥  s   &r   r§  ÚJClientServiceTests.test_prepareConnectionThrows.<locals>.prepareConnection¨  s   € Ü"Ó$Ð$r   r¾  rj  N)
r   r  r%  r®   r;  r<  r\   ra  r.  Útype)r%   r•   r§  r  r  rÌ  s   &     r   Útest_prepareConnectionThrowsÚ/ClientServiceTests.test_prepareConnectionThrows¡  sŸ   € ô
 “ˆò	%ð ×*Ñ*Ø/ð +ó 
‰ˆð !(× 5Ñ 5ÈÐ 5Ó JÐØ×ÑÐ1Ô2à�‰Ô*Ô+Ø×ÑÐ1Ô2à�‰Ô*Ô+Ø×ÑÜ˜d×2Ñ2Ð3HÓI×NÑNö	
r   r   N)(r>   r?   r@   rA   rB   r   r  rž   r  r  r"  r*  r/  r7  r>  rA  rG  rO  rR  r^  rc  rg  rr  r€  rƒ  r‡  r�  r’  r˜  r›  rž  rª  r³  r¹  r¿  rÆ  rÍ  rÓ  rC   rD   rE   s   @r   ró   ró   þ  sË   ø‡ € ñð ØØØôHòT2ò6ò ò:ò +ò8
ò"Jò( ò
 ò
ò02ò"
÷*$+ð $+òL"òMòBò*81òt0ò& ò3ò
ò21ò.1ò0Dò)òJò)ò.)ò.2ò&
÷.
ð 
r   ró   )F)0rB   r½   Úzope.interfacer   Úzope.interface.verifyr   Útwisted.applicationr   Útwisted.application.internetr   r   r   Útwisted.internetr   Útwisted.internet.deferr	   r
   Útwisted.internet.interfacesr   r   r   r   r   Útwisted.internet.protocolr   r   Útwisted.internet.taskr   Útwisted.internet.testingr   Útwisted.loggerr   r   Útwisted.python.failurer   Útwisted.trial.unittestr   r   r   r   r"   rT   r‘   rÍ   rå   rñ   r<  ró   r   r   r   Ú<module>râ     sô   ðñ
ó å &Ý -å (÷ñ õ
 "ß ;÷õ ÷ 8Ý 'Ý 4ß :Ý *ß @ò	ñ Ð"Ó#÷=*ð =*ó $ð=*ñ@ Ð! :Ô .ñ ˆ^Ó÷ð ó ðñ6 Ð! :Ô .ôV1˜8ô V1ôrC-˜ô C-÷L"ñ "ô( &ðF &8ô :ð$ Ð ôz

Ð,ö z

r   