ó
    ×›‘hs ã                   óF  • S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKrSSKJrJrJrJrJr  SSKJr  SS	KJrJr  SS
KJr  SSKJr  SSKJrJr  SSKJ r   SSK!J"r"J#r#  S`S jr$ " S S\RJ                  5      r& " S S\RN                  5      r( " S S5      r) " S S\)\RN                  5      r* " S S\)\RV                  5      r, " S S\#5      r- " S S\#5      r. " S S\R^                  5      r0 " S  S!\,5      r1 " S" S#\#5      r2 " S$ S%\#5      r3 " S& S'\#5      r4 " S( S)\RJ                  5      r5 " S* S+\RJ                  5      r6 " S, S-\RV                  5      r7 " S. S/\#5      r8 " S0 S1\RJ                  5      r9 " S2 S3\RJ                  5      r: " S4 S5\RJ                  5      r; " S6 S7\;5      r< " S8 S95      r= " S: S;\#\=5      r> " S< S=\R~                  5      r@ " S> S?\R‚                  5      rB " S@ SA\#5      rC " SB SC\RJ                  5      rD " SD SE\RJ                  5      rE " SF SG\RV                  5      rF " SH SI\R~                  5      rG " SJ SK\R‚                  5      rH " SL SM\#5      rI\" \5       " SN SO\5      5       rJ " SP SQ\RN                  5      rK " SR SS\#5      rL " ST SU\#5      rM " SV SW\#5      rN " SX SY\#5      rO " SZ S[\#5      rP " S\ S]\#5      rQ SSKRrR\RR¦                  " \RR¨                  5      S   S^-   rU\V" \>S_\U5        g! \W a     gf = f)az.
Tests for implementations of L{IReactorTCP}.
é    N©Úwraps)ÚOptional)ÚskipIf)Úimplementer)ÚdeferÚerrorÚ
interfacesÚprotocolÚreactor)ÚIPv4Address)ÚIHalfCloseableProtocolÚIPullProducer)ÚAccumulatingProtocol)Úpolicies)ÚerrÚmsg)Úplatform)ÚSkipTestÚTestCasec                 óø   ^ ^^• SSK Jn  [        R                  " 5       mUU 4S jnUR	                  U5      mU4S jnTR                  U5        TR                  U5      nUR                  TR                  5        T$ )z˜
Poor excuse for an event notification helper.  This polls a condition and
calls back a Deferred when it is seen to be true.

Do not use this function.
r   )Útaskc                  óF   >• T" 5       n U (       a  TR                  U 5        g g ©N©Úcallback)ÚresÚdÚ	predicates    €€ÚYC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/test/test_tcp.pyÚcheckÚloopUntil.<locals>.check)   s   ø€ Ù‹kˆÞØ�J‰J�s�Oð ó    c                 ó(   >• TR                  5         U $ r   )Ústop)ÚresultÚcalls    €r    r%   ÚloopUntil.<locals>.stop0   s   ø€ Ø�	‰	ŒØˆr#   )	Útwisted.internetr   r   ÚDeferredÚLoopingCallÚaddCallbackÚstartÚ
addErrbackÚerrback)r   Úintervalr   r!   r%   Úd2r'   r   s   `     @@r    Ú	loopUntilr2      sa   ú€ õ &ä�ŠÓ€Aöð
 ×Ñ˜EÓ"€Dõð ‡M�M�$ÔØ	�‰�HÓ	€BØ‡M�M�!—)‘)ÔØ€Hr#   c                   ó    • \ rS rSrS rS rSrg)ÚClosingProtocolé:   c                 óN   • [        S5        U R                  R                  5         g )NzClosingProtocol.connectionMade©r   Ú	transportÚloseConnection©Úselfs    r    ÚconnectionMadeÚClosingProtocol.connectionMade;   s   € ÜÐ,Ô-Ø�‰×%Ñ%Õ'r#   c                 óX   • [        S5        UR                  [        R                  5        g )NzClosingProtocol.connectionLost)r   Útrapr	   ÚConnectionDone©r;   Úreasons     r    ÚconnectionLostÚClosingProtocol.connectionLost?   s   € ÜÐ,Ô-Ø�‰”E×(Ñ(Õ)r#   © N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r<   rC   Ú__static_attributes__rE   r#   r    r4   r4   :   s   † ò(õ*r#   r4   c                   óR   • \ rS rSr% SrSrSr\\R                     \
S'   S rS rSrg)ÚClosingFactoryéD   z'
Factory that closes port immediately.
NÚportc                 óT   • U R                   R                  5       U l        [        5       $ r   )rO   ÚstopListeningÚ_cleanerUpperr4   )r;   Úconns     r    ÚbuildProtocolÚClosingFactory.buildProtocolL   s    € Ø!ŸY™Y×4Ñ4Ó6ˆÔÜÓ Ð r#   c                 óŽ   • U R                   c-  U R                  (       d   eU R                  R                  5       $ U R                   $ )z<
Clean-up for tests to wait for the port to stop listening.
)rR   rO   rQ   r:   s    r    ÚcleanUpÚClosingFactory.cleanUpP   s=   € ð ×ÑÑ%ð —9—9Ð�9Ø—9‘9×*Ñ*Ó,Ð,Ø×!Ñ!Ð!r#   )rR   )rG   rH   rI   rJ   Ú__doc__rR   rO   r   r
   ÚIListeningPortÚ__annotations__rT   rW   rK   rE   r#   r    rM   rM   D   s-   ‡ ñð €MØ04€Dˆ(�:×,Ñ,Ñ
-Ó4ò!õ	"r#   rM   c                   óž   • \ rS rSr% Sr\rSr\\	R                  \      \S'   Sr\\	R                  \      \S'   Sr\\   \S'   SrS rS	 rS
rg)ÚMyProtocolFactoryMixiné\   a¯  
Mixin for factories which create L{AccumulatingProtocol} instances.

@type protocolFactory: no-argument callable
@ivar protocolFactory: Factory for protocols - takes the place of the
    typical C{protocol} attribute of factories (but that name is used by
    this class for something else).

@type protocolConnectionMade: L{None} or L{defer.Deferred}
@ivar protocolConnectionMade: When an instance of L{AccumulatingProtocol}
    is connected, if this is not L{None}, the L{Deferred} will be called
    back with the protocol instance and the attribute set to L{None}.

@type protocolConnectionLost: L{None} or L{defer.Deferred}
@ivar protocolConnectionLost: When an instance of L{AccumulatingProtocol}
    is created, this will be set as its C{closedDeferred} attribute and
    then this attribute will be set to L{None} so the L{defer.Deferred} is
    not used by more than one protocol.

@ivar protocol: The most recently created L{AccumulatingProtocol} instance
    which was returned from C{buildProtocol}.

@type called: C{int}
@ivar called: A counter which is incremented each time C{buildProtocol}
    is called.

@ivar peerAddresses: A C{list} of the addresses passed to C{buildProtocol}.
NÚprotocolConnectionMadeÚprotocolConnectionLostÚlastProtocolr   c                 ó   • / U l         g r   )ÚpeerAddressesr:   s    r    Ú__init__ÚMyProtocolFactoryMixin.__init__�   s
   € ØˆÕr#   c                 óÎ   • U R                   R                  U5        U =R                  S-  sl        U R                  5       nXl        U R
                  Ul        SU l        X l        U$ )zQ
Create a L{AccumulatingProtocol} and set it up to be able to perform
callbacks.
é   N)rc   ÚappendÚcalledÚprotocolFactoryÚfactoryr`   ÚclosedDeferredra   ©r;   ÚaddrÚps      r    rT   Ú$MyProtocolFactoryMixin.buildProtocol„   sZ   € ð
 	×Ñ×!Ñ! $Ô'Ø�Š�qÑ�Ø× Ñ Ó"ˆØŒ	Ø×6Ñ6ˆÔØ&*ˆÔ#ØÔØˆr#   )ra   rc   r`   )rG   rH   rI   rJ   rY   r   rj   r_   r   r   r*   r[   r`   ra   ri   rd   rT   rK   rE   r#   r    r]   r]   \   sa   ‡ ñð: +€OàMQÐ˜H U§^¡^Ð4HÑ%IÑJÓQØMQÐ˜H U§^¡^Ð4HÑ%IÑJÓQØ37€L�(Ð/Ñ0Ó7Ø€Fò õr#   r]   c                   ó   • \ rS rSrSrSrg)ÚMyServerFactoryé“   zA
Server factory which creates L{AccumulatingProtocol} instances.
rE   N)rG   rH   rI   rJ   rY   rK   rE   r#   r    rr   rr   “   s   † ôr#   rr   c                   ó‚   • \ rS rSr% SrSrSr\R                  S   \	S'   \R                  S   \	S'   S r
S rS	 rS
 rSrg)ÚMyClientFactoryé™   zA
Client factory which creates L{AccumulatingProtocol} instances.
r   NÚdeferredÚfailDeferredc                 ó–   • [         R                  U 5        [        R                  " 5       U l        [        R                  " 5       U l        g r   )r]   rd   r   r*   rw   rx   r:   s    r    rd   ÚMyClientFactory.__init__£   s-   € Ü×'Ñ'¨Ô-ÜŸšÓ(ˆŒÜ!ŸNšNÓ,ˆÕr#   c                 óT   • SU l         X l        U R                  R                  S 5        g ©Nrg   )ÚfailedrB   rx   r   ©r;   Ú	connectorrB   s      r    ÚclientConnectionFailedÚ&MyClientFactory.clientConnectionFailed¨   s"   € ØˆŒØŒØ×Ñ×"Ñ" 4Õ(r#   c                 óF   • X l         U R                  R                  S 5        g r   )Ú
lostReasonrw   r   r~   s      r    ÚclientConnectionLostÚ$MyClientFactory.clientConnectionLost­   s   € Ø ŒØ�‰×Ñ˜tÕ$r#   c                 ó   • SU l         g r|   ©Ústoppedr:   s    r    ÚstopFactoryÚMyClientFactory.stopFactory±   s	   € Øˆ�r#   )rw   rx   r}   rƒ   rB   rˆ   )rG   rH   rI   rJ   rY   r}   rˆ   r   r*   r[   rd   r€   r„   r‰   rK   rE   r#   r    ru   ru   ™   sE   ‡ ñð €FØ€GØ�n‰n˜TÑ"Ó"Ø—.‘. Ñ&Ó&ò-ò
)ò
%õr#   ru   c                   óP   • \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rSrg)ÚListeningTestséµ   c                 óÖ   • [        5       n[        R                  " SUSS9nU R                  UR                  5        U R                  [        R                  R                  U5      5        g)zN
L{IReactorTCP.listenTCP} returns an object which provides
L{IListeningPort}.
r   ú	127.0.0.1©Ú	interfaceN)	rr   r   Ú	listenTCPÚ
addCleanuprQ   Ú
assertTruer
   rZ   Ú
providedBy©r;   ÚfÚp1s      r    Útest_listenÚListeningTests.test_listen¶   sO   € ô
 ÓˆÜ×Ò˜q !¨{Ñ;ˆØ�‰˜×(Ñ(Ô)Ø�‰œ
×1Ñ1×<Ñ<¸RÓ@ÕAr#   c                 óî   ^^• [        5       m[        R                  " STSS9nUR                  5       R                  mUU4S jn[
        R                  " UR                  5      nUR                  U5        U$ )zà
The L{IListeningPort} returned by L{IReactorTCP.listenTCP} can be
stopped with its C{stopListening} method.  After the L{Deferred} it
(optionally) returns has been called back, the port number can be bound
to a new server.
r   r�   r�   c                 óP   >• [         R                  " TTSS9nUR                  5       $ )Nr�   r�   )r   r’   rQ   )ÚignoredrO   r—   Úns     €€r    ÚcbStopListeningÚ9ListeningTests.testStopListening.<locals>.cbStopListeningË   s&   ø€ ä×$Ò$ Q¨°[ÑAˆDØ×%Ñ%Ó'Ð'r#   )	rr   r   r’   ÚgetHostrO   r   ÚmaybeDeferredrQ   r,   )r;   rO   rŸ   r   r—   rž   s       @@r    ÚtestStopListeningÚ ListeningTests.testStopListeningÀ   s`   ù€ ô ÓˆÜ× Ò   A°Ñ=ˆØ�L‰L‹N×Ñˆö	(ô
 ×Ò × 2Ñ 2Ó3ˆØ	�‰�oÔ&Øˆr#   c                 ób   • [        5       n[        R                  " SUSS9nUR                  5       $ ©Nr   r�   r�   )rr   r   r’   rQ   r–   s      r    ÚtestNumberedInterfaceÚ$ListeningTests.testNumberedInterfaceÔ   s-   € ÜÓˆä×Ò˜q !¨{Ñ;ˆØ×ÑÓ!Ð!r#   c                 óZ  ^ ^^• [        5       n[        R                  " SU5      m[        TR	                  5       R
                  5      mT R                  [        T5      R                  T5      S:H  5        UUU 4S jn[        R                  " TR                  5      nUR                  U5      $ )Nr   éÿÿÿÿc                 ó^   >• TR                  [        T5      R                  T5      S:g  5        g )Nrª   )ÚassertFalseÚreprÚfind)Úignro   ÚportNor;   s    €€€r    ÚstoppedListeningÚ5ListeningTests.testPortRepr.<locals>.stoppedListeningà   s#   ø€ Ø×ÑœT !›WŸ\™\¨&Ó1°RÑ7Õ8r#   )rr   r   r’   Ústrr¡   rO   r¬   r­   r®   r   r¢   rQ   r,   )r;   r—   r±   r   ro   r°   s   `   @@r    ÚtestPortReprÚListeningTests.testPortReprÚ   s~   ú€ ÜÓˆÜ×Ò˜a Ó#ˆÜ�Q—Y‘Y“[×%Ñ%Ó&ˆØ×Ñœ˜a›Ÿ™ fÓ-°Ñ3Ô4÷	9ô ×Ò §¡Ó0ˆØ�}‰}Ð-Ó.Ð.r#   c                 óî  ^ ^• [        5       n[        R                  " 5       =o!l        [        R
                  " SU5      mT R                  TR                  5        [        5       n[        R                  " 5       =oCl        [        R                  " STR                  5       R                  U5      nT R                  UR                  5        UU 4S jn[        R                  " X$/5      R                  U5      $ )zi
Check that the repr string of the server transport get the good port
number if the server listens on 0.
r   r�   c                 óü   >• U u  pTR                  5       R                  nTR                  [        UR                  5      SU S35        UR                  R                  5         UR                  R                  5         g )Nz<AccumulatingProtocol #0 on Ú>)r¡   rO   ÚassertEqualr­   r8   r9   )r&   ÚserverProtoÚclientProtoÚ
portNumberrO   r;   s       €€r    r!   Ú-ListeningTests.test_serverRepr.<locals>.checkõ   sj   ø€ Ø'-Ñ$ˆKØŸ™›×,Ñ,ˆJØ×ÑÜ�[×*Ñ*Ó+Ø.¨z¨l¸!Ð<ôð ×!Ñ!×0Ñ0Ô2Ø×!Ñ!×0Ñ0Õ2r#   )rr   r   r*   r_   r   r’   r“   rQ   ru   Ú
connectTCPr¡   rO   Ú
disconnectÚgatherResultsr,   )r;   ÚserverÚserverConnMadeÚclientÚclientConnMader   r!   rO   s   `      @r    Útest_serverReprÚListeningTests.test_serverRepræ   s¶   ù€ ô
 !Ó"ˆÜ9>¿ºÓ9IÐIˆÔ6Ü× Ò   FÓ+ˆØ�‰˜×*Ñ*Ô+ä Ó"ˆÜ9>¿ºÓ9IÐIˆÔ6Ü×&Ò& {°D·L±L³N×4GÑ4GÈÓPˆ	Ø�‰˜	×,Ñ,Ô-ö	3ô ×"Ò" NÐ#CÓD×PÑPÐQVÓWÐWr#   c                 óþ   ^ ^^^• [        5       m[        R                  " STSS9mT R                  TR                  5        UUU U4S jnS m[
        R                  " TR                  5      nUR                  U5        U$ )zv
Stop and then try to restart a L{tcp.Port}: after a restart, the
server should be able to handle client connections.
r   r�   r�   c                 ó¬  >• TR                  5         [        5       n[        R                  " 5       Tl        [        R                  " 5       Ul        [
        R                  " STR                  5       R                  U5      nTR                  UR                  5        [        R                  " TR                  UR                  /5      R                  T5      $ ©Nr�   )ÚstartListeningru   r   r*   r_   r   r¾   r¡   rO   r“   r¿   rÀ   r,   ©r�   rÃ   r   ÚcloserO   r;   ÚserverFactorys      €€€€r    rŸ   Ú=ListeningTests.test_restartListening.<locals>.cbStopListening
  s˜   ø€ Ø×ÑÔ!ä$Ó&ˆFÜ38·>²>Ó3CˆMÔ0Ü,1¯NªNÓ,<ˆFÔ)Ü×*Ò*¨;¸¿¹»×8KÑ8KÈVÓTˆIØ�O‰O˜I×0Ñ0Ô1Ü×&Ò&Ø×5Ñ5°v×7TÑ7TÐUóç‰k˜%Ó ð!r#   c                 ót   • U u  pUR                   R                  5         UR                   R                  5         g r   ©r8   r9   ©r&   rº   r»   s      r    rÌ   Ú3ListeningTests.test_restartListening.<locals>.close  ó.   € Ø'-Ñ$ˆKØ×!Ñ!×0Ñ0Ô2Ø×!Ñ!×0Ñ0Õ2r#   )rr   r   r’   r“   rQ   r   r¢   r,   )r;   rŸ   r   rÌ   rO   rÍ   s   `  @@@r    Útest_restartListeningÚ$ListeningTests.test_restartListening  sk   û€ ô
 (Ó)ˆÜ× Ò   M¸[ÑIˆØ�‰˜×*Ñ*Ô+÷
	!ð 
	!ò	3ô
 ×Ò × 2Ñ 2Ó3ˆØ	�‰�oÔ&Øˆr#   c                 óœ   • [        5       nS nX!l        [        R                  " SUSS9nU R	                  UR                  5       [        5      $ )z›
If the server factory raises an exception in C{stopFactory}, the
deferred returned by L{tcp.Port.stopListening} should fail with the
corresponding error.
c                  ó   • [        S5      e©NzAn error©ÚRuntimeErrorrE   r#   r    ÚraiseExceptionÚ8ListeningTests.test_exceptInStop.<locals>.raiseException'  ó   € Ü˜zÓ*Ð*r#   r   r�   r�   )rr   r‰   r   r’   ÚassertFailurerQ   rÚ   ©r;   rÍ   rÛ   rO   s       r    Útest_exceptInStopÚ ListeningTests.test_exceptInStop  sI   € ô (Ó)ˆò	+ð %3Ô!Ü× Ò   M¸[ÑIˆà×!Ñ! $×"4Ñ"4Ó"6¼ÓEÐEr#   c                 ó  ^ ^^^• [        5       mS nUTl        [        R                  " STSS9mT R	                  TR
                  5        UUU U4S jnS mT R                  TR                  5       [        5      R                  U5      $ )z™
Even if the server factory raise an exception in C{stopFactory}, the
corresponding C{tcp.Port} instance should be in a sane state and can
be restarted.
c                  ó   • [        S5      erØ   rÙ   rE   r#   r    rÛ   Ú>ListeningTests.test_restartAfterExcept.<locals>.raiseException7  rÝ   r#   r   r�   r�   c                 ó°  >• T? TR                  5         [        5       n[        R                  " 5       Tl        [        R                  " 5       Ul        [        R                  " STR                  5       R                  U5      nTR                  UR                  5        [        R                  " TR
                  UR
                  /5      R                  T5      $ rÉ   )r‰   rÊ   ru   r   r*   r_   r   r¾   r¡   rO   r“   r¿   rÀ   r,   rË   s      €€€€r    rŸ   Ú?ListeningTests.test_restartAfterExcept.<locals>.cbStopListening>  sž   ø€ ØÐ)Ø×ÑÔ!ä$Ó&ˆFÜ38·>²>Ó3CˆMÔ0Ü,1¯NªNÓ,<ˆFÔ)Ü×*Ò*¨;¸¿¹»×8KÑ8KÈVÓTˆIØ�O‰O˜I×0Ñ0Ô1Ü×&Ò&Ø×5Ñ5°v×7TÑ7TÐUóç‰k˜%Ó ð!r#   c                 ót   • U u  pUR                   R                  5         UR                   R                  5         g r   rÐ   rÑ   s      r    rÌ   Ú5ListeningTests.test_restartAfterExcept.<locals>.closeK  rÓ   r#   )	rr   r‰   r   r’   r“   rQ   rÞ   rÚ   r,   )r;   rÛ   rŸ   rÌ   rO   rÍ   s   `  @@@r    Útest_restartAfterExceptÚ&ListeningTests.test_restartAfterExcept/  s   û€ ô (Ó)ˆò	+ð %3ˆÔ!Ü× Ò   M¸[ÑIˆØ�‰˜×*Ñ*Ô+÷	!ð 	!ò	3ð
 ×!Ñ! $×"4Ñ"4Ó"6¼ÓE×QÑQØó
ð 	
r#   c                 óˆ  ^• [        5       n[        R                  " SUSS9nUR                  5       R                  nUR                  S5        [        5       m[        R                  " 5       Ul	        [        R                  " 5       Tl	        [        R                  " SUT5        U4S jnTR                  R                  U5      $ )zË
If C{connectionLost} is called directly on a port object, it succeeds
(and doesn't expect the presence of a C{deferred} attribute).

C{connectionLost} is called by L{reactor.disconnectAll} at shutdown.
r   r�   r�   Nc                 óX   >• TR                   R                  [        R                  5        g r   ©rB   r?   r	   ÚConnectionRefusedError)r¯   rÃ   s    €r    r!   Ú;ListeningTests.test_directConnectionLostCall.<locals>.checke  s   ø€ Ø�M‰M×Ñœu×;Ñ;Õ<r#   )rr   r   r’   r¡   rO   rC   ru   r   r*   r_   r¾   rx   r,   )r;   rÍ   rO   r¼   r!   rÃ   s        @r    Útest_directConnectionLostCallÚ,ListeningTests.test_directConnectionLostCallT  s–   ø€ ô (Ó)ˆÜ× Ò   M¸[ÑIˆØ—\‘\“^×(Ñ(ˆ
Ø×Ñ˜DÔ!ä Ó"ˆÜ/4¯~ª~Ó/?ˆÔ,Ü(-¯ªÓ(8ˆÔ%Ü×Ò˜;¨
°FÔ;õ	=ð ×"Ñ"×.Ñ.¨uÓ5Ð5r#   c                 ó˜   • [        5       nS nX!l        [        R                  " SUSS9nU R	                  [
        UR                  S5        g)zó
If C{connectionLost} is called directory on a port object and that the
server factory raises an exception in C{stopFactory}, the exception is
passed through to the caller.

C{connectionLost} is called by L{reactor.disconnectAll} at shutdown.
c                  ó   • [        S5      erØ   rÙ   rE   r#   r    rÛ   ÚFListeningTests.test_exceptInConnectionLostCall.<locals>.raiseExceptiont  rÝ   r#   r   r�   r�   N)rr   r‰   r   r’   ÚassertRaisesrÚ   rC   rß   s       r    Útest_exceptInConnectionLostCallÚ.ListeningTests.test_exceptInConnectionLostCallj  sE   € ô (Ó)ˆò	+ð %3Ô!Ü× Ò   M¸[ÑIˆØ×Ñœ,¨×(;Ñ(;¸TÕBr#   rE   N)rG   rH   rI   rJ   r™   r£   r§   r´   rÅ   rÔ   rà   ré   rð   rö   rK   rE   r#   r    rŒ   rŒ   µ   s9   † òBòò("ò
/òXò6ò<Fò #
òJ6õ,Cr#   rŒ   c                   óN   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rSrg)ÚLoopbackTestsi|  z
Test loopback connections.
c                 óJ  ^ ^^• [        5       n[        R                  " SUSS9mTUl        T R	                  UR
                  5        TR                  5       R                  n[        5       m[        R                  " SUT5        UUU 4S jnTR                  R                  U5      $ )zb
A port created with L{IReactorTCP.listenTCP} can be connected to with
L{IReactorTCP.connectTCP}.
r   r�   r�   c                 óØ   >• TR                  TR                  R                  5        TR                  TR                  5        TR                  R                  [        R                  5        g r   )r”   ra   ÚmadeÚdisconnectedrƒ   r?   r	   r@   )ÚxÚclientFrO   r;   s    €€€r    r!   Ú<LoopbackTests.test_closePortInProtocolFactory.<locals>.checkŽ  sG   ø€ Ø�O‰O˜G×0Ñ0×5Ñ5Ô6Ø�O‰O˜D×-Ñ-Ô.Ø×Ñ×#Ñ#¤E×$8Ñ$8Õ9r#   )rM   r   r’   rO   r“   rW   r¡   ru   r¾   rw   r,   )r;   r—   r¼   r!   rÿ   rO   s   `   @@r    Útest_closePortInProtocolFactoryÚ-LoopbackTests.test_closePortInProtocolFactory�  s�   ú€ ô
 ÓˆÜ× Ò   A°Ñ=ˆØˆŒØ�‰˜Ÿ	™	Ô"Ø—\‘\“^×(Ñ(ˆ
Ü!Ó#ˆÜ×Ò˜;¨
°GÔ<÷	:ð
 ×Ñ×+Ñ+¨EÓ2Ð2r#   c                 óH   • [        USS 5      " [        R                  5        g )Nr?   c                 ó   • g r   rE   )rþ   s    r    Ú<lambda>Ú,LoopbackTests._trapCnxDone.<locals>.<lambda>–  s   €  tr#   )Úgetattrr	   r@   )r;   Úobjs     r    Ú_trapCnxDoneÚLoopbackTests._trapCnxDone•  s   € Ü��V™^Ô,¬U×-AÑ-AÕBr#   c                 ó¼  ^• [        5       n[        R                  " 5       nX2l        [        R
                  " SUSS9nU R                  UR                  5        UR                  5       R                  n[        5       n[        R                  " 5       nXvl        [        R                  " SXV5        [        R                  " X7/5      nU4S jn	UR                  U	5        U$ )zq
Invoke the given callback with a client protocol and a server protocol
which have been connected to each other.
r   r�   r�   c                 ó†   >• U u  pT" X5        UR                   R                  5         UR                   R                  5         g r   rÐ   )r&   ÚserverProtocolÚclientProtocolr   s      €r    Ú	connectedÚ>LoopbackTests._connectedClientAndServerTest.<locals>.connected«  s7   ø€ Ø-3Ñ*ˆNÙ�^Ô4Ø×$Ñ$×3Ñ3Ô5Ø×$Ñ$×3Ñ3Õ5r#   )rr   r   r*   r_   r   r’   r“   rQ   r¡   rO   ru   r¾   rÀ   r,   )
r;   r   rÍ   rÂ   rO   r¼   rÿ   rÄ   Ú	connsMader  s
    `        r    Ú_connectedClientAndServerTestÚ+LoopbackTests._connectedClientAndServerTest˜  s®   ø€ ô
 (Ó)ˆÜŸšÓ)ˆØ/=Ô,Ü× Ò   M¸[ÑIˆØ�‰˜×*Ñ*Ô+à—\‘\“^×(Ñ(ˆ
Ü!Ó#ˆÜŸšÓ)ˆØ)7Ô&Ü×Ò˜;¨
Ô<ä×'Ò'¨Ð(HÓIˆ	õ	6ð 	×Ñ˜iÔ(ØÐr#   c                 ó2   ^ • U 4S jnT R                  U5      $ )zç
The transport of a protocol connected with L{IReactorTCP.connectTCP} or
L{IReactor.TCP.listenTCP} can have its I{TCP_NODELAY} state inspected
and manipulated with L{ITCPTransport.getTcpNoDelay} and
L{ITCPTransport.setTcpNoDelay}.
c                 ó6  >• X4 H‘  nUR                   nTR                  UR                  5       S5        UR                  S5        TR                  UR                  5       S5        UR                  S5        TR                  UR                  5       S5        M“     g ©Nr   rg   )r8   r¹   ÚgetTcpNoDelayÚsetTcpNoDelay©r  r  ro   r8   r;   s       €r    r!   Ú,LoopbackTests.test_tcpNoDelay.<locals>.check¼  s€   ø€ Ø$Ó5�ØŸK™K�	Ø× Ñ  ×!8Ñ!8Ó!:¸AÔ>Ø×'Ñ'¨Ô*Ø× Ñ  ×!8Ñ!8Ó!:¸AÔ>Ø×'Ñ'¨Ô*Ø× Ñ  ×!8Ñ!8Ó!:¸AÖ>ò 6r#   ©r  ©r;   r!   s   ` r    Útest_tcpNoDelayÚLoopbackTests.test_tcpNoDelay´  s   ø€ õ	?ð ×1Ñ1°%Ó8Ð8r#   c                 ó2   ^ • U 4S jnT R                  U5      $ )zì
The transport of a protocol connected with L{IReactorTCP.connectTCP} or
L{IReactor.TCP.listenTCP} can have its I{SO_KEEPALIVE} state inspected
and manipulated with L{ITCPTransport.getTcpKeepAlive} and
L{ITCPTransport.setTcpKeepAlive}.
c                 ó6  >• X4 H‘  nUR                   nTR                  UR                  5       S5        UR                  S5        TR                  UR                  5       S5        UR                  S5        TR                  UR                  5       S5        M“     g r  )r8   r¹   ÚgetTcpKeepAliveÚsetTcpKeepAliver  s       €r    r!   Ú.LoopbackTests.test_tcpKeepAlive.<locals>.checkÏ  s€   ø€ Ø$Ó5�ØŸK™K�	Ø× Ñ  ×!:Ñ!:Ó!<¸aÔ@Ø×)Ñ)¨!Ô,Ø× Ñ  ×!:Ñ!:Ó!<¸aÔ@Ø×)Ñ)¨!Ô,Ø× Ñ  ×!:Ñ!:Ó!<¸aÖ@ò 6r#   r  r  s   ` r    Útest_tcpKeepAliveÚLoopbackTests.test_tcpKeepAliveÇ  s   ø€ õ	Að ×1Ñ1°%Ó8Ð8r#   c                 óˆ   ^• [        5       m[        R                  " SSTSS9  U4S jnTR                  R	                  U5      $ )Nr�   éE   é   )Útimeoutc                 óX   >• TR                   R                  [        R                  5        g r   rí   )r�   rÿ   s    €r    r!   Ú(LoopbackTests.testFailing.<locals>.checkß  s   ø€ Ø�N‰N×Ñ¤× <Ñ <Õ=r#   )ru   r   r¾   rx   r,   )r;   r!   rÿ   s     @r    ÚtestFailingÚLoopbackTests.testFailingÚ  s=   ø€ Ü!Ó#ˆä×Ò˜;¨¨G¸QÒ?õ	>ð ×#Ñ#×/Ñ/°Ó6Ð6r#   c                 ó   ^ ^^^• / m[        S5       HK  n[        R                  " 5       nUR                  S5        UR                  S5        TR	                  U5        MM     [
        R                  " T5        [        R                  " [        [        R                  5      mUU UU4S jmT" 5       nT R                  U[        R                  5        U 4S jnUR                  U5        U4S jnUR                  U5        U$ )zv
Assert that the error number of the ConnectionRefusedError is
ECONNREFUSED, and not some other socket related error.
é
   ©r�   r   rg   c                  óÀ   >• UUU4S jn TR                  5       nUR                  5       u  p#UR                  5         TR                  X#5      nUR	                  U 5        U$ )Nc                 óx   >• U R                   R                  5         T(       a  T" 5       $ TR                  S5        g)z<
Darn.  Kill it and try again, if there are any tries left.
z?Could not fail to connect - could not test errno for that case.N)r8   r9   Úfail)Úprotor;   ÚserverSocketsÚtryConnectFailures    €€€r    r  Ú]LoopbackTests.test_connectionRefusedErrorNumber.<locals>.tryConnectFailure.<locals>.connected  s0   ø€ ð —‘×.Ñ.Ô0Þ Ù,Ó.Ð.Ø—	‘	ØUõr#   )ÚpopÚgetsocknamerÌ   r¾   r,   )	r  ÚserverSocketÚ
serverHostÚ
serverPortÚconnectDeferredÚclientCreatorr;   r5  r6  s	        €€€€r    r6  ÚJLoopbackTests.test_connectionRefusedErrorNumber.<locals>.tryConnectFailure  sY   ø€ ÷	ð )×,Ñ,Ó.ˆLØ%1×%=Ñ%=Ó%?Ñ"ˆJØ×ÑÔ à+×6Ñ6°zÓNˆOØ×'Ñ'¨	Ô2Ø"Ð"r#   c                 óZ   >• TR                  U R                  [        R                  5        g r   )r¹   ÚosErrorÚerrnoÚECONNREFUSED)Úexcr;   s    €r    ÚconnRefusedÚDLoopbackTests.test_connectionRefusedErrorNumber.<locals>.connRefused  s   ø€ Ø×Ñ˜SŸ[™[¬%×*<Ñ*<Õ=r#   c                 ód   >• T(       a'  TR                  5       R                  5         T(       a  M'  U $ r   )r8  rÌ   )Úpassthroughr5  s    €r    ÚcleanupÚ@LoopbackTests.test_connectionRefusedErrorNumber.<locals>.cleanup#  s(   ø€ ÞØ×!Ñ!Ó#×)Ñ)Ô+÷  �-àÐr#   )ÚrangeÚsocketÚbindÚlistenrh   ÚrandomÚshuffler   ÚClientCreatorr   ÚProtocolrÞ   r	   rî   r,   ÚaddBoth)	r;   Úir:  ÚrefusedDeferredrE  rI  r>  r5  r6  s	   `     @@@r    Ú!test_connectionRefusedErrorNumberÚ/LoopbackTests.test_connectionRefusedErrorNumberä  sÎ   û€ ð2 ˆÜ�r–ˆAÜ!Ÿ=š=›?ˆLØ×ÑÐ.Ô/Ø×Ñ Ô"Ø× Ñ  Ö.ñ	 ô
 	�Š�}Ô%ä ×.Ò.¬w¼×8IÑ8IÓJˆ÷	#ð 	#ñ( ,Ó-ˆØ×Ñ˜?¬E×,HÑ,HÔIõ	>ð 	×#Ñ# KÔ0õ	ð
 	×Ñ Ô(ØÐr#   c                 óv   • U R                  [        R                  [        R                  SS[        5       5        g)z]
Connecting to a named service which does not exist raises
L{error.ServiceNameUnknownError}.
r�   ÚthisbetternotexistN)rõ   r	   ÚServiceNameUnknownErrorr   r¾   ru   r:   s    r    Útest_connectByServiceFailÚ'LoopbackTests.test_connectByServiceFail+  s0   € ð
 	×ÑÜ×)Ñ)Ü×ÑØØ ÜÓõ	
r#   c                 ó   ^ ^^	• [        5       m	[        R                  " 5       nUT	l        [        R
                  " ST	SS9nT R                  UR                  5        UR                  5       R                  m[        5       n[        R                  " 5       nXCl        U4S jnT R                  [        SU5        [        R                  " SSU5        [        R                  " X/5      nU U	4S jnUR                  U5        U$ )z·
L{IReactorTCP.connectTCP} accepts the name of a service instead of a
port number and connects to the port number associated with that
service, as defined by L{socket.getservbyname}.
r   r�   r�   c                 ó"   >• U S:X  a  US:X  a  T$ g)NÚhttpÚtcpr/  rE   )ÚserviceNameÚprotocolNamer¼   s     €r    ÚfakeGetServicePortByNameÚELoopbackTests.test_connectByService.<locals>.fakeGetServicePortByNameH  s   ø€ Ø˜fÓ$¨¸Ó)>Ø!Ð!Ør#   Úgetservbynamer_  c                 ó®   >• U u  pTR                  TR                  S5        UR                  R                  5         UR                  R                  5         g )Nz7Server factory was not called upon to build a protocol.)r”   ri   r8   r9   )r&   r  r  r;   rÍ   s      €€r    r  Ú6LoopbackTests.test_connectByService.<locals>.connectedS  sI   ø€ Ø-3Ñ*ˆNØ�O‰OØ×$Ñ$ØIôð ×$Ñ$×3Ñ3Ô5Ø×$Ñ$×3Ñ3Õ5r#   )rr   r   r*   r_   r   r’   r“   rQ   r¡   rO   ru   ÚpatchrL  r¾   rÀ   r,   )
r;   rÂ   rO   ÚclientFactoryrÄ   rc  ÚconnMader  r¼   rÍ   s
   `       @@r    Útest_connectByServiceÚ#LoopbackTests.test_connectByService8  sÉ   ú€ ô (Ó)ˆÜŸšÓ)ˆØ/=ˆÔ,Ü× Ò   M¸[ÑIˆØ�‰˜×*Ñ*Ô+Ø—\‘\“^×(Ñ(ˆ
Ü'Ó)ˆÜŸšÓ)ˆØ/=Ô,õ	ð
 	�
‰
”6˜?Ð,DÔEä×Ò˜;¨°Ô>ä×&Ò&¨Ð'GÓHˆö	6ð 	×Ñ˜YÔ'Øˆr#   rE   N)rG   rH   rI   rJ   rY   r  r	  r  r  r$  r,  rV  r[  rk  rK   rE   r#   r    rù   rù   |  s7   † ñò3ò(Còò89ò&9ò&7òEòN
õ%r#   rù   c                   ó(   • \ rS rSrSrSrS rS rSrg)ÚStartStopFactoryi`  r   c                 ób   • U R                   (       d  U R                  (       a  [        eSU l         g r|   ©Ústartedrˆ   rÚ   r:   s    r    ÚstartFactoryÚStartStopFactory.startFactoryd  ó   € Ø�<�<˜4Ÿ<Ÿ<ÜÐØˆ�r#   c                 ób   • U R                   (       a  U R                  (       a  [        eSU l        g r|   rp  r:   s    r    r‰   ÚStartStopFactory.stopFactoryi  s   € Ø�|�|˜tŸ|Ÿ|ÜÐØˆ�r#   )rq  rˆ   N)	rG   rH   rI   rJ   rq  rˆ   rr  r‰   rK   rE   r#   r    rn  rn  `  s   † Ø€GØ€Gòõ
r#   rn  c                   ó.   • \ rS rSrSrSrS rS rS rSr	g)ÚClientStartStopFactoryio  r   c                 ól   • [         R                  " U /UQ70 UD6  [        R                  " 5       U l        g r   )ru   rd   r   r*   ÚwhenStopped)r;   ÚaÚkws      r    rd   ÚClientStartStopFactory.__init__s  s)   € Ü× Ò  Ð0¨Ò0¨RÒ0Ü Ÿ>š>Ó+ˆÕr#   c                 ób   • U R                   (       d  U R                  (       a  [        eSU l         g r|   rp  r:   s    r    rr  Ú#ClientStartStopFactory.startFactoryw  rt  r#   c                 ó˜   • U R                   (       a  U R                  (       a  [        eSU l        U R                  R	                  S5        g )Nrg   T)rq  rˆ   rÚ   rz  r   r:   s    r    r‰   Ú"ClientStartStopFactory.stopFactory|  s0   € Ø�|�|˜tŸ|Ÿ|ÜÐØˆŒØ×Ñ×!Ñ! $Õ'r#   )rq  rˆ   rz  N)
rG   rH   rI   rJ   rq  rˆ   rd   rr  r‰   rK   rE   r#   r    rx  rx  o  s   † Ø€GØ€Gò,òõ
(r#   rx  c                   ó$   • \ rS rSrSrS rS rSrg)ÚFactoryTestsiƒ  zTests for factories.c                 óŠ  ^ ^^	• [        5       m[        R                  " STSS9nT R                  UR                  5        T R                  TR                  TR                  4S5        [        R                  " STSS9n[        R                  " STSS9m	T R                  TR                  TR                  4S5        [        R                  " UR                  5      n[        R                  " UR                  5      n[        R                  " X4/5      nUU	U 4S jnUR                  U5        UU 4S jnUR                  U5        U$ )z÷
The factory passed to L{IReactorTCP.listenTCP} should be started only
when it transitions from being used on no ports to being used on one
port and should be stopped only when it transitions from being used on
one port to being used on no ports.
r   r�   r�   ©rg   r   c                 ót   >• TR                  TR                  TR                  4S5        TR                  5       $ )Nr…  )r¹   rq  rˆ   rQ   )r�   r—   Úp3r;   s    €€€r    ÚcbClosedÚ3FactoryTests.test_serverStartStop.<locals>.cbClosed¦  s/   ø€ Ø×Ñ˜aŸi™i¨¯©Ð3°VÔ<à×#Ñ#Ó%Ð%r#   c                 óV   >• TR                  TR                  TR                  4S5        g )N)rg   rg   )r¹   rq  rˆ   )r�   r—   r;   s    €€r    ÚcbClosedAllÚ6FactoryTests.test_serverStartStop.<locals>.cbClosedAll­  s    ø€ Ø×Ñ˜aŸi™i¨¯©Ð3°VÕ<r#   )rn  r   r’   r“   rQ   r¹   rq  rˆ   r   r¢   rÀ   r,   )
r;   r˜   Úp2Úd1r1   rl   rˆ  r‹  r—   r‡  s
   `       @@r    Útest_serverStartStopÚ!FactoryTests.test_serverStartStop†  s	  ú€ ô Óˆô ×Ò˜q !¨{Ñ;ˆØ�‰˜×(Ñ(Ô)à×Ñ˜!Ÿ)™) Q§Y¡YÐ/°Ô8ô ×Ò˜q !¨{Ñ;ˆÜ×Ò˜q !¨{Ñ;ˆà×Ñ˜!Ÿ)™) Q§Y¡YÐ/°Ô8ô × Ò  ×!1Ñ!1Ó2ˆÜ× Ò  ×!1Ñ!1Ó2ˆÜ×,Ò,¨b¨XÓ6ˆ÷	&ð
 	×"Ñ" 8Ô,ö	=ð 	×"Ñ" ;Ô/ØÐr#   c                 óR  ^• [        5       n[        R                  " SUSS9nX!l        U R	                  UR
                  5        UR                  5       R                  n[        5       m[        R                  " SUT5        U R                  TR                  5        [        U4S j5      $ )zƒ
The factory passed to L{IReactorTCP.connectTCP} should be started when
the connection attempt starts and stopped when it is over.
r   r�   r�   c                  ó   >• T R                   $ r   r‡   )rk   s   €r    r  Ú3FactoryTests.test_clientStartStop.<locals>.<lambda>Á  s	   ø€  §¢r#   )rM   r   r’   rO   r“   rW   r¡   rx  r¾   r”   rq  r2   )r;   r—   ro   r¼   rk   s       @r    Útest_clientStartStopÚ!FactoryTests.test_clientStartStop³  s}   ø€ ô
 ÓˆÜ×Ò˜a ¨kÑ:ˆØŒØ�‰˜Ÿ	™	Ô"Ø—Y‘Y“[×%Ñ%ˆ
ä(Ó*ˆÜ×Ò˜;¨
°GÔ<Ø�‰˜Ÿ™Ô(ÜÔ0Ó1Ð1r#   rE   N)rG   rH   rI   rJ   rY   r�  r”  rK   rE   r#   r    rƒ  rƒ  ƒ  s   † Ùò+õZ2r#   rƒ  c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚCannotBindTestsiÄ  zQ
Tests for correct behavior when a reactor cannot bind to the required TCP
port.
c                 óÒ  • [        5       n[        R                  " SUSS9nU R                  UR                  5        UR                  5       R                  nUR                  5       nU R                  UR                  S5        U R                  UR                  S5        U R                  UR                  U5        U R                  [        R                  [        R                  X1SS9  g)zk
L{IReactorTCP.listenTCP} raises L{error.CannotListenError} if the
address to listen on is already in use.
r   r�   r�   ÚTCPN)rr   r   r’   r“   rQ   r¡   rO   r¹   ÚtypeÚhostrõ   r	   ÚCannotListenError)r;   r—   r˜   rž   Údests        r    Útest_cannotBindÚCannotBindTests.test_cannotBindÊ  s´   € ô
 Óˆä×Ò˜q !¨{Ñ;ˆØ�‰˜×(Ñ(Ô)Ø�J‰J‹L×ÑˆØ�z‰z‹|ˆØ×Ñ˜Ÿ™ EÔ*Ø×Ñ˜Ÿ™ KÔ0Ø×Ñ˜Ÿ™ AÔ&ð 	×ÑÜ×#Ñ#¤W×%6Ñ%6¸Èð 	ò 	
r#   c                 ó4   ^^• [        T5      UU4S j5       nU$ )z>Returns closure that when called calls f and then callbacks d.c                  ó:   >• T" U 0 UD6nTR                  S5        U$ )NÚ r   )Úargsr|  Úrtnr   r—   s      €€r    ÚnewfÚ/CannotBindTests._fireWhenDoneFunc.<locals>.newfá  s    ø€ á�T�.˜R‘.ˆCØ�J‰J�rŒNØˆJr#   r   )r;   r   r—   r¥  s    `` r    Ú_fireWhenDoneFuncÚ!CannotBindTests._fireWhenDoneFuncÞ  s"   ù€ ô 
ˆq‹õ	ó 
ð	ð
 ˆr#   c                 ó|  ^ ^^^^^^	^
• [         R                  " 5       n[        5       nT R                  XR                  5      Ul        [
        R                  " SUSS9m
T R                  T
R                  5        UU
U 4S jnUU 4S jmUUU	U
U 4S jmU 4S jmU 4S jmUU 4S	 jm	U 4S
 jmUR                  U5        U$ )z“
L{IReactorTCP.connectTCP} calls C{Factory.clientConnectionFailed} with
L{error.ConnectBindError} if the bind address specified is already in
use.
r   r�   r�   c                 ó  >• [         R                  " 5       n[        5       nTR                  XR                  5      Ul        [
        R                  " STR                  5       R                  USS9  UR                  TU5        U$ )Nr�   r0  ©ÚbindAddress)
r   r*   ru   r§  rT   r   r¾   r¡   rO   r,   )Úresultsr   Úcf1Ú_conmadero   r;   s      €€€r    Ú	_connect1Ú2CannotBindTests.test_clientBind.<locals>._connect1õ  si   ø€ Ü—’Ó ˆAÜ!Ó#ˆCØ $× 6Ñ 6°q×:KÑ:KÓ LˆCÔÜ×ÒØ˜QŸY™Y›[×-Ñ-¨sÐ@Pòð �M‰M˜( CÔ(ØˆHr#   c                 ó¾   >• [         R                  " 5       nTR                  X!R                  R                  5      UR                  l        UR                  TU5        U$ r   )r   r*   r§  ra   r<   r,   )r­  r®  r   Ú_check1connect2r;   s      €€r    r¯  Ú1CannotBindTests.test_clientBind.<locals>._conmadeÿ  sL   ø€ Ü—’Ó ˆAØ.2×.DÑ.DØ×#Ñ#×2Ñ2ó/ˆC×ÑÔ+ð �M‰M˜/¨3Ô/ØˆHr#   c                 ó”  >• TR                  UR                  R                  S5        [        R                  " 5       n[        R                  " 5       nUR                  R
                  R                  5       R                  n[        5       nTR                  X%R                  5      Ul
        TR                  X5R                  5      Ul        [        R                  " ST
R                  5       R                  USU4S9  UR                  TX5        UR                  TX5        [        R                  " X#/5      nUR                  T	X5        U$ )Nrg   r�   r«  )r¹   ra   rü   r   r*   r8   r¡   rO   ru   r§  r€   r‰   r   r¾   r,   ÚDeferredList)r­  r®  rŽ  r1   rO   Úcf2ÚdlÚ_check2failedÚ_check2stoppedÚ_stopro   r;   s          €€€€€r    r³  Ú8CannotBindTests.test_clientBind.<locals>._check1connect2  sþ   ø€ Ø×Ñ˜S×-Ñ-×2Ñ2°AÔ6ä—’Ó!ˆBÜ—’Ó!ˆBØ×#Ñ#×-Ñ-×5Ñ5Ó7×<Ñ<ˆDÜ!Ó#ˆCØ)-×)?Ñ)?Ø×.Ñ.ó*ˆCÔ&ð #×4Ñ4°R¿¹ÓIˆCŒOÜ×ÒØ˜QŸY™Y›[×-Ñ-¨sÀÈdÐ@Sòð �N‰N˜=¨#Ô3Ø�N‰N˜>¨3Ô4Ü×#Ò# R HÓ-ˆBØ�N‰N˜5 #Ô+ØˆIr#   c                 ó  >• TR                  UR                  S5        UR                  R                  [        R
                  5        TR                  UR                  R                  [        R
                  5      5        U $ r|   )r¹   r}   rB   r?   r	   ÚConnectBindErrorr”   r!   ©r­  r®  r·  r;   s      €r    r¹  Ú6CannotBindTests.test_clientBind.<locals>._check2failed  sS   ø€ Ø×Ñ˜SŸZ™Z¨Ô+Ø�J‰J�O‰OœE×2Ñ2Ô3Ø�O‰O˜CŸJ™J×,Ñ,¬U×-CÑ-CÓDÔEØˆNr#   c                 ó@   >• TR                  UR                  S5        U $ r|   ©r¹   rˆ   r¿  s      €r    rº  Ú7CannotBindTests.test_clientBind.<locals>._check2stopped!  s   ø€ Ø×Ñ˜SŸ[™[¨!Ô,ØˆNr#   c                 óÞ   >• [         R                  " 5       nUR                  TU5        TR                  X1R                  5      Ul        UR
                  R                  R                  5         U$ r   )r   r*   r,   r§  r‰   ra   r8   r9   )r­  r®  r·  r   Ú_check1cleanupr;   s       €€r    r»  Ú.CannotBindTests.test_clientBind.<locals>._stop%  sP   ø€ Ü—’Ó ˆAØ�M‰M˜.¨#Ô.Ø"×4Ñ4°Q¿¹ÓHˆCŒOØ×Ñ×&Ñ&×5Ñ5Ô7ØˆHr#   c                 ó>   >• TR                  UR                  S5        g r|   rÂ  )r­  r®  r;   s     €r    rÅ  Ú7CannotBindTests.test_clientBind.<locals>._check1cleanup,  s   ø€ Ø×Ñ˜SŸ[™[¨!Õ,r#   )
r   r*   rr   r§  rr  r   r’   r“   rQ   r,   )r;   ÚtheDeferredÚsfr°  rÅ  r³  r¹  rº  r¯  r»  ro   s   `   @@@@@@@r    Útest_clientBindÚCannotBindTests.test_clientBindé  s‘   ÿ€ ô —n’nÓ&ˆÜÓˆØ×0Ñ0°¿o¹oÓNˆŒÜ×Ò˜a ¨{Ñ;ˆØ�‰˜Ÿ™Ô(÷	ö	÷	ñ 	õ(	õ	ö	õ	-ð 	×Ñ 	Ô*ØÐr#   rE   N)	rG   rH   rI   rJ   rY   rž  r§  rË  rK   rE   r#   r    r—  r—  Ä  s   † ñò

ò(	õGr#   r—  c                   ó   • \ rS rSrSrS rSrg)ÚLocalRemoteAddressTestsi3  zc
Tests for correct getHost/getPeer values and that the correct address is
passed to buildProtocol.
c                 óä  ^ ^^^^	• [        5       n[        R                  " 5       Ul        UR                  m	[        R
                  " SUSS9mT R                  TR                  5        TR                  5       R                  n[        5       m[        R                  " 5       =nTl        [        R                  " SUT5      mUUU 4S jnUR                  U5        UU	4S jnUR                  U5        U$ )zg
L{IListeningPort.getHost} returns the same address as a client
connection's L{ITCPTransport.getPeer}.
r   r�   r�   c                 óà   >• TR                  TR                  5       /TR                  5        TR                  TR                  5       TR                  R                  R                  5       5        g r   )r¹   r¡   rc   ra   r8   ÚgetPeer)r�   ri  rO   r;   s    €€€r    r!   Ú7LocalRemoteAddressTests.test_hostAddress.<locals>.checkI  sP   ø€ Ø×Ñ˜dŸl™l›nÐ-¨}×/JÑ/JÔKØ×ÑØ—‘“ × :Ñ :× DÑ D× LÑ LÓ Nõr#   c                 ó(   >• TR                  5         T$ r   )r¿   )r�   r   ÚserverConnectionLosts    €€r    rI  Ú9LocalRemoteAddressTests.test_hostAddress.<locals>.cleanupQ  s   ø€ ð × Ñ Ô"Ø'Ð'r#   )rr   r   r*   r`   r   r’   r“   rQ   r¡   rO   ru   r_   r¾   r,   )
r;   rÍ   rž   ÚonConnectionr!   rI  ri  r   rO   rÔ  s
   `     @@@@r    Útest_hostAddressÚ(LocalRemoteAddressTests.test_hostAddress9  s¿   ü€ ô
 (Ó)ˆÜ/4¯~ª~Ó/?ˆÔ,Ø,×CÑCÐÜ× Ò   M¸[ÑIˆØ�‰˜×*Ñ*Ô+Ø�L‰L‹N×Ñˆä'Ó)ˆÜ>C¿nºnÓ>NÐNˆ�}Ô;Ü×&Ò& {°A°}ÓEˆ	÷	ð 	× Ñ  Ô'ö	(ð 	× Ñ  Ô)àÐr#   rE   N)rG   rH   rI   rJ   rY   r×  rK   rE   r#   r    rÎ  rÎ  3  s   † ñõ
!r#   rÎ  c                   ó   • \ rS rSrS rSrg)ÚWriterProtocoli]  c                 óò  • U R                   R                  S5        / SQnU R                   R                  U5        U R                   R                  5       nUR                  S:w  a  [        SU 35        SU R                  l        U R                   R                  5       nUR                  S:w  a  [        SU 35        SU R                  l        SU R                  l	        U R                   R                  5         g )Nó   Hello Cleveland!
)ó   Goodbyeó    crueló    worldó   
r™  z!getPeer returned non-TCP socket: rg   z!getHost returned non-TCP socket: )r8   ÚwriteÚwriteSequencerÑ  rš  r   rk   Úproblemr¡   Údoner9   )r;   ÚseqÚpeerÚuss       r    r<   ÚWriterProtocol.connectionMade^  s¾   € ð 	�‰×ÑÐ2Ô3Ú7ˆØ�‰×$Ñ$ SÔ)Ø�~‰~×%Ñ%Ó'ˆØ�9‰9˜ÓÜÐ3°D°6Ð:Ô;Ø#$ˆD�L‰LÔ Ø�^‰^×#Ñ#Ó%ˆØ�7‰7�eÓÜÐ3°B°4Ð8Ô9Ø#$ˆD�L‰LÔ Øˆ�‰Ôà�‰×%Ñ%Õ'r#   rE   N©rG   rH   rI   rJ   r<   rK   rE   r#   r    rÚ  rÚ  ]  s   † õ(r#   rÚ  c                   ó    • \ rS rSrS rS rSrg)ÚReaderProtocolit  c                 óB   • U R                   =R                  U-  sl        g r   )rk   Údata©r;   rí  s     r    ÚdataReceivedÚReaderProtocol.dataReceivedu  s   € Ø�‰×Ò˜TÑ!Ör#   c                 ó&   • SU R                   l        g r|   ©rk   rä  rA   s     r    rC   ÚReaderProtocol.connectionLostx  ó   € Øˆ�‰Õr#   rE   N©rG   rH   rI   rJ   rï  rC   rK   rE   r#   r    rë  rë  t  s   † ò"õr#   rë  c                   ó    • \ rS rSrS rS rSrg)ÚWriterClientFactoryi|  c                 ó    • SU l         SU l        g )Nr   r#   )rä  rí  r:   s    r    rd   ÚWriterClientFactory.__init__}  s   € ØˆŒ	Øˆ�	r#   c                 ó2   • [        5       nXl        X l        U$ r   )rë  rk   ra   rm   s      r    rT   Ú!WriterClientFactory.buildProtocol�  s   € ÜÓˆØŒ	ØÔØˆr#   )rí  rä  ra   N©rG   rH   rI   rJ   rd   rT   rK   rE   r#   r    r÷  r÷  |  s   † òõr#   r÷  c                   ó$   • \ rS rSrSrS rS rSrg)ÚWriteDataTestsiˆ  zk
Test that connected TCP sockets can actually write data. Try to exercise
the entire ITransport interface.
c                 óò  ^ ^^• [         R                  " 5       m[        Tl         STl        STl        [        T5      n[        R                  " SUSS9nT R                  UR                  5        UR                  5       R                  n[        5       m[        T5      n[        R                  " SX45        UUU 4S jn[        R                  " UR                   UR                   /5      nUR#                  U5      $ )zj
L{ITCPTransport.write} and L{ITCPTransport.writeSequence} send bytes to
the other end of the connection.
r   r�   r�   c                 ó  >• TR                  TR                  S5        TR                  TR                  S:H  S5        TR                  TR                  S5        SR                  / SQ5      nTR                  TR                  U:H  S5        g )Nú&writer didn't finish, it probably diedr   zwriter indicated an errorú$client didn't see connection droppedr#   )rÜ  rÝ  rÞ  rß  rà  z.client didn't receive all the data it expected)r”   rä  rã  Újoinrí  )r�   Úexpectedrÿ   r—   r;   s     €€€r    r!   Ú)WriteDataTests.test_writer.<locals>.checkŸ  sn   ø€ Ø�O‰O˜AŸF™FÐ$LÔMØ�O‰O˜AŸI™I¨™NÐ,GÔHØ�O‰O˜GŸL™LÐ*PÔQØ—x‘xÚPóˆHð �O‰OØ—‘ Ñ(Ø@õr#   )r   ÚFactoryrÚ  rä  rã  ÚWiredFactoryr   r’   r“   rQ   r¡   rO   r÷  r¾   r   rÀ   ÚonDisconnectr,   )	r;   ÚwrappedFro   rž   ÚwrappedClientFr!   r   rÿ   r—   s	   `      @@r    Útest_writerÚWriteDataTests.test_writerŽ  s¿   ú€ ô
 ×ÒÓˆÜ#ˆŒ
ØˆŒØˆŒ	Ü “?ˆÜ×Ò˜a °[ÑAˆØ�‰˜Ÿ™Ô(Ø�I‰I‹K×ÑˆÜ%Ó'ˆÜ% gÓ.ˆÜ×Ò˜;¨Ô:÷
	ô ×Ò ×!6Ñ!6¸×8SÑ8SÐ TÓUˆØ�}‰}˜UÓ#Ð#r#   c                 óv  ^^	^
^• [         R                  R                  S:X  a  [        S5      e[        R
                  " 5       m
[        R
                  " 5       m " U
U4S jS[        R                  5      n[        R                  " 5       nXl        [         R                  " SUSS9nU R                  UR                  5        UR                  5       n[        [        5       " S S	5      5       m " UU
U4S
 jS[        R                  5      n[        5       m	UT	l        T	R"                  nU	4S jnUR%                  U5        ['        SUR(                   SUR*                   35        [         R,                  " UR(                  UR*                  T	5        ['        S5        U R/                  U[0        R2                  5      $ )zü
A TCP transport which is written to after the connection has been shut
down should notify its protocol that the connection has been lost, even
if the TCP transport is not actively being monitored for read events
(ie, pauseProducing was called on it).
ÚIOCPReactora(  iocpreactor does not, in fact, stop reading immediately after pauseProducing is called. This results in a bonus disconnection notification. Under some circumstances, it might be possible to not receive this notifications (specifically, pauseProducing, deliver some data, proceed with this test). c                   ó2   >• \ rS rSrSrU 4S jrU4S jrSrg)ÚJWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.DisconnecteriÏ  z¨
Protocol for the server side of the connection which disconnects
itself in a callback on clientPaused and publishes notification
when its connection is actually lost.
c                 óL   >^ • [        S5        U 4S jnTR                  U5        g)z;
Set up a callback on clientPaused to lose the connection.
zDisconnector.connectionMadec                 óf   >• [        S5        TR                  R                  5         [        S5        g )Nz&Disconnector.connectionMade disconnectzloseConnection calledr7   )r�   r;   s    €r    r¿   ÚmWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Disconnecter.connectionMade.<locals>.disconnectÜ  s%   ø€ ÜÐ@ÔAØ—N‘N×1Ñ1Ô3ÜÐ/Õ0r#   N)r   r,   )r;   r¿   ÚclientPauseds   ` €r    r<   ÚYWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Disconnecter.connectionMadeÖ  s#   ù€ ô Ð1Ô2õ1ð
 ×(Ñ(¨Õ4r#   c                 óT   >• [        S5        TR                  S5        [        S5        g)zD
Notify observers that the server side of the connection has
ended.
zDisconnecter.connectionLostNzserverLost called back)r   r   )r;   rB   Ú
serverLosts     €r    rC   ÚYWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Disconnecter.connectionLostã  s%   ø€ ô
 Ð1Ô2Ø×#Ñ# DÔ)ÜÐ,Õ-r#   rE   N)rG   rH   rI   rJ   rY   r<   rC   rK   )r  r  s   €€r    ÚDisconnecterr  Ï  s   ø† ñõ5÷.ð .r#   r  r   r�   r�   c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚFWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infiniteió  z�
A producer which will write to its consumer as long as
resumeProducing is called.

@ivar consumer: The L{IConsumer} which will be written to.
c                 ó   • Xl         g r   ©Úconsumer)r;   r  s     r    rd   ÚOWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infinite.__init__ü  s   € Ø (•r#   c                 óf   • [        S5        U R                  R                  S5        [        S5        g )NzInfinite.resumeProducingó   xz*Infinite.resumeProducing wrote to consumer)r   r  rá  r:   s    r    ÚresumeProducingÚVWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infinite.resumeProducingÿ  s&   € ÜÐ.Ô/Ø—‘×#Ñ# DÔ)ÜÐ@ÕAr#   c                 ó   • [        S5        g )NzInfinite.stopProducing)r   r:   s    r    ÚstopProducingÚTWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.Infinite.stopProducing  s   € ÜÐ,Õ-r#   r  N)	rG   rH   rI   rJ   rY   rd   r"  r%  rK   rE   r#   r    ÚInfiniter  ó  s   † ñò)òBõ
.r#   r'  c                   ó*   >• \ rS rSrSrU UU4S jrSrg)ÚMWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.UnreadingWriteri  z[
Trivial protocol which pauses its transport immediately and then
writes some bytes to it.
c                 óº   >^ • [        S5        T R                  R                  5         TR                  S 5        [        S5        UU 4S jnTR	                  U5        g )NzUnreadingWriter.connectionMadezclientPaused called backc                 ó¤   >• [        S5        T" TR                  5      n[        S5        TR                  R                  US5        [        S5        g )Nz$UnreadingWriter.connectionMade writez5UnreadingWriter.connectionMade write created producerFz8UnreadingWriter.connectionMade write registered producer)r   r8   ÚregisterProducer)r�   Úproducerr'  r;   s     €€r    rá  ÚkWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.UnreadingWriter.connectionMade.<locals>.write  sB   ø€ ÜÐ>Ô?ñ  (¨¯©Ó7�HÜÐOÔPØ—N‘N×3Ñ3°H¸eÔDÜÐRÕSr#   )r   r8   ÚpauseProducingr   r,   )r;   rá  r'  r  r  s   ` €€€r    r<   Ú\WriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.UnreadingWriter.connectionMade  sI   ù€ ÜÐ4Ô5Ø—‘×-Ñ-Ô/Ø×%Ñ% dÔ+ÜÐ.Ô/öTð$ ×&Ñ& uÕ-r#   rE   N)rG   rH   rI   rJ   rY   r<   rK   )r'  r  r  s   €€€r    ÚUnreadingWriterr)    s   ø† ñ÷
.ò .r#   r1  c                 ó2   >• [        S5        TR                  $ )NÚcbClientLost)r   rƒ   )r�   rÃ   s    €r    r3  ÚJWriteDataTests.test_writeAfterShutdownWithoutReading.<locals>.cbClientLost,  s   ø€ Ü�ÔØ×$Ñ$Ð$r#   zConnecting to Ú:zReturning Deferred)r   Ú	__class__rG   r   r   r*   r   rR  ÚServerFactoryr’   r“   rQ   r¡   r   r   ru   rj   rw   r,   r   r›  rO   r¾   rÞ   r	   ÚConnectionLost)r;   r  rÁ   rO   rn   r1  r„   r3  r'  rÃ   r  r  s           @@@@r    Ú%test_writeAfterShutdownWithoutReadingÚ4WriteDataTests.test_writeAfterShutdownWithoutReading®  se  û€ ô ×Ñ×%Ñ%¨Ó6Üð?óð ô —~’~Ó'ˆô —^’^Ó%ˆ
÷	.ð 	.œ8×,Ñ,ô 	.ô< ×'Ò'Ó)ˆØ&ŒÜ× Ò   F°kÑBˆØ�‰˜×*Ñ*Ô+Ø�|‰|‹~ˆä	”]Ó	#÷	.ð 	.ó 
$ð	.÷&	.ñ 	.œh×/Ñ/ô 	.ôB !Ó"ˆØ!0ˆÔØ%Ÿ™Ðõ	%ð 	×(Ñ(¨Ô6Üˆn˜TŸY™Y˜K q¨¯©¨Ð4Ô5Ü×Ò˜4Ÿ9™9 d§i¡i°Ô8ô 	Ð Ô!Ø×!Ñ!Ð"6¼×8LÑ8LÓMÐMr#   rE   N)rG   rH   rI   rJ   rY   r  r9  rK   rE   r#   r    rþ  rþ  ˆ  s   † ñò
$õ@INr#   rþ  c                   ó   • \ rS rSrS rSrg)ÚConnectionLosingProtocoli:  c                 ó   • U R                   R                  S5        U R                   R                  5         U R                  R	                  5         U R                  R
                  R                  U R                   5        g )Nó   1)r8   rá  r9   ÚmasterÚ_connectionMadeÚportsrh   r:   s    r    r<   Ú'ConnectionLosingProtocol.connectionMade;  sP   € Ø�‰×Ñ˜TÔ"Ø�‰×%Ñ%Ô'Ø�‰×#Ñ#Ô%Ø�‰×Ñ× Ñ  §¡Õ0r#   rE   Nré  rE   r#   r    r<  r<  :  s   † õ1r#   r<  c                   ó    • \ rS rSrS rS rSrg)ÚNoopProtocoliB  c                 ó–   • [         R                  " 5       U l        U R                  R                  R                  U R                  5        g r   )r   r*   r   r?  ÚserverConnsrh   r:   s    r    r<   ÚNoopProtocol.connectionMadeC  s,   € Ü—’Ó!ˆŒØ�‰×Ñ×&Ñ& t§v¡vÕ.r#   c                 ó:   • U R                   R                  S5        g ©NT)r   r   rA   s     r    rC   ÚNoopProtocol.connectionLostG  s   € Ø�‰�‰˜Õr#   )r   NrF   rE   r#   r    rD  rD  B  s   † ò/õr#   rD  c                   ó$   • \ rS rSrSrS rS rSrg)ÚConnectionLostNotifyingProtocoliK  aG  
Protocol which fires a Deferred which was previously passed to
its initializer when the connection is lost.

@ivar onConnectionLost: The L{Deferred} which will be fired in
    C{connectionLost}.

@ivar lostConnectionReason: L{None} until the connection is lost, then a
    reference to the reason passed to C{connectionLost}.
c                 ó   • S U l         Xl        g r   ©ÚlostConnectionReasonÚonConnectionLost)r;   rP  s     r    rd   Ú(ConnectionLostNotifyingProtocol.__init__W  s   € Ø$(ˆÔ!Ø 0Õr#   c                 óF   • Xl         U R                  R                  U 5        g r   )rO  rP  r   rA   s     r    rC   Ú.ConnectionLostNotifyingProtocol.connectionLost[  s   € Ø$*Ô!Ø×Ñ×&Ñ& tÕ,r#   rN  N)rG   rH   rI   rJ   rY   rd   rC   rK   rE   r#   r    rL  rL  K  s   † ñ	ò1õ-r#   rL  c                   ó   • \ rS rSrSrS rSrg)ÚHandleSavingProtocoli`  z…
Protocol which grabs the platform-specific socket handle and
saves it as an attribute on itself when the connection is
established.
c                 ój   • UR                  5       U l        [        R                  R	                  X5      $ )zD
Save the platform-specific socket handle for future
introspection.
)Ú	getHandleÚhandler   rR  ÚmakeConnection)r;   r8   s     r    rY  Ú#HandleSavingProtocol.makeConnectiong  s+   € ð
  ×)Ñ)Ó+ˆŒÜ× Ñ ×/Ñ/°Ó@Ð@r#   )rX  N)rG   rH   rI   rJ   rY   rY  rK   rE   r#   r    rU  rU  `  s   † ñõAr#   rU  c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚProperlyCloseFilesMixinip  z9
Tests for platform resources properly being cleaned up.
c                 ó   • [        5       e)z¢
Bind a server port to which connections will be made.  The server
should use the given protocol factory.

@return: The L{IListeningPort} for the server created.
©ÚNotImplementedError©r;   Úaddressr¼   rk   s       r    ÚcreateServerÚ$ProperlyCloseFilesMixin.createServeru  ó   € ô "Ó#Ð#r#   c                 ó   • [        5       e)z£
Establish a connection to the given address using the given
L{ClientCreator} instance.

@return: A Deferred which will fire with the connected protocol instance.
r^  ©r;   ra  r¼   r>  s       r    ÚconnectClientÚ%ProperlyCloseFilesMixin.connectClient~  rd  r#   c                 ó   • [        5       e)zm
Return the exception class which will be raised when an operation is
attempted on a closed platform handle.
r^  r:   s    r    ÚgetHandleExceptionTypeÚ.ProperlyCloseFilesMixin.getHandleExceptionType‡  s   € ô
 "Ó#Ð#r#   c                 óÆ   • [         R                  " 5       (       a$  [        R                  " [        R
                  5      $ [        R                  " [        R                  5      $ )z†
Return a L{hamcrest.core.matcher.Matcher} that matches the
errno expected to result from writing to a closed platform
socket handle.
)r   Ú	isWindowsÚhamcrestÚequal_torB  ÚWSAENOTSOCKÚEBADFr:   s    r    ÚgetHandleErrorCodeMatcherÚ1ProperlyCloseFilesMixin.getHandleErrorCodeMatcherŽ  s?   € ô ×Ò×ÑÜ×$Ò$¤U×%6Ñ%6Ó7Ð7Ü× Ò ¤§¡Ó-Ð-r#   c                 ó   ^ ^^	^
• [         R                  " 5       m	[        R                  " 5       nU	4S jUl        T R	                  SSU5      m
[         R                  " 5       mT
R                  5       n[        R                  " [        U4S j5      nT R                  UR                  UR                  U5      nUU	4S jnUR                  U5        U 4S jnUR                  U5        U
4S jnUR                  U5        U$ )zX
Test that lost connections properly have their underlying socket
resources cleaned up.
c                  ó   >• [        T 5      $ r   )rL  )ÚonServerConnectionLosts   €r    r  ÚAProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.<lambda>¡  s   ø€ Ô)HØ"ô*
r#   r�   r   c                  ó   >• [        T 5      $ r   )rU  )ÚonClientConnectionLosts   €r    r  rw  ©  s   ø€ Ô1Ð2HÔIr#   c                 óž   >• U R                   R                  S5        U R                   R                  5         [        R                  " TT/5      $ )z‚
Disconnect the client.  Return a Deferred which fires when both
the client and the server have received disconnect notification.
s0   some bytes to make sure the connection is set up)r8   rá  r9   r   rÀ   )rÃ   ry  rv  s    €€r    ÚclientConnectedÚHProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.clientConnected¯  sD   ø€ ð
 ×Ñ×"Ñ"Ð#VÔWØ×Ñ×+Ñ+Ô-Ü×&Ò&Ð(>Ð@VÐ'WÓXÐXr#   c                 óð  >• U u  pUR                   R                  [        R                  5      (       d  [	        UR                   S5        UR                   R                  [        R                  5      (       d  [	        UR                   S5        TR                  5       nTR                  TR                  5       UR                  R                  S5      n[        R                  " UR                  S   U5        g)zH
Verify that the underlying platform socket handle has been
cleaned up.
z,Client lost connection for unexpected reasonz,Server lost connection for unexpected reasons   bytesr   N)rO  r!   r	   ÚConnectionClosedr   rr  rõ   rj  rX  Úsendrn  Úassert_thatr£  )r&   rÃ   rÁ   ÚerrorCodeMatcherÚ	exceptionr;   s        €r    ÚclientDisconnectedÚKProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.clientDisconnectedº  sÊ   ø€ ð
 $‰NˆFØ×.Ñ.×4Ñ4´U×5KÑ5K×LÑLÜØ×/Ñ/ØBôð ×.Ñ.×4Ñ4´U×5KÑ5K×LÑLÜØ×/Ñ/ØBôð  $×=Ñ=Ó?ÐØ×)Ñ)Ø×+Ñ+Ó-¨v¯}©}×/AÑ/AÀ8óˆIô × Ò Ø—‘˜qÑ!Ø õr#   c                 ót   >^ • [         R                  " TR                  5      nUR                  U 4S j5        U$ )zT
Shut down the server port.  Return a Deferred which fires when
this has completed.
c                 ó   >• T$ r   rE   )r¯   rH  s    €r    r  ÚRProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.cleanup.<locals>.<lambda>Û  s   ø€ ©;r#   )r   r¢   rQ   r,   )rH  r&   r<  s   ` €r    rI  Ú@ProperlyCloseFilesMixin.test_properlyCloseFiles.<locals>.cleanupÕ  s/   ù€ ô
 ×(Ò(¨×)AÑ)AÓBˆFØ×ÑÔ6Ô7ØˆMr#   )r   r*   r   r7  rb  r¡   rQ  r   rg  r›  rO   r,   rS  )r;   rÍ   Ú
serverAddrr>  ÚclientDeferredr{  rƒ  rI  ry  rv  r<  s   `       @@@r    Útest_properlyCloseFilesÚ/ProperlyCloseFilesMixin.test_properlyCloseFilesš  sÙ   û€ ô
 "'§¢Ó!1ÐÜ ×.Ò.Ó0ˆô"
ˆÔð ×&Ñ& {°A°}ÓEˆ
ä!&§¢Ó!1ÐØ×'Ñ'Ó)ˆ
Ü ×.Ò.ÜÔIó
ˆð ×+Ñ+Ø�O‰O˜ZŸ_™_¨mó
ˆö	Yð 	×"Ñ" ?Ô3õ	ð2 	×"Ñ"Ð#5Ô6õ	ð 	×Ñ˜wÔ'àÐr#   rE   N)rG   rH   rI   rJ   rY   rb  rg  rj  rr  r‹  rK   rE   r#   r    r\  r\  p  s!   † ñò$ò$ò$ò
.õFr#   r\  c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚProperlyCloseFilesTestsiã  zƒ
Test that the sockets created by L{IReactorTCP.connectTCP} are cleaned up
when the connection they are associated with is closed.
c                 ó,   • [         R                  " X#US9$ )z5
Create a TCP server using L{IReactorTCP.listenTCP}.
r�   )r   r’   r`  s       r    rb  Ú$ProperlyCloseFilesTests.createServeré  s   € ô × Ò  ÀÑHÐHr#   c                 ó$   • UR                  X5      $ )z6
Create a TCP client using L{IReactorTCP.connectTCP}.
)r¾   rf  s       r    rg  Ú%ProperlyCloseFilesTests.connectClientï  s   € ð ×'Ñ'¨Ó<Ð<r#   c                 ó"   • [         R                  $ )zŒ
Return L{socket.error} as the expected error type which will be
raised by a write to the low-level socket object after it has been
closed.
)rL  r	   r:   s    r    rj  Ú.ProperlyCloseFilesTests.getHandleExceptionTypeõ  s   € ô �|‰|Ðr#   rE   N)	rG   rH   rI   rJ   rY   rb  rg  rj  rK   rE   r#   r    rŽ  rŽ  ã  s   † ñò
Iò=õr#   rŽ  c                   ó&   • \ rS rSrS rS rS rSrg)ÚWiredForDeferredsiþ  c                 óD   • [         R                  R                  XU5        g r   )r   ÚProtocolWrapperrd   )r;   rk   ÚwrappedProtocols      r    rd   ÚWiredForDeferreds.__init__ÿ  s   € Ü× Ñ ×)Ñ)¨$¸ÕIr#   c                 óŒ   • [         R                  R                  U 5        U R                  R                  R                  S 5        g r   )r   r˜  r<   rk   Ú	onConnectr   r:   s    r    r<   Ú WiredForDeferreds.connectionMade  s.   € Ü× Ñ ×/Ñ/°Ô5Ø�‰×Ñ×'Ñ'¨Õ-r#   c                 óŒ   • [         R                  R                  X5        U R                  R                  R                  S 5        g r   )r   r˜  rC   rk   r  r   rA   s     r    rC   Ú WiredForDeferreds.connectionLost  s.   € Ü× Ñ ×/Ñ/°Ô=Ø�‰×!Ñ!×*Ñ*¨4Õ0r#   rE   N)rG   rH   rI   rJ   rd   r<   rC   rK   rE   r#   r    r–  r–  þ  s   † òJò.õ1r#   r–  c                   ó   • \ rS rSr\rS rSrg)r  i  c                 óª   • [         R                  R                  X5        [        R                  " 5       U l        [        R                  " 5       U l        g r   )r   ÚWrappingFactoryrd   r   r*   rœ  r  ©r;   ÚwrappedFactorys     r    rd   ÚWiredFactory.__init__  s3   € Ü× Ñ ×)Ñ)¨$Ô?ÜŸšÓ)ˆŒÜ!ŸNšNÓ,ˆÕr#   )rœ  r  N)rG   rH   rI   rJ   r–  r   rd   rK   rE   r#   r    r  r    s   † Ø €Hõ-r#   r  c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚAddressTestsi  zJ
Tests for address-related interactions with client and server protocols.
c                 óœ  •  " S S[         R                  5      n[        5       U l        [        R
                  " 5       =U l        U R                  l        [        R
                  " 5       =U l        U R                  l	        U" U R                  5      U l
        [        5       U l        [        R
                  " 5       =U l        U R                  l        [        R
                  " 5       =U l        U R                  l	        U" U R                  5      U l        [         R"                  " SU R                  SS9U l        [         R&                  " U R$                  R)                  5       R*                  U R$                  R)                  5       R$                  U R                  5      U l        [        R.                  " U R                  U R                  /5      $ )a	  
Create a port and connected client/server pair which can be used
to test factory behavior related to addresses.

@return: A L{defer.Deferred} which will be called back when both the
    client and server protocols have received their connection made
    callback.
c                   ó$   • \ rS rSrSrS rS rSrg)Ú.AddressTests.setUp.<locals>.RememberingWrapperi#  a0  
Simple wrapper factory which records the addresses which are
passed to its L{buildProtocol} method and delegates actual
protocol creation to another factory.

@ivar addresses: A list of the objects passed to buildProtocol.
@ivar factory: The wrapped factory to which protocol creation is
    delegated.
c                 ó   • / U l         Xl        g r   ©Ú	addressesrk   )r;   rk   s     r    rd   Ú7AddressTests.setUp.<locals>.RememberingWrapper.__init__.  s   € Ø!#�”Ø&•r#   c                 ón   • U R                   R                  U5        U R                  R                  U5      $ )zX
Append the given address to C{self.addresses} and forward
the call to C{self.factory}.
)r­  rh   rk   rT   )r;   rn   s     r    rT   Ú<AddressTests.setUp.<locals>.RememberingWrapper.buildProtocol5  s+   € ð
 —‘×%Ñ% dÔ+Ø—|‘|×1Ñ1°$Ó7Ð7r#   r¬  N)rG   rH   rI   rJ   rY   rd   rT   rK   rE   r#   r    ÚRememberingWrapperrª  #  s   † ñò'õ8r#   r±  r   r�   r�   )r   ÚClientFactoryrr   rÁ   r   r*   rÂ   r_   ÚserverConnLostr`   ÚserverWrapperru   rÃ   rÄ   ÚclientConnLostÚclientWrapperr   r’   rO   r¾   r¡   r›  r   rÀ   )r;   r±  s     r    ÚsetUpÚAddressTests.setUp  sA  € ô	8¤×!7Ñ!7ô 	8ô: &Ó'ˆŒÜCHÇ>Â>ÓCSÐSˆÔ˜dŸk™kÔ@ÜCHÇ>Â>ÓCSÐSˆÔ˜dŸk™kÔ@ñ 0°·±Ó<ˆÔô &Ó'ˆŒÜCHÇ>Â>ÓCSÐSˆÔ˜dŸk™kÔ@ÜCHÇ>Â>ÓCSÐSˆÔ˜dŸk™kÔ@Ù/°·±Ó<ˆÔä×%Ò% a¨×);Ñ);À{ÑSˆŒ	Ü ×+Ò+Ø�I‰I×ÑÓ×$Ñ$ d§i¡i×&7Ñ&7Ó&9×&>Ñ&>À×@RÑ@Ró
ˆŒô ×"Ò" D×$7Ñ$7¸×9LÑ9LÐ#MÓNÐNr#   c                 óà   • U R                   R                  5         [        R                  " U R                  U R
                  [        R                  " U R                  R                  5      /5      $ )zN
Disconnect the client/server pair and shutdown the port created in
L{setUp}.
)	r   r¿   r   rÀ   r³  rµ  r¢   rO   rQ   r:   s    r    ÚtearDownÚAddressTests.tearDownT  sV   € ð
 	�‰×!Ñ!Ô#Ü×"Ò"à×#Ñ#Ø×#Ñ#Ü×#Ò# D§I¡I×$;Ñ$;Ó<ðó
ð 	
r#   c                 óÔ  • U R                   R                  R                  R                  5       nU R                  R                  R                  R                  5       nU R                  U R                  R                  [        SUR                  UR                  5      /5        U R                  U R                  R                  [        SUR                  UR                  5      /5        g)a5  
L{ClientFactory.buildProtocol} should be invoked with the address of
the server to which a connection has been established, which should
be the same as the address reported by the C{getHost} method of the
transport of the server protocol and as the C{getPeer} method of the
transport of the client protocol.
r™  N)rÁ   ra   r8   r¡   rÃ   rÑ  r¹   r¶  r­  r   r›  rO   )r;   r;  Ú
clientPeers      r    Útest_buildProtocolClientÚ%AddressTests.test_buildProtocolClientb  sª   € ð —[‘[×-Ñ-×7Ñ7×?Ñ?ÓAˆ
Ø—[‘[×-Ñ-×7Ñ7×?Ñ?ÓAˆ
à×ÑØ×Ñ×(Ñ(Ü˜ 
§¡°·±ÓAÐBô	
ð 	×ÑØ×Ñ×(Ñ(Ü˜ 
§¡°·±ÓAÐBõ	
r#   )
rÃ   rµ  rÄ   r¶  r   rO   rÁ   r³  rÂ   r´  N)	rG   rH   rI   rJ   rY   r·  rº  r¾  rK   rE   r#   r    r§  r§    s   † ñò9Oòv
õ
r#   r§  c                   ó   • \ rS rSrS rSrg)ÚLargeBufferWriterProtocoliw  c                 óª   ^ • T R                   R                  ST R                  R                  S-
  -  5        U 4S jn[        R
                  " SU5        g )Nó   Xrg   c                  ó’   >• T R                   R                  S5        ST R                  l        T R                   R	                  5         g )NrÃ  rg   )r8   rá  rk   rä  r9   r:   s   €r    ÚfinishÚ8LargeBufferWriterProtocol.connectionMade.<locals>.finish€  s1   ø€ Ø�N‰N× Ñ  Ô&Ø !ˆD�L‰LÔØ�N‰N×)Ñ)Õ+r#   gü©ñÒMbP?)r8   rá  rk   Úlenr   Ú	callLater)r;   rÅ  s   ` r    r<   Ú(LargeBufferWriterProtocol.connectionMade}  s@   ø€ Ø�‰×Ñ˜T T§\¡\×%5Ñ%5¸Ñ%9Ñ:Ô;õ	,ô
 	×Ò˜% Õ(r#   rE   Nré  rE   r#   r    rÁ  rÁ  w  s   † õ)r#   rÁ  c                   ó    • \ rS rSrS rS rSrg)ÚLargeBufferReaderProtocoliˆ  c                 óT   • U R                   =R                  [        U5      -  sl        g r   )rk   rÇ  rî  s     r    rï  Ú&LargeBufferReaderProtocol.dataReceived‰  s   € Ø�‰×ÒœC ›IÑ%Ör#   c                 ó&   • SU R                   l        g r|   rò  rA   s     r    rC   Ú(LargeBufferReaderProtocol.connectionLostŒ  rô  r#   rE   Nrõ  rE   r#   r    rË  rË  ˆ  s   † ò&õr#   rË  c                   ó    • \ rS rSrS rS rSrg)ÚLargeBufferReaderClientFactoryi�  c                 ó    • SU l         SU l        g ©Nr   )rä  rÇ  r:   s    r    rd   Ú'LargeBufferReaderClientFactory.__init__‘  s   € ØˆŒ	Øˆ�r#   c                 ó2   • [        5       nXl        X l        U$ r   )rË  rk   ra   rm   s      r    rT   Ú,LargeBufferReaderClientFactory.buildProtocol•  s   € Ü%Ó'ˆØŒ	ØÔØˆr#   )rä  ra   rÇ  Nrü  rE   r#   r    rÑ  rÑ  �  s   † òõr#   rÑ  c                   ó   • \ rS rSrSrS rSrg)ÚFireOnCloseiœ  zYA wrapper around a protocol that makes it fire a deferred when
connectionLost is called.
c                 óŒ   • [         R                  R                  X5        U R                  R                  R                  S 5        g r   )r   r˜  rC   rk   rw   r   rA   s     r    rC   ÚFireOnClose.connectionLost¡  s.   € Ü× Ñ ×/Ñ/°Ô=Ø�‰×Ñ×&Ñ& tÕ,r#   rE   N)rG   rH   rI   rJ   rY   rC   rK   rE   r#   r    rØ  rØ  œ  s   † ñõ-r#   rØ  c                   ó   • \ rS rSr\rS rSrg)ÚFireOnCloseFactoryi¦  c                 óv   • [         R                  R                  X5        [        R                  " 5       U l        g r   )r   r¢  rd   r   r*   rw   r£  s     r    rd   ÚFireOnCloseFactory.__init__©  s$   € Ü× Ñ ×)Ñ)¨$Ô?ÜŸšÓ(ˆ�r#   )rw   N)rG   rH   rI   rJ   rØ  r   rd   rK   rE   r#   r    rÜ  rÜ  ¦  s   † Ø€Hõ)r#   rÜ  c                   ó"   • \ rS rSrSrSrS rSrg)ÚLargeBufferTestsi®  z0Test that buffering large amounts of data works.i  Àc                 ó  ^ ^^• [         R                  " 5       m[        Tl         STl        STl        T R
                  Tl        [        T5      n[        R                  " SUSS9nT R                  UR                  5        UR                  5       R                  n[        5       m[        T5      n[        R                  " SX45        [         R"                  " UR$                  UR$                  /5      nUUU 4S jnUR'                  U5      $ )Nr   r�   r�   c                 ó~  >• TR                  TR                  S5        TR                  TR                  TR                  :¬  STR                  TR                  4-  5        TR                  TR                  TR                  :*  STR                  TR                  4-  5        TR                  TR                  S5        g )Nr  z9client didn't receive all the data it expected (%d != %d)z8client did receive more data than it expected (%d != %d)r  )r”   rä  rÇ  Údatalen)r�   rÿ   r—   r;   s    €€€r    r!   Ú*LargeBufferTests.testWriter.<locals>.checkÃ  s™   ø€ Ø�O‰O˜AŸF™FÐ$LÔMØ�O‰OØ—‘˜tŸ|™|Ñ+ðØ '§¡¨T¯\©\Ð:ñ;ôð
 �O‰OØ—‘˜tŸ|™|Ñ+ðØ '§¡¨T¯\©\Ð:ñ;ôð
 �O‰O˜GŸL™LÐ*PÕQr#   )r   r  rÁ  rä  rã  rã  rÇ  rÜ  r   r’   r“   rQ   r¡   rO   rÑ  r¾   r   rÀ   rw   r,   )	r;   r	  ro   rž   r
  r   r!   rÿ   r—   s	   `      @@r    Ú
testWriterÚLargeBufferTests.testWriter³  sÊ   ú€ Ü×ÒÓˆÜ.ˆŒ
ØˆŒØˆŒ	Ø—‘ˆŒÜ% aÓ(ˆÜ×Ò˜a °[ÑAˆØ�‰˜Ÿ™Ô(Ø�I‰I‹K×ÑˆÜ0Ó2ˆÜ+¨GÓ4ˆÜ×Ò˜;¨Ô:ä×Ò ×!2Ñ!2°N×4KÑ4KÐ LÓMˆ÷	Rð �}‰}˜UÓ#Ð#r#   rE   N)rG   rH   rI   rJ   rY   rã  rå  rK   rE   r#   r    rà  rà  ®  s   † Ù:à€Gõ$r#   rà  c                   ó(   • \ rS rSrSrSrS rS rSrg)ÚMyHCProtocoliÔ  Fc                 óX   • SU l         U R                  (       a  U R                  S 5        g g rI  )ÚreadHalfClosedÚwriteHalfClosedrC   r:   s    r    ÚreadConnectionLostÚMyHCProtocol.readConnectionLostÙ  s&   € Ø"ˆÔà××Ø×Ñ Õ%ð  r#   c                 óX   • SU l         U R                  (       a  U R                  S 5        g g rI  )rë  rê  rC   r:   s    r    ÚwriteConnectionLostÚ MyHCProtocol.writeConnectionLostß  s&   € Ø#ˆÔà××Ø×Ñ Õ%ð r#   )rê  rë  N)	rG   rH   rI   rJ   rê  rë  rì  rï  rK   rE   r#   r    rè  rè  Ô  s   † à€NØ€Oò&õ&r#   rè  c                   ó"   • \ rS rSrSrSrS rSrg)ÚMyHCFactoryiæ  r   Nc                 ó\   • U =R                   S-  sl         [        5       nXl        X l        U$ r|   )ri   rè  rk   ra   rm   s      r    rT   ÚMyHCFactory.buildProtocolê  s'   € Ø�Š�qÑ�Ü‹NˆØŒ	ØÔØˆr#   )ra   )rG   rH   rI   rJ   ri   r_   rT   rK   rE   r#   r    rò  rò  æ  s   † Ø€FØ!Ðõr#   rò  c                   ó<   • \ rS rSrSrS rS rS rS rS r	S r
S	rg
)ÚHalfCloseTestsiò  zTest half-closing connections.c                 ód  ^ ^• [        5       =T l        n[        R                  " SUSS9=T l        mT R                  TR                  5        [        U4S j5      n[        R                  " [        [        5      T l        UR                  UU 4S j5        UR                  T R                  5        U$ )Nr   r�   r�   c                  ó   >• T R                   $ r   )r  )ro   s   €r    r  Ú&HalfCloseTests.setUp.<locals>.<lambda>ù  s	   ø€ ˜aŸkškr#   c                 óœ   >• TR                   R                  TR                  5       R                  TR                  5       R                  5      $ r   )Úcfr¾   r¡   r›  rO   )Ú_ro   r;   s    €€r    r  rù  ý  s.   ø€  §¡× 2Ñ 2°1·9±9³;×3CÑ3CÀQÇYÁYÃ[×EUÑEUÔ Vr#   )rò  r—   r   r’   ro   r“   rQ   r2   r   rQ  rè  rû  r,   Ú_setUp)r;   r—   r   ro   s   `  @r    r·  ÚHalfCloseTests.setUpõ  s}   ù€ Ü “]Ð"ˆŒ�Ü×&Ò& q¨!°{ÑCÐCˆŒ�Ø�‰˜Ÿ™Ô(ÜÔ)Ó*ˆä×(Ò(¬´,Ó?ˆŒà	�‰ÕVÔWØ	�‰�d—k‘kÔ"Øˆr#   c                 óæ   ^ • UT l         [        R                  " 5       =T l        T R                   l        T R                  T R                   R                  R                  S5        [        U 4S j5      $ )Nrg   c                  ó6   >• [        T R                  SS 5      S L$ )Nra   )r  r—   r:   s   €r    r  Ú'HalfCloseTests._setUp.<locals>.<lambda>  s   ø€ ¤¨¯©°ÀÓ!FÈdÑ!Rr#   )	rÃ   r   r*   ÚclientProtoConnectionLostrl   r¹   r8   r  r2   ©r;   rÃ   s   ` r    rý  ÚHalfCloseTests._setUp  sQ   ø€ ØˆŒÜFKÇnÂnÓFVÐVˆÔ&¨¯©Ô)CØ×Ñ˜Ÿ™×.Ñ.×8Ñ8¸!Ô<äÔRÓSÐSr#   c                 óP  ^ • T R                  T R                  R                  S5        T R                  R                  R	                  5         [
        R                  " T R                  R                  5      nUR                  U 4S j5        UR                  T R                  5        U$ )Nr   c                 ó   >• TR                   $ r   )r  )r¯   r;   s    €r    r  Ú)HalfCloseTests.tearDown.<locals>.<lambda>  s   ø€  $×"@Ò"@r#   )r¹   rÃ   Úclosedr8   r9   r   r¢   ro   rQ   r,   Ú	_tearDown)r;   r   s   ` r    rº  ÚHalfCloseTests.tearDown  so   ø€ Ø×Ñ˜Ÿ™×+Ñ+¨QÔ/Ø�‰×Ñ×,Ñ,Ô.Ü×Ò §¡× 4Ñ 4Ó5ˆØ	�‰Ô@ÔAØ	�‰�d—n‘nÔ%Øˆr#   c                 óª  ^ ^• T R                  T R                  R                  S5        T R                  T R                  R                  R                  S5        [
        R                  " 5       mUU 4S jnUT R                  R                  l        T R                  R                  R                  R                  5         TR                  U 4S j5        T$ )Nrg   r   c                 ó^   >• STR                   R                  l        TR                  S 5        g r|   )r—   ra   r  r   )rB   r   r;   s    €€r    Ú_connectionLostÚ1HalfCloseTests._tearDown.<locals>._connectionLost  s!   ø€ Ø)*ˆD�F‰F×ÑÔ&Ø�J‰J�tÕr#   c                 ód   >• TR                  TR                  R                  R                  S5      $ r|   )r¹   r—   ra   r  ©rþ   r;   s    €r    r  Ú*HalfCloseTests._tearDown.<locals>.<lambda>  s"   ø€  × 0Ñ 0°·±×1DÑ1D×1KÑ1KÈQÔ Or#   )r¹   rÃ   r  r—   ra   r   r*   rC   r8   r9   r,   )r;   r�   r  r   s   `  @r    r	  ÚHalfCloseTests._tearDown  s’   ù€ Ø×Ñ˜Ÿ™×+Ñ+¨QÔ/ð 	×Ñ˜Ÿ™×,Ñ,×3Ñ3°QÔ7Ü�NŠNÓˆö	ð .=ˆ�‰×ÑÔ*Ø�‰×Ñ×%Ñ%×4Ñ4Ô6Ø	�‰ÔOÔPØˆr#   c                 ó  ^ ^^^• T R                   mT R                  mTR                  mTR                  S5        [	        U4S j5      nU4S jnUUU 4S jnUUU 4S jnUR                  U5      R                  U5      R                  U5      $ )Nó   helloc                  ó4   >• [        T R                  5      S:H  $ rÓ  )rÇ  Ú_tempDataBuffer©Úts   €r    r  Ú5HalfCloseTests.testCloseWriteCloser.<locals>.<lambda>&  s   ø€ œc !×"3Ñ"3Ó4¸Ò9r#   c                 óB   >• TR                  5         [        U4S j5      $ )Nc                  ó   >• T R                   $ r   )Ú_writeDisconnectedr  s   €r    r  ÚHHalfCloseTests.testCloseWriteCloser.<locals>.loseWrite.<locals>.<lambda>*  s   ø€  Q×%9Ò%9r#   )ÚloseWriteConnectionr2   )r�   r  s    €r    Ú	loseWriteÚ6HalfCloseTests.testCloseWriteCloser.<locals>.loseWrite(  s   ø€ Ø×!Ñ!Ô#ÜÔ9Ó:Ð:r#   c                 óÄ   >• TR                  TR                  5        TR                  TR                  5        TR                  TR                  5        [        U4S j5      $ )Nc                  ó0   >• T R                   R                  $ r   )ra   rê  ©r—   s   €r    r  ÚDHalfCloseTests.testCloseWriteCloser.<locals>.check.<locals>.<lambda>0  s   ø€  Q§^¡^×%BÒ%Br#   )r¬   r  r”   rë  rê  r2   )r�   rÃ   r—   r;   s    €€€r    r!   Ú2HalfCloseTests.testCloseWriteCloser.<locals>.check,  sG   ø€ Ø×Ñ˜VŸ]™]Ô+Ø�O‰O˜F×2Ñ2Ô3Ø×Ñ˜V×2Ñ2Ô3ÜÔBÓCÐCr#   c                 ó�  >• TR                   R                  nU" S5        U" S5        TR                  S[        TR                   R                  5      5        TR                  TR
                  R                  S5        TR                  TR
                  R                  5        TR                  TR
                  R                  5        g )Nrß  s   lalala fooled your   r  )r8   rá  r¹   rÇ  r  ra   rí  r¬   r  r”   rê  )r�   ÚwrÃ   r—   r;   s     €€€r    rá  Ú2HalfCloseTests.testCloseWriteCloser.<locals>.write2  s�   ø€ Ø× Ñ ×&Ñ&ˆAÙˆiŒLÙÐ"Ô#Ø×Ñ˜Q¤ F×$4Ñ$4×$DÑ$DÓ EÔFØ×Ñ˜QŸ^™^×0Ñ0°(Ô;Ø×Ñ˜QŸ^™^×2Ñ2Ô3Ø�O‰O˜AŸN™N×9Ñ9Õ:r#   )rÃ   r—   r8   rá  r2   r,   )r;   r   r  r!   rá  rÃ   r—   r  s   `    @@@r    ÚtestCloseWriteCloserÚ#HalfCloseTests.testCloseWriteCloser   sn   û€ Ø—‘ˆØ�F‰FˆØ×Ñˆà	�‰�ÔÜÔ9Ó:ˆõ	;÷	D÷	;ð �}‰}˜YÓ'×3Ñ3°EÓ:×FÑFÀuÓMÐMr#   c                 óú   ^ ^• T R                   mTR                  R                  R                  5         [        R
                  " [        U4S j5      [        U 4S j5      /5      nUR                  UU 4S j5        U$ )Nc                  ó0   >• T R                   R                  $ r   )ra   rë  r#  s   €r    r  Ú;HalfCloseTests.testWriteCloseNotification.<locals>.<lambda>C  s   ø€  !§.¡.×"@Ò"@r#   c                  ó0   >• T R                   R                  $ r   )rÃ   rê  r:   s   €r    r  r-  D  s   ø€  $§+¡+×"<Ò"<r#   c                 óP   >• TR                  TR                  R                  S5      $ )NF)r¹   ra   rê  )rü  r—   r;   s    €€r    r  r-  G  s   ø€  × 0Ñ 0°·±×1NÑ1NÐPUÔ Vr#   )r—   ra   r8   r  r   rÀ   r2   r,   )r;   r   r—   s   ` @r    ÚtestWriteCloseNotificationÚ)HalfCloseTests.testWriteCloseNotification=  s]   ù€ Ø�F‰FˆØ	�‰× Ñ ×4Ñ4Ô6ä×ÒäÔ@ÓAÜÔ<Ó=ðó
ˆð 	
�‰ÕVÔWØˆr#   )rû  rÃ   r  r—   ro   N)rG   rH   rI   rJ   rY   r·  rý  rº  r	  r)  r0  rK   rE   r#   r    rö  rö  ò  s%   † Ù(ò
òTòòò Nõ:r#   rö  c                   ó2   • \ rS rSrS rS rS rS rS rSr	g)	Ú0HalfCloseNoNotificationAndShutdownExceptionTestsiK  c                 óž  • [        5       =U l        n[        R                  " 5       U R                  l        [
        R                  " SUSS9=U l        n[        R                  " [
        [        5      R                  UR                  5       R                  UR                  5       R                  5      nUR                  U R                   5        U$ r¦   )rr   r—   r   r*   r_   r   r’   ro   r   rQ  r   r¾   r¡   r›  rO   r,   Ú
_gotClient)r;   r—   ro   r   s       r    r·  Ú6HalfCloseNoNotificationAndShutdownExceptionTests.setUpL  s“   € Ü$Ó&Ð&ˆŒ�Ü(-¯ªÓ(8ˆ�‰Ô%Ü×&Ò& q¨!°{ÑCÐCˆŒ�ô ×"Ò"¤7Ô,@ÓA×LÑLØ�I‰I‹K×Ñ˜aŸi™i›k×.Ñ.ó
ˆð 	
�‰�d—o‘oÔ&Øˆr#   c                 ó:   • Xl         U R                  R                  $ r   )rÃ   r—   r_   r  s     r    r5  Ú;HalfCloseNoNotificationAndShutdownExceptionTests._gotClientX  s   € ØŒð �v‰v×,Ñ,Ð,r#   c                 ó~   • U R                   R                  R                  5         U R                  R	                  5       $ r   )rÃ   r8   r9   ro   rQ   r:   s    r    rº  Ú9HalfCloseNoNotificationAndShutdownExceptionTests.tearDown_  s+   € Ø�‰×Ñ×,Ñ,Ô.Ø�v‰v×#Ñ#Ó%Ð%r#   c                 óÄ  ^ • T R                   R                  R                  S5        T R                   R                  R                  5         [        R
                  " 5       =T R                  R                  l        n[        R
                  " 5       =T R                   l        nUR                  U 4S j5        UR                  U 4S j5        [        R                  " X/5      $ )zË
TCP protocols support half-close connections, but not all of them
support being notified of write closes.  In this case, test that
half-closing the connection causes the peer's connection to be
closed.
r  c                 ód   >• TR                  TR                  R                  R                  S5      $ )Nr  )r¹   r—   ra   rí  r  s    €r    r  ÚUHalfCloseNoNotificationAndShutdownExceptionTests.testNoNotification.<locals>.<lambda>n  s"   ø€  × 0Ñ 0°·±×1DÑ1D×1IÑ1IÈ8Ô Tr#   c                 ób   >• TR                  TR                  R                  R                  5      $ r   ©r”   r—   ra   r  r  s    €r    r  r=  o  ó   ø€  §¡°·±×0CÑ0C×0JÑ0JÔ Kr#   )rÃ   r8   rá  r  r   r*   r—   ra   rl   r,   rÀ   ©r;   r   r1   s   `  r    ÚtestNoNotificationÚCHalfCloseNoNotificationAndShutdownExceptionTests.testNoNotificationc  s–   ø€ ð 	�‰×Ñ×#Ñ# HÔ-Ø�‰×Ñ×1Ñ1Ô3Ü16·²Ó1AÐAˆ�‰×ÑÔ*¨QÜ*/¯.ª.Ó*:Ð:ˆ�‰Ô" RØ	�‰ÔTÔUØ	�‰ÔKÔLÜ×"Ò" A 7Ó+Ð+r#   c                 óö  ^ • T R                   R                  R                  R                  5         T R                  R                  R                  S5        T R                  R                  R                  5         [        R                  " 5       =T R                   R                  l	        n[        R                  " 5       =T R                  l	        nUR                  U 4S j5        [        R                  " X/5      $ )z`
If the other side has already closed its connection,
loseWriteConnection should pass silently.
rÃ  c                 ób   >• TR                  TR                  R                  R                  5      $ r   r?  r  s    €r    r  ÚXHalfCloseNoNotificationAndShutdownExceptionTests.testShutdownException.<locals>.<lambda>|  r@  r#   )r—   ra   r8   r9   rÃ   rá  r  r   r*   rl   r,   rÀ   rA  s   `  r    ÚtestShutdownExceptionÚFHalfCloseNoNotificationAndShutdownExceptionTests.testShutdownExceptionr  s¥   ø€ ð
 	�‰×Ñ×%Ñ%×4Ñ4Ô6Ø�‰×Ñ×#Ñ# DÔ)Ø�‰×Ñ×1Ñ1Ô3Ü16·²Ó1AÐAˆ�‰×ÑÔ*¨QÜ*/¯.ª.Ó*:Ð:ˆ�‰Ô" RØ	�‰ÔKÔLÜ×"Ò" A 7Ó+Ð+r#   )rÃ   r—   ro   N)
rG   rH   rI   rJ   r·  r5  rº  rB  rG  rK   rE   r#   r    r3  r3  K  s   † ò
ò-ò&ò,õ,r#   r3  c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚHalfCloseBuggyApplicationTestsi€  zA
Test half-closing connections where notification code has bugs.
c                 óB  ^ • [        5       T l        [        R                  " 5       T R                  l        [
        R                  " ST R                  SS9T l        T R                  T R                  R                  5        T R                  R                  5       n[        R                  " [
        [        5      nUR                  UR                  UR                  5      nU 4S jnUR!                  U5        [        R"                  " T R                  R                  U/5      $ )zd
Set up a server and connect a client to it.  Return a Deferred which
only fires once this is done.
r   r�   r�   c                 ó   >• U Tl         g r   )r  )r  r;   s    €r    Ú	setClientÚ7HalfCloseBuggyApplicationTests.setUp.<locals>.setClient’  s   ø€ Ø"0ˆDÕr#   )rò  rÍ   r   r*   r_   r   r’   rO   r“   rQ   r¡   r   rQ  rè  r¾   r›  r,   rÀ   )r;   rn   ÚcreatorrŠ  rM  s   `    r    r·  Ú$HalfCloseBuggyApplicationTests.setUp…  sÐ   ø€ ô
 )›]ˆÔÜ49·N²NÓ4Dˆ×ÑÔ1Ü×%Ò% a¨×);Ñ);À{ÑSˆŒ	Ø�‰˜Ÿ	™	×/Ñ/Ô0Ø�y‰y× Ñ Ó"ˆÜ×(Ò(¬´,Ó?ˆØ ×+Ñ+¨D¯I©I°t·y±yÓAˆõ	1ð 	×"Ñ" 9Ô-Ü×"Ò"Ø×Ñ×6Ñ6¸ÐGó
ð 	
r#   c                 ó   • [        S5      e)zH
Fake implementation of a callback which illegally raises an
exception.
zONO I AM BUGGY CODErÙ   )r;   r£  s     r    ÚaBugÚ#HalfCloseBuggyApplicationTests.aBugš  s   € ô
 Ð0Ó1Ð1r#   c                 óÊ   ^ • [         R                  " 5       =nT R                  l        T R                  R                  R                  5         U 4S jnUR                  U5        U$ )zf
Helper for testing that an exception is logged by the time the
client protocol loses its connection.
c                 óf   >• TR                  [        5      nTR                  [        U5      S5        g r|   )ÚflushLoggedErrorsrÚ   r¹   rÇ  )r�   Úerrorsr;   s     €r    r!   ÚEHalfCloseBuggyApplicationTests._notificationRaisesTest.<locals>.check©  s'   ø€ Ø×+Ñ+¬LÓ9ˆFØ×ÑœS ›[¨!Õ,r#   )r   r*   r  rl   r8   r  r,   )r;   r  r!   s   `  r    Ú_notificationRaisesTestÚ6HalfCloseBuggyApplicationTests._notificationRaisesTest¡  sQ   ø€ ô
 7<·n²nÓ6FÐFˆ�×$Ñ$Ô3Ø×Ñ×%Ñ%×9Ñ9Ô;õ	-ð 	×Ñ˜5Ô!Øˆr#   c                 ól   • U R                   U R                  R                  l        U R	                  5       $ )zÃ
If C{readConnectionLost} raises an exception when the transport
calls it to notify the protocol of that event, the exception should
be logged and the protocol should be disconnected completely.
)rR  rÍ   ra   rì  rY  r:   s    r    Útest_readNotificationRaisesÚ:HalfCloseBuggyApplicationTests.test_readNotificationRaises°  s,   € ð >B¿Y¹Yˆ×Ñ×'Ñ'Ô:Ø×+Ñ+Ó-Ð-r#   c                 óX   • U R                   U R                  l        U R                  5       $ )zÄ
If C{writeConnectionLost} raises an exception when the transport
calls it to notify the protocol of that event, the exception should
be logged and the protocol should be disconnected completely.
)rR  r  rï  rY  r:   s    r    Útest_writeNotificationRaisesÚ;HalfCloseBuggyApplicationTests.test_writeNotificationRaises¹  s%   € ð 37·)±)ˆ×ÑÔ/Ø×+Ñ+Ó-Ð-r#   )r  rO   rÍ   N)rG   rH   rI   rJ   rY   r·  rR  rY  r\  r_  rK   rE   r#   r    rJ  rJ  €  s    † ñò
ò*2òò.õ.r#   rJ  c                   ó   • \ rS rSrSrS rSrg)ÚLogTestsiÃ  z,
Test logging facility of TCP base classes.
c                 ó2  ^ ^• [        5       n[        5       n[        R                  " 5       Ul        [
        R                  " SUSS9nT R                  UR                  5        [
        R                  " UR                  5       R                  UR                  5       R                  U5      mT R                  TR                  5        T R                  TR                  R                   S5        UU 4S jnUR                  R#                  U5        UR                  $ )z`
Check that the log customization of the client transport happens
once the client is connected.
r   r�   r�   ÚUninitializedc                 óR   >• TR                  TR                  R                  S5        g )NzAccumulatingProtocol,client)r¹   r8   Úlogstr)r¯   r   r;   s    €€r    ÚcbÚ+LogTests.test_logstrClientSetup.<locals>.cbÛ  s    ø€ Ø×Ñ˜Y×0Ñ0×7Ñ7Ð9VÕWr#   )rr   ru   r   r*   r_   r   r’   r“   rQ   r¾   r¡   r›  rO   r¿   r¹   r8   rf  r,   )r;   rÁ   rÃ   rO   rg  r   s   `    @r    Útest_logstrClientSetupÚLogTests.test_logstrClientSetupÈ  sÏ   ù€ ô
 !Ó"ˆä Ó"ˆÜ(-¯ªÓ(8ˆÔ%ä× Ò   F°kÑBˆØ�‰˜×*Ñ*Ô+ä×&Ò& t§|¡|£~×':Ñ':¸D¿L¹L»N×<OÑ<OÐQWÓXˆ	Ø�‰˜	×,Ñ,Ô-ð 	×Ñ˜×,Ñ,×3Ñ3°_ÔEö	Xð 	×%Ñ%×1Ñ1°"Ô5Ø×,Ñ,Ð,r#   rE   N)rG   rH   rI   rJ   rY   ri  rK   rE   r#   r    rb  rb  Ã  s   † ñõ-r#   rb  c                   ór   • \ rS rSrSr\" \R                  R                  \	5      (       + S5      S 5       r
Srg)ÚPauseProducingTestsiâ  z?
Test some behaviors of pausing the production of a transport.
z#Reactor not providing IReactorFDSetc                 óò  ^ ^• [        5       n[        5       n[        R                  " 5       Ul        [
        R                  " SUSS9nT R                  UR                  5        [
        R                  " UR                  5       R                  UR                  5       R                  U5      nT R                  UR                  5        UU 4S jnU 4S jmUR                  R                  U5        UR                  $ )z€
In C{connectionMade} of a client protocol, C{pauseProducing} used to be
ignored: this test is here to ensure it's not ignored.
r   r�   r�   c                 óÐ  >• U R                   nTR                  U[        R                  " 5       [        R                  " 5       -   5        U R                   R                  5         TR                  U[        R                  " 5       [        R                  " 5       -   5        [        R                  " 5       nUR                  T5        [        R                  " SUR                  U 5        U$ rÓ  )r8   ÚassertInr   Ú
getReadersÚ
getWritersr/  ÚassertNotInr   r*   r,   rÈ  r   )r4  Útrr   ÚcheckAfterConnectionMader;   s      €€r    ÚcheckInConnectionMadeÚVPauseProducingTests.test_pauseProducingInConnectionMade.<locals>.checkInConnectionMadeû  sœ   ø€ Ø—‘ˆBà�M‰M˜"œg×0Ò0Ó2´W×5GÒ5GÓ5IÑIÔJØ�O‰O×*Ñ*Ô,Ø×Ñ˜R¤×!3Ò!3Ó!5¼×8JÒ8JÓ8LÑ!LÔMÜ—’Ó ˆAØ�M‰MÐ2Ô3Ü×Ò˜a §¡¨UÔ3ØˆHr#   c                 ó”   >• U R                   nTR                  U[        R                  " 5       [        R                  " 5       -   5        g r   )r8   rr  r   rp  rq  )r4  rs  r;   s     €r    rt  ÚYPauseProducingTests.test_pauseProducingInConnectionMade.<locals>.checkAfterConnectionMade  s3   ø€ Ø—‘ˆBà×Ñ˜R¤×!3Ò!3Ó!5¼×8JÒ8JÓ8LÑ!LÕMr#   )rr   ru   r   r*   r_   r   r’   r“   rQ   r¾   r¡   r›  rO   r¿   r,   )r;   rÁ   rÃ   rO   r   ru  rt  s   `     @r    Ú#test_pauseProducingInConnectionMadeÚ7PauseProducingTests.test_pauseProducingInConnectionMadeç  s·   ù€ ô !Ó"ˆä Ó"ˆÜ(-¯ªÓ(8ˆÔ%ä× Ò   F°kÑBˆØ�‰˜×*Ñ*Ô+ä×&Ò& t§|¡|£~×':Ñ':¸D¿L¹L»N×<OÑ<OÐQWÓXˆ	Ø�‰˜	×,Ñ,Ô-ö		õ	Nð
 	×%Ñ%×1Ñ1Ð2GÔHØ×,Ñ,Ð,r#   rE   N)rG   rH   rI   rJ   rY   r   r
   ÚIReactorFDSetr•   r   ry  rK   rE   r#   r    rl  rl  â  s:   † ññ Ø×$Ñ$×/Ñ/°Ó8Ô8Ø-óñ!-ó	ó!-r#   rl  c                   ó   • \ rS rSrSrS rSrg)ÚCallBackOrderTestsi  z%
Test the order of reactor callbacks
c                 ó(  ^ ^	• [        5       n[        R                  " 5       R                  U 4S j5      Ul        [        5       m	[        R                  " 5       T	l        [        R                  " 5       T	l        U	4S jnT	R                  R                  U5        [        R                  " SUSS9nT R                  UR                  5        [        R                  " UR                  5       R                  UR                  5       R                  T	5      nT R                  UR                  5        S nS nU 4S jn[        R                   " T	R                  R                  U5      T	R"                  R                  U5      /5      nUR                  U5      $ )	zT
Check that Protocol.connectionLost is called before factory's
clientConnectionLost
c                 óN   >• TR                  U R                  R                  5      $ r   )r“   r8   r9   )r4  r;   s    €r    r  Ú3CallBackOrderTests.test_loseOrder.<locals>.<lambda>  s   ø€ ˜$Ÿ/™/¨%¯/©/×*HÑ*HÔIr#   c                 óp   >• [         R                  " STR                  R                  R                  5        g)z"
protocol.connectionMade callback
r   N)r   rÈ  ra   r8   r9   )r   rÃ   s    €r    Ú_cbCMÚ0CallBackOrderTests.test_loseOrder.<locals>._cbCM"  s'   ø€ ô ×Ò˜a ×!4Ñ!4×!>Ñ!>×!MÑ!MÕNr#   r   r�   r�   c                 ó   • g)z'
factory.clientConnectionLost callback
ÚCCLrE   ©r   s    r    Ú_cbCCLÚ1CallBackOrderTests.test_loseOrder.<locals>._cbCCL0  s   € ð r#   c                 ó   • g)z"
protocol.connectionLost callback
ÚCLrE   r†  s    r    Ú_cbCLÚ0CallBackOrderTests.test_loseOrder.<locals>._cbCL6  s   € ð r#   c                 ó.   >• TR                  U SS/5        g )NrŠ  r…  )r¹   )r   r;   s    €r    Ú	_cbGatherÚ4CallBackOrderTests.test_loseOrder.<locals>._cbGather<  s   ø€ Ø×Ñ˜S 4¨ -Õ0r#   )rr   r   r*   r,   r_   ru   r`   r   r’   r“   rQ   r¾   r¡   r›  rO   r¿   rÀ   rw   )
r;   rÁ   r‚  rO   r   r‡  r‹  rŽ  r   rÃ   s
   `        @r    Útest_loseOrderÚ!CallBackOrderTests.test_loseOrder  s0  ù€ ô
 !Ó"ˆÜ(-¯ªÓ(8×(DÑ(DÜIó)
ˆÔ%ô !Ó"ˆÜ(-¯ªÓ(8ˆÔ%Ü(-¯ªÓ(8ˆÔ%õ	Oð 	×%Ñ%×1Ñ1°%Ô8ä× Ò   F°kÑBˆØ�‰˜×*Ñ*Ô+ä×&Ò& t§|¡|£~×':Ñ':¸D¿L¹L»N×<OÑ<OÐQWÓXˆ	Ø�‰˜	×,Ñ,Ô-ò	ò	õ	1ô ×Òà×-Ñ-×9Ñ9¸%Ó@Ø—‘×+Ñ+¨FÓ3ðó
ˆð �}‰}˜YÓ'Ð'r#   rE   N)rG   rH   rI   rJ   rY   r�  rK   rE   r#   r    r}  r}    s   † ñõ1(r#   r}  r/  ÚnumberRounds)r   )XrY   rB  rO  rL  Ú	functoolsr   Útypingr   Úunittestr   Úzope.interfacer   rn  r)   r   r	   r
   r   r   Útwisted.internet.addressr   Útwisted.internet.interfacesr   r   Útwisted.internet.testingr   Útwisted.protocolsr   Útwisted.python.logr   r   Útwisted.python.runtimer   Útwisted.trial.unittestr   r   r2   rR  r4   r7  rM   r]   rr   r²  ru   rŒ   rù   r  rn  rx  rƒ  r—  rÎ  rÚ  rë  r÷  rþ  r<  rD  rL  rU  r\  rŽ  r˜  r–  r¢  r  r§  rÁ  rË  rÑ  rØ  rÜ  rà  rè  rò  rö  r3  rJ  rb  rl  r}  ÚresourceÚ	getrlimitÚRLIMIT_NOFILEÚ	numRoundsÚsetattrÚImportErrorrE   r#   r    Ú<module>r¤     s  ðñó
 Û Û Ý Ý Ý å &ã ç HÕ HÝ 0ß MÝ 9Ý &ß 'Ý +ß 5ôô8*�h×'Ñ'ô *ô"�X×+Ñ+ô "÷04ñ 4ônÐ,¨h×.DÑ.Dô ôÐ,¨h×.DÑ.Dô ô8DC�Xô DCôNa�Hô aôH�x×'Ñ'ô ô(˜_ô (ô(>2�8ô >2ôBl�hô lô^'˜hô 'ôT(�X×&Ñ&ô (ô.�X×&Ñ&ô ô	˜(×0Ñ0ô 	ôoN�Xô oNôd1˜x×0Ñ0ô 1ô�8×$Ñ$ô ô- h×&7Ñ&7ô -ô*AÐ:ô A÷ pñ pôf˜hÐ(?ô ô6
1˜×0Ñ0ô 
1ô-�8×+Ñ+ô -ô`
�8ô `
ôF) × 1Ñ 1ô )ô" × 1Ñ 1ô ô	 X×%;Ñ%;ô 	ô-�(×*Ñ*ô -ô)˜×1Ñ1ô )ô#$�xô #$ñL Ð#Ó$ô&Ð'ó &ó %ð&ô"	�(×(Ñ(ô 	ôV�Xô Vôr2,°xô 2,ôj@. Xô @.ôF-ˆxô -ô>*-˜(ô *-ôZ6(˜ô 6(ðr@Ûð ×"Ò" 8×#9Ñ#9Ó:¸1Ñ=ÀÑB€IÙÐ# ^°YÕ?øð	 ó 	Ùð	ús   Ë&L ÌL ÌL 