ó
    ×›‘h�  ã                   ó@  • S r SSKrSSKJr  SSKJrJrJr  SSKJ	r	J
r
JrJrJr  SSKJrJr  SSKJr  SSKJr   " S	 S
\R*                  5      r " S S\R.                  5      r " S S\R*                  5      r " S S\R4                  5      r " S S\R8                  5      r " S S\R<                  5      r " S S\R@                  5      r! " S S\RD                  5      r" " S S\R@                  5      r# " S S\R@                  5      r$ " S S\R@                  5      r% " S S \R*                  \RL                  5      r' " S! S"\R@                  5      r( " S# S$\R@                  5      r) " S% S&\5      r* " S' S(\RV                  5      r, " S) S*\R@                  5      r-g)+z
Test code for policies.
é    N)ÚStringIO)Ú	InterfaceÚimplementedByÚimplementer)ÚaddressÚdeferÚprotocolÚreactorÚtask)ÚStringTransportÚ StringTransportWithDisconnection)Úpolicies)Úunittestc                   ó8   • \ rS rSrS=rrSrS rS rS r	S r
Srg	)
ÚSimpleProtocolé   r   ó    c                 ól   • [         R                  " 5       U l        [         R                  " 5       U l        g ©N)r   ÚDeferredÚ
dConnectedÚdDisconnected©Úselfs    Ú^C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/test/test_policies.pyÚ__init__ÚSimpleProtocol.__init__   s   € ÜŸ.š.Ó*ˆŒÜ"Ÿ^š^Ó-ˆÕr   c                 óH   • SU l         U R                  R                  S5        g ©Né   Ú )Ú	connectedr   Úcallbackr   s    r   ÚconnectionMadeÚSimpleProtocol.connectionMade   s   € ØˆŒØ�‰× Ñ  Õ$r   c                 óH   • SU l         U R                  R                  S5        g r   )Údisconnectedr   r#   ©r   Úreasons     r   ÚconnectionLostÚSimpleProtocol.connectionLost    s   € ØˆÔØ×Ñ×#Ñ# BÕ'r   c                 ó.   • U =R                   U-  sl         g r   )Úbuffer©r   Údatas     r   ÚdataReceivedÚSimpleProtocol.dataReceived$   s   € Ø�Š�tÑŽr   )r"   r   r   r'   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__r"   r'   r-   r   r$   r*   r0   Ú__static_attributes__© r   r   r   r      s%   † Ø Ð €I�Ø€Fò.ò%ò(õr   r   c                   ó    • \ rS rSrS rS rSrg)ÚSillyFactoryé(   c                 ó   • Xl         g r   ©Úp)r   r=   s     r   r   ÚSillyFactory.__init__)   s   € Ø�r   c                 ó   • U R                   $ r   r<   )r   Úaddrs     r   ÚbuildProtocolÚSillyFactory.buildProtocol,   s   € Ø�v‰vˆr   r<   N)r2   r3   r4   r5   r   rA   r6   r7   r   r   r9   r9   (   s   † òõr   r9   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚEchoProtocolé0   Fc                 ó   • SU l         g ©NT©Úpausedr   s    r   ÚpauseProducingÚEchoProtocol.pauseProducing3   s	   € Øˆ�r   c                 ó   • SU l         g )NFrH   r   s    r   ÚresumeProducingÚEchoProtocol.resumeProducing6   s	   € Øˆ�r   c                 ó   • g r   r7   r   s    r   ÚstopProducingÚEchoProtocol.stopProducing9   s   € Ør   c                 ó:   • U R                   R                  U5        g r   )Ú	transportÚwriter.   s     r   r0   ÚEchoProtocol.dataReceived<   s   € Ø�‰×Ñ˜TÕ"r   rH   N)
r2   r3   r4   r5   rI   rJ   rM   rP   r0   r6   r7   r   r   rD   rD   0   s   † Ø€Fòòòõ#r   rD   c                   ó   • \ rS rSrSr\rSrg)ÚServeré@   z0
A simple server factory using L{EchoProtocol}.
r7   N)r2   r3   r4   r5   Ú__doc__rD   r	   r6   r7   r   r   rW   rW   @   s   † ñð ƒHr   rW   c                   ó$   • \ rS rSrSrS rS rSrg)ÚTestableThrottlingFactoryéH   z@
L{policies.ThrottlingFactory} using a L{task.Clock} for tests.
c                 óX   • [         R                  R                  " U /UQ70 UD6  Xl        g©zx
@param clock: object providing a callLater method that can be used
    for tests.
@type clock: C{task.Clock} or alike.
N)r   ÚThrottlingFactoryr   Úclock©r   r`   ÚargsÚkwargss       r   r   Ú"TestableThrottlingFactory.__init__M   s'   € ô 	×"Ñ"×+Ò+¨DÐB°4ÒB¸6ÒBØ�
r   c                 ó8   • U R                   R                  X5      $ ©z 
Forward to the testable clock.
©r`   Ú	callLater©r   ÚperiodÚfuncs      r   rh   Ú#TestableThrottlingFactory.callLaterV   ó   € ð �z‰z×#Ñ# FÓ1Ð1r   ©r`   N©r2   r3   r4   r5   rY   r   rh   r6   r7   r   r   r[   r[   H   ó   † ñòõ2r   r[   c                   ó$   • \ rS rSrSrS rS rSrg)ÚTestableTimeoutFactoryé]   z=
L{policies.TimeoutFactory} using a L{task.Clock} for tests.
c                 óX   • [         R                  R                  " U /UQ70 UD6  Xl        gr^   )r   ÚTimeoutFactoryr   r`   ra   s       r   r   ÚTestableTimeoutFactory.__init__b   s'   € ô 	×Ñ×(Ò(¨Ð?°Ò?¸Ò?Ø�
r   c                 ó8   • U R                   R                  X5      $ rf   rg   ri   s      r   rh   Ú TestableTimeoutFactory.callLaterk   rm   r   rn   Nro   r7   r   r   rr   rr   ]   rp   r   rr   c                   óx   • \ 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S rS rS rS rS rS rSrg)ÚWrapperTestsér   z6
Tests for L{WrappingFactory} and L{ProtocolWrapper}.
c                 óÞ   • [        5       n[        R                  " U5      nUR                  [        R
                  " SSS5      5      nU R                  UR                  R                  U5        g)zN
Make sure protocol.factory is the wrapped factory, not the wrapping
factory.
ÚTCPú	127.0.0.1é#   N)	rW   r   ÚWrappingFactoryrA   r   ÚIPv4AddressÚassertIsÚwrappedProtocolÚfactory)r   ÚfÚwfr=   s       r   Útest_protocolFactoryAttributeÚ*WrapperTests.test_protocolFactoryAttributew   sT   € ô
 ‹HˆÜ×%Ò% aÓ(ˆØ×ÑœW×0Ò0°¸ÀRÓHÓIˆØ�‰�a×'Ñ'×/Ñ/°Õ3r   c                 ó„  •  " S S[         5      n[        U5       " S S5      5       n[        [        R                  5        [
        R                  " 5       n[        R                  " [        R                  " S5      U5      nUR                  U" 5       5        U R                  UR                  UR                  5      5        g)z’
The transport wrapper passed to the wrapped protocol's
C{makeConnection} provides the same interfaces as are provided by the
original transport.
c                   ó   • \ rS rSrSrg)Ú=WrapperTests.test_transportInterfaces.<locals>.IStubTransportéˆ   r7   N©r2   r3   r4   r5   r6   r7   r   r   ÚIStubTransportr‹   ˆ   ó   † Úr   rŽ   c                   ó   • \ rS rSrSrg)Ú<WrapperTests.test_transportInterfaces.<locals>.StubTransporté‹   r7   Nr�   r7   r   r   ÚStubTransportr‘   ‹   s   † âr   r“   N)r   r   r   r   ÚProtocolWrapperr	   ÚProtocolr€   ÚmakeConnectionÚ
assertTrueÚ
providedByrS   )r   rŽ   r“   ÚprotoÚwrappers        r   Útest_transportInterfacesÚ%WrapperTests.test_transportInterfaces�   s’   € ô	œYô 	ô 
�^Ó	$÷	ð 	ó 
%ð	ô 	”h×.Ñ.Ô/ä×!Ò!Ó#ˆÜ×*Ò*¬8×+CÒ+CÀDÓ+IÈ5ÓQˆà×Ñ™}›Ô/Ø�‰˜×1Ñ1°%·/±/ÓBÕCr   c                 ó„   • [        5       n[        R                  " U5      nU R                  SUR	                  5       5        g)zk
L{WrappingFactory.logPrefix} is customized to mention both the original
factory and the wrapping factory.
zServer (WrappingFactory)N)rW   r   r€   ÚassertEqualÚ	logPrefix)r   Úserverr„   s      r   Útest_factoryLogPrefixÚ"WrapperTests.test_factoryLogPrefixž   s5   € ô
 “ˆÜ×*Ò*¨6Ó2ˆØ×ÑÐ3°W×5FÑ5FÓ5HÕIr   c                 ó’   •  " S S5      nU" 5       n[         R                  " U5      nU R                  SUR                  5       5        g)z
If the wrapped factory doesn't have a L{logPrefix} method,
L{WrappingFactory.logPrefix} falls back to the factory class name.
c                   ó   • \ rS rSrSrg)Ú=WrapperTests.test_factoryLogPrefixFallback.<locals>.NoFactoryé­   r7   Nr�   r7   r   r   Ú	NoFactoryr¥   ­   r�   r   r§   zNoFactory (WrappingFactory)N)r   r€   rž   rŸ   )r   r§   r    r„   s       r   Útest_factoryLogPrefixFallbackÚ*WrapperTests.test_factoryLogPrefixFallback§   s?   € ÷	ñ 	ñ “ˆÜ×*Ò*¨6Ó2ˆØ×ÑÐ6¸×8IÑ8IÓ8KÕLr   c                 óÔ   • [        5       n[        R                  " U5      nUR                  [        R
                  " SSS5      5      nU R                  SUR                  " 5       5        g)zc
L{ProtocolWrapper.logPrefix} is customized to mention both the original
protocol and the wrapper.
r}   r~   r   zEchoProtocol (ProtocolWrapper)N)rW   r   r€   rA   r   r�   rž   rŸ   )r   r    r„   r	   s       r   Útest_protocolLogPrefixÚ#WrapperTests.test_protocolLogPrefix´   sU   € ô
 “ˆÜ×*Ò*¨6Ó2ˆØ×(Ñ(¬×)<Ò)<¸UÀKÐQSÓ)TÓUˆØ×ÑÐ9¸8×;MÒ;MÓ;OÕPr   c                 óô   •  " S S5      n[        5       nXl        [        R                  " U5      nUR	                  [
        R                  " SSS5      5      nU R                  SUR                  " 5       5        g)z�
If the wrapped protocol doesn't have a L{logPrefix} method,
L{ProtocolWrapper.logPrefix} falls back to the protocol class name.
c                   ó   • \ rS rSrSrg)Ú?WrapperTests.test_protocolLogPrefixFallback.<locals>.NoProtocoléÄ   r7   Nr�   r7   r   r   Ú
NoProtocolr¯   Ä   r�   r   r±   r}   r~   r   zNoProtocol (ProtocolWrapper)N)	rW   r	   r   r€   rA   r   r�   rž   rŸ   )r   r±   r    r„   r	   s        r   Útest_protocolLogPrefixFallbackÚ+WrapperTests.test_protocolLogPrefixFallback¾   sd   € ÷	ñ 	ô “ˆØ$ŒÜ×*Ò*¨6Ó2ˆØ×(Ñ(¬×)<Ò)<¸UÀKÐQSÓ)TÓUˆØ×ÑÐ7¸×9KÒ9KÓ9MÕNr   c                 óÈ   • [         R                  " [         R                  " [        5       5      [        R
                  " 5       5      n[        5       nUR                  U5        U$ )zU
Return L{policies.ProtocolWrapper} that has been connected to a
L{StringTransport}.
)r   r”   r€   rW   r	   r•   r   r–   ©r   rš   rS   s      r   Ú_getWrapperÚWrapperTests._getWrapperÍ   sL   € ô
 ×*Ò*Ü×$Ò$¤V£XÓ.´×0AÒ0AÓ0Có
ˆô $Ó%ˆ	Ø×Ñ˜yÔ)Øˆr   c                 ó”   • U R                  5       nU R                  UR                  5       UR                  R                  5       5        g)zS
L{policies.ProtocolWrapper.getHost} calls C{getHost} on the underlying
transport.
N)r¶   rž   ÚgetHostrS   ©r   rš   s     r   Útest_getHostÚWrapperTests.test_getHostÙ   ó8   € ð
 ×"Ñ"Ó$ˆØ×Ñ˜Ÿ™Ó*¨G×,=Ñ,=×,EÑ,EÓ,GÕHr   c                 ó”   • U R                  5       nU R                  UR                  5       UR                  R                  5       5        g)zS
L{policies.ProtocolWrapper.getPeer} calls C{getPeer} on the underlying
transport.
N)r¶   rž   ÚgetPeerrS   rº   s     r   Útest_getPeerÚWrapperTests.test_getPeerá   r½   r   c                 óò   • U R                  5       n[        5       nUR                  US5        U R                  UR                  R
                  U5        U R                  UR                  R                  5        g)ze
L{policies.ProtocolWrapper.registerProducer} calls C{registerProducer}
on the underlying transport.
TN)r¶   ÚobjectÚregisterProducerr‚   rS   Úproducerr—   Ú	streaming©r   rš   rÅ   s      r   Útest_registerProducerÚ"WrapperTests.test_registerProduceré   s[   € ð
 ×"Ñ"Ó$ˆÜ“8ˆØ× Ñ  ¨4Ô0Ø�‰�g×'Ñ'×0Ñ0°(Ô;Ø�‰˜×)Ñ)×3Ñ3Õ4r   c                 ó  • U R                  5       n[        5       nUR                  US5        UR                  5         U R	                  UR
                  R                  5        U R	                  UR
                  R                  5        g)zi
L{policies.ProtocolWrapper.unregisterProducer} calls
C{unregisterProducer} on the underlying transport.
TN)r¶   rÃ   rÄ   ÚunregisterProducerÚassertIsNonerS   rÅ   rÆ   rÇ   s      r   Útest_unregisterProducerÚ$WrapperTests.test_unregisterProducerô   si   € ð
 ×"Ñ"Ó$ˆÜ“8ˆØ× Ñ  ¨4Ô0Ø×"Ñ"Ô$Ø×Ñ˜'×+Ñ+×4Ñ4Ô5Ø×Ñ˜'×+Ñ+×5Ñ5Õ6r   c                 óš   ^• U R                  5       n/ mU4S jUR                  l        UR                  5         U R                  TS/5        g)z_
L{policies.ProtocolWrapper.stopConsuming} calls C{stopConsuming} on
the underlying transport.
c                  ó&   >• T R                  S5      $ rG   ©Úappend©Úresults   €r   Ú<lambda>Ú1WrapperTests.test_stopConsuming.<locals>.<lambda>  s   ø€ °&·-±-ÀÔ2Er   TN)r¶   rS   ÚstopConsumingrž   )r   rš   rÔ   s     @r   Útest_stopConsumingÚWrapperTests.test_stopConsuming   sD   ø€ ð
 ×"Ñ"Ó$ˆØˆÜ*Eˆ×ÑÔ'Ø×ÑÔØ×Ñ˜ $ Õ(r   c                 ó¶   ^• / m " U4S jS5      n[         R                  " U" 5       5      n[        5       nUR                  U5        U R	                  TU/5        g)ze
L{policies.WrappingFactory.startedConnecting} calls
C{startedConnecting} on the underlying factory.
c                   ó"   >• \ rS rSrU 4S jrSrg)Ú4WrapperTests.test_startedConnecting.<locals>.Factoryi  c                 ó(   >• TR                  U5        g r   rÑ   )r   Ú	connectorrÔ   s     €r   ÚstartedConnectingÚFWrapperTests.test_startedConnecting.<locals>.Factory.startedConnecting  s   ø€ Ø—‘˜iÕ(r   r7   N)r2   r3   r4   r5   rß   r6   rÓ   s   €r   ÚFactoryrÜ     s   ø† ÷)ð )r   rá   N)r   r€   rÃ   rß   rž   )r   rá   rš   rÞ   rÔ   s       @r   Útest_startedConnectingÚ#WrapperTests.test_startedConnecting  sO   ø€ ð
 ˆ÷	)ô 	)ô ×*Ò*©7«9Ó5ˆÜ“Hˆ	Ø×!Ñ! )Ô,Ø×Ñ˜ ) Õ-r   c                 óÌ   ^• / m " U4S jS5      n[         R                  " U" 5       5      n[        5       n[        5       nUR                  X45        U R	                  TX44/5        g)zk
L{policies.WrappingFactory.clientConnectionLost} calls
C{clientConnectionLost} on the underlying factory.
c                   ó"   >• \ rS rSrU 4S jrSrg)Ú7WrapperTests.test_clientConnectionLost.<locals>.Factoryi"  c                 ó*   >• TR                  X45        g r   rÑ   ©r   rÞ   r)   rÔ   s      €r   ÚclientConnectionLostÚLWrapperTests.test_clientConnectionLost.<locals>.Factory.clientConnectionLost#  ó   ø€ Ø—‘˜yÐ1Õ2r   r7   N)r2   r3   r4   r5   ré   r6   rÓ   s   €r   rá   ræ   "  ó   ø† ÷3ð 3r   rá   N)r   r€   rÃ   ré   rž   ©r   rá   rš   rÞ   r)   rÔ   s        @r   Útest_clientConnectionLostÚ&WrapperTests.test_clientConnectionLost  sZ   ø€ ð
 ˆ÷	3ô 	3ô ×*Ò*©7«9Ó5ˆÜ“Hˆ	Ü“ˆØ×$Ñ$ YÔ7Ø×Ñ˜ 9Ð"5Ð!6Õ7r   c                 óÌ   ^• / m " U4S jS5      n[         R                  " U" 5       5      n[        5       n[        5       nUR                  X45        U R	                  TX44/5        g)zo
L{policies.WrappingFactory.clientConnectionFailed} calls
C{clientConnectionFailed} on the underlying factory.
c                   ó"   >• \ rS rSrU 4S jrSrg)Ú9WrapperTests.test_clientConnectionFailed.<locals>.Factoryi3  c                 ó*   >• TR                  X45        g r   rÑ   rè   s      €r   ÚclientConnectionFailedÚPWrapperTests.test_clientConnectionFailed.<locals>.Factory.clientConnectionFailed4  rë   r   r7   N)r2   r3   r4   r5   rô   r6   rÓ   s   €r   rá   rò   3  rì   r   rá   N)r   r€   rÃ   rô   rž   rí   s        @r   Útest_clientConnectionFailedÚ(WrapperTests.test_clientConnectionFailed,  sZ   ø€ ð
 ˆ÷	3ô 	3ô ×*Ò*©7«9Ó5ˆÜ“Hˆ	Ü“ˆØ×&Ñ& yÔ9Ø×Ñ˜ 9Ð"5Ð!6Õ7r   c                 ó^  • [         R                  " [         R                  " [        5       5      [        R
                  " 5       5      n[        5       nXl        UR                  U5        U R                  UR                  5        UR                  5         U R                  UR                  5        g)z˜
L{policies.ProtocolWrapper.connectionLost} sets C{wrappedProtocol} to
C{None} in order to break reference cycle between wrapper and wrapped
protocols.
N)r   r”   r€   rW   r	   r•   r   r–   ÚassertIsNotNonerƒ   ÚloseConnectionrÌ   rµ   s      r   Útest_breakReferenceCycleÚ%WrapperTests.test_breakReferenceCycle=  s�   € ô ×*Ò*Ü×$Ò$¤V£XÓ.´×0AÒ0AÓ0Có
ˆô 5Ó6ˆ	Ø$ÔØ×Ñ˜yÔ)à×Ñ˜W×4Ñ4Ô5Ø× Ñ Ô"Ø×Ñ˜'×1Ñ1Õ2r   r7   N)r2   r3   r4   r5   rY   r‡   r›   r¡   r¨   r«   r²   r¶   r»   rÀ   rÈ   rÍ   rØ   râ   rî   rö   rû   r6   r7   r   r   rz   rz   r   s^   † ñò4òDò:JòMòQòOò
òIòIò	5ò
7ò	)ò.ò 8ò"8õ"3r   rz   c                   ó    • \ rS rSrS rS rSrg)r€   iO  c                 ó   • U$ r   r7   )r   r…   r=   s      r   r	   ÚWrappingFactory.protocolP  s   € Øˆr   c                 óx   • [         R                  R                  U 5        U R                  R	                  S 5        g r   )r   r€   ÚstartFactoryÚdeferredr#   r   s    r   r  ÚWrappingFactory.startFactoryS  s(   € Ü× Ñ ×-Ñ-¨dÔ3Ø�‰×Ñ˜tÕ$r   r7   N)r2   r3   r4   r5   r	   r  r6   r7   r   r   r€   r€   O  s   † òõ%r   r€   c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚThrottlingTestsiX  z*
Tests for L{policies.ThrottlingFactory}.
c                 óæ  ^ ^	^
^^^^^• [        5       nS [        S5       5       u  m	m
mm[        R                  " US5      m[	        T5      n[
        R                  " 5       Ul        [        R                  " SUSS9mTR                  5       R                  mU	U
UU4S jnU	U
UU U4S jnU	4S	 jnUU4S
 jnUU 4S jnU
UU4S jnUR                  R                  U5        UR                  R                  U5        UR                  R                  U5        UR                  R                  U5        UR                  R                  U5        UR                  R                  U5        UR                  $ )z‹
Full test using a custom server limiting number of connections.

FIXME: https://twistedmatrix.com/trac/ticket/10012
This is a flaky test.
c              3   ó6   #   • U  H  n[        5       v •  M     g 7fr   )r   )Ú.0Úis     r   Ú	<genexpr>Ú-ThrottlingTests.test_limit.<locals>.<genexpr>e  s   é € Ð=²H¨qœ.×*Ð*²Hùs   ‚é   é   r   r~   )Ú	interfacec                 óÞ   >• [         R                  " ST[        T5      5        TR                  R	                  UU4S j5        TR                  R	                  UU4S j5        TR
                  $ )Nr~   c                 óF   >• [         R                  " ST[        T5      5      $ ©Nr~   ©r
   Ú
connectTCPr9   )ÚrÚc2Úns    €€r   rÕ   ÚAThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>q  ó   ø€ œ'×,Ò,¨[¸!¼\È"Ó=MÔNr   c                 óF   >• [         R                  " ST[        T5      5      $ r  r  )r  Úc3r  s    €€r   rÕ   r  t  r  r   )r
   r  r9   r   ÚaddCallbackr   )ÚresultsÚc1r  r  r  s    €€€€r   Ú_connect123Ú/ThrottlingTests.test_limit.<locals>._connect123n  sT   ø€ Ü×Ò˜{¨A¬|¸BÓ/?Ô@Ø�M‰M×%Ñ%ÝNôð �M‰M×%Ñ%ÝNôð ×#Ñ#Ð#r   c                 óF  >• TR                  TTT4 Vs/ s H  oR                  PM     sn/ SQ5        TR                  TTT4 Vs/ s H  oR                  PM     sn/ SQ5        TR                  [        TR                  R                  5       5      S5        U $ s  snf s  snf )N)r    r    r    )r   r   r    r  )rž   r"   r'   ÚlenÚ	protocolsÚkeys)r  Úcr  r  r  r   ÚtServers     €€€€€r   Ú	_check123Ú-ThrottlingTests.test_limit.<locals>._check123x  sƒ   ø€ Ø×Ñ°B¸¸B±<Ó@²<¨aŸkœk±<Ñ@Â)ÔLØ×Ñ°r¸2¸r±lÓC²l°Ÿnœn±lÑCÂYÔOØ×ÑœS ×!2Ñ!2×!7Ñ!7Ó!9Ó:¸AÔ>ØˆNùò AùÚCs   ”BÁBc                 óP   >• TR                   R                  5         TR                  $ r   )rS   rú   r   )r  r  s    €r   Ú_lose1Ú*ThrottlingTests.test_limit.<locals>._lose1~  s   ø€ à�L‰L×'Ñ'Ô)Ø×#Ñ#Ð#r   c                 ó^   >• [         R                  " ST[        T5      5        TR                  $ r  )r
   r  r9   r   )r  Úc4r  s    €€r   Ú	_connect4Ú-ThrottlingTests.test_limit.<locals>._connect4ƒ  s$   ø€ Ü×Ò˜{¨A¬|¸BÓ/?Ô@Ø—=‘=Ð r   c                 óx   >• TR                  TR                  S5        TR                  TR                  S5        U $ )Nr    r   )rž   r"   r'   )r  r,  r   s    €€r   Ú_check4Ú+ThrottlingTests.test_limit.<locals>._check4‡  s0   ø€ Ø×Ñ˜RŸ\™\¨1Ô-Ø×Ñ˜RŸ_™_¨aÔ0ØˆNr   c                 óä   >• TT4 H  nUR                   R                  5         M     [        R                  " [        R                  " TR
                  5      TR                  TR                  /5      $ r   )rS   rú   r   ÚDeferredListÚmaybeDeferredÚstopListeningr   )r  r$  r  r,  r=   s     €€€r   Ú_cleanupÚ,ThrottlingTests.test_limit.<locals>._cleanupŒ  s]   ø€ Ø˜“V�Ø—‘×*Ñ*Ö,ñ ä×%Ò%ä×'Ò'¨¯©Ó8Ø×$Ñ$Ø×$Ñ$ðóð r   )rW   Úranger   r_   r€   r   r   r  r
   Ú	listenTCPr¹   Úportr  )r   r    ÚwrapTServerr  r&  r)  r-  r0  r6  r  r  r  r,  r  r=   r%  s   `        @@@@@@@r   Ú
test_limitÚThrottlingTests.test_limit]  s"  ÿ€ ô “ˆÙ=´E¸!´HÓ=‰ˆˆB��BÜ×,Ò,¨V°QÓ7ˆÜ% gÓ.ˆÜ$Ÿ~š~Ó/ˆÔô ×Ò˜a ¸ÑDˆØ�I‰I‹K×Ñˆ÷	$ð 	$÷	ñ 	õ	$ö
	!ö	÷
		ð 	×Ñ×(Ñ(¨Ô5Ø×Ñ×(Ñ(¨Ô3Ø×Ñ×(Ñ(¨Ô0Ø×Ñ×(Ñ(¨Ô3Ø×Ñ×(Ñ(¨Ô1Ø×Ñ×(Ñ(¨Ô2Ø×#Ñ#Ð#r   c                 óŒ  • [        5       n[        [        R                  " 5       U5      nUR	                  [
        R                  " SSS5      5      n[        5       nX4l        UR                  " U5        UR                  " S/S-  5        U R                  UR                  5       S5        U R                  UR                  S5        g)	zJ
L{ThrottlingProtocol.writeSequence} is called on the underlying factory.
r}   r~   r   ó   bytesr  s   bytesbytesbytesbytesr   N)rW   r[   r   ÚClockrA   r   r�   r   r	   r–   ÚwriteSequencerž   ÚvalueÚwrittenThisSecond)r   r    r%  r	   rS   s        r   Útest_writeSequenceÚ"ThrottlingTests.test_writeSequenceŸ  s›   € ô “ˆÜ+¬D¯JªJ«L¸&ÓAˆØ×(Ñ(¬×)<Ò)<¸UÀKÐQRÓ)SÓTˆÜ4Ó6ˆ	Ø%ÔØ×Ò 	Ô*à×Ò ˜z¨A™~Ô.Ø×Ñ˜Ÿ™Ó*Ð,CÔDØ×Ñ˜×2Ñ2°BÕ7r   c                 ó|  • [        5       n[        [        R                  " 5       USS9nUR	                  [
        R                  " SSS5      5      n[        5       nX4l        UR                  U5        UR                  Ul        UR                  S5        UR                  S5        U R                  UR                  5       S5        U R                  UR                  S	5        U R!                  UR                  R"                  5        UR$                  R'                  S
5        U R                  UR                  S5        U R)                  UR                  R"                  5        UR$                  R'                  S
5        U R                  UR                  S5        U R!                  UR                  R"                  5        g)zM
Check the writeLimit parameter: write data, and check for the pause
status.
é
   )Ú
writeLimitr}   r~   r   ó
   0123456789ó
   abcdefghijó   0123456789abcdefghijr   çÍÌÌÌÌÌð?N)rW   r[   r   r@  rA   r   r�   r   r	   r–   rƒ   rÅ   r0   rž   rB  rC  ÚassertFalserI   r`   Úadvancer—   ©r   r    r%  r:  Útrs        r   Útest_writeLimitÚThrottlingTests.test_writeLimit®  sM  € ô
 “ˆÜ+¬D¯JªJ«L¸&ÈRÑPˆØ×$Ñ$¤W×%8Ò%8¸ÀÈQÓ%OÓPˆÜ-Ó/ˆØŒØ×Ñ˜BÔØ×,Ñ,ˆŒà×Ñ˜-Ô(Ø×Ñ˜-Ô(Ø×Ñ˜Ÿ™›Ð%<Ô=Ø×Ñ˜×2Ñ2°BÔ7Ø×Ñ˜×-Ñ-×4Ñ4Ô5ð
 	�‰×Ñ˜dÔ#Ø×Ñ˜×2Ñ2°AÔ6Ø�‰˜×,Ñ,×3Ñ3Ô4à�‰×Ñ˜dÔ#Ø×Ñ˜×2Ñ2°AÔ6Ø×Ñ˜×-Ñ-×4Ñ4Õ5r   c                 ó  • [        5       n[        [        R                  " 5       USS9nUR	                  [
        R                  " SSS5      5      n[        5       nX4l        UR                  U5        UR                  S5        UR                  S5        U R                  UR                  5       S5        U R                  UR                  S	5        UR                  R                  S
5        U R                  UR                  S5        U R                  UR                   S5        UR                  R                  S
5        U R                  UR                  S5        U R                  UR                   S5        UR#                  5         UR                  S5        UR                  S5        U R                  UR                  5       S5        U R                  UR                  S	5        UR                  R                  S
5        U R                  UR                  S5        U R                  UR                   S5        UR                  R                  S
5        U R                  UR                  S5        U R                  UR                   S5        g)zJ
Check the readLimit parameter: read data and check for the pause
status.
rG  )Ú	readLimitr}   r~   r   rI  rJ  rK  r   rL  rI   Ú	producingN)rW   r[   r   r@  rA   r   r�   r   r	   r–   r0   rž   rB  ÚreadThisSecondr`   rN  ÚproducerStateÚclearrO  s        r   Útest_readLimitÚThrottlingTests.test_readLimitÌ  sì  € ô
 “ˆÜ+¬D¯JªJ«L¸&ÈBÑOˆØ×$Ñ$¤W×%8Ò%8¸ÀÈQÓ%OÓPˆÜ-Ó/ˆØŒØ×Ñ˜BÔà×Ñ˜-Ô(Ø×Ñ˜-Ô(Ø×Ñ˜Ÿ™›Ð%<Ô=Ø×Ñ˜×/Ñ/°Ô4à�‰×Ñ˜dÔ#Ø×Ñ˜×/Ñ/°Ô3Ø×Ñ˜×)Ñ)¨8Ô4à�‰×Ñ˜dÔ#Ø×Ñ˜×/Ñ/°Ô3Ø×Ñ˜×)Ñ)¨;Ô7à
�‰Œ
Ø×Ñ˜-Ô(Ø×Ñ˜-Ô(Ø×Ñ˜Ÿ™›Ð%<Ô=Ø×Ñ˜×/Ñ/°Ô4à�‰×Ñ˜dÔ#Ø×Ñ˜×/Ñ/°Ô3Ø×Ñ˜×)Ñ)¨8Ô4à�‰×Ñ˜dÔ#Ø×Ñ˜×/Ñ/°Ô3Ø×Ñ˜×)Ñ)¨;Õ7r   r7   N)
r2   r3   r4   r5   rY   r<  rD  rQ  rY  r6   r7   r   r   r  r  X  s   † ñò@$òD8ò6õ<%8r   r  c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚTimeoutProtocolTestsiô  z(
Tests for L{policies.TimeoutProtocol}.
c                 ó  • [         R                  " 5       n[        R                  " 5       n[        Ul        [        XS5      nUR                  [        R                  " SSS5      5      n[        5       nXEl        UR                  U5        XA4$ )z®
Helper to set up an already connected protocol to be tested.

@return: A new protocol with its attached clock.
@rtype: Tuple of (L{policies.TimeoutProtocol}, L{task.Clock})
Nr}   r~   é90  )r   r@  r	   ÚServerFactoryr   rr   rA   r   r�   r   r–   )r   r`   ÚwrappedFactoryr„   r™   rS   s         r   ÚgetProtocolAndClockÚ(TimeoutProtocolTests.getProtocolAndClockù  st   € ô —
’
“ˆä!×/Ò/Ó1ˆÜ"0ˆÔä(¨ÀÓEˆà×%Ñ%¤g×&9Ò&9¸%ÀÈeÓ&TÓUˆä4Ó6ˆ	Ø"ÔØ×Ñ˜YÔ'àˆ~Ðr   c                 ó®  • U R                  5       u  pUR                  S5        U R                  UR                  5        U R	                  UR
                  R                  5        UR                  S5        UR                  5         U R                  UR                  5        UR                  S5        U R	                  UR
                  R                  5        g)z"
Will cancel the ongoing timeout.
é   r    N)
ra  Ú
setTimeoutrù   ÚtimeoutCallrM  rƒ   r'   rN  ÚcancelTimeoutrÌ   ©r   Úsutr`   s      r   Útest_cancelTimeoutÚ'TimeoutProtocolTests.test_cancelTimeout  sž   € ð ×-Ñ-Ó/‰
ˆØ�‰�qÔà×Ñ˜SŸ_™_Ô-Ø×Ñ˜×,Ñ,×9Ñ9Ô:à�‰�aÔØ×ÑÔà×Ñ˜#Ÿ/™/Ô*ð 	�‰�aÔØ×Ñ˜×,Ñ,×9Ñ9Õ:r   c                 óÈ   • U R                  5       u  pU R                  UR                  5        UR                  5         U R	                  UR
                  R                  5        g)z,
Does nothing if no timeout is already set.
N)ra  rÌ   rf  rg  rM  rƒ   r'   rh  s      r   Útest_cancelTimeoutNoTimeoutÚ0TimeoutProtocolTests.test_cancelTimeoutNoTimeout"  sN   € ð ×-Ñ-Ó/‰
ˆØ×Ñ˜#Ÿ/™/Ô*à×ÑÔð 	×Ñ˜×,Ñ,×9Ñ9Õ:r   c                 óÚ   • U R                  5       u  pUR                  nUR                  S5        UR                  S5        U R	                  UR
                  5        UR                  5         g)z0
Does nothing if no timeout is already reached.
rd  N)ra  rƒ   re  rN  r—   r'   rg  )r   ri  r`   ÚwrappedProtos       r   Útest_cancelTimeoutAlreadyCalledÚ4TimeoutProtocolTests.test_cancelTimeoutAlreadyCalled.  sW   € ð ×-Ñ-Ó/‰
ˆØ×*Ñ*ˆØ�‰�qÔà�‰�aÔØ�‰˜×1Ñ1Ô2ð 	×ÑÕr   c                 óè   • U R                  5       u  pUR                  S5        UR                  R                  5         UR	                  5         U R                  UR                  R                  5        g)zU
Does nothing if the timeout is cancelled from another part.
Ex from another thread.
rd  N)ra  re  rf  Úcancelrg  rM  rƒ   r'   rh  s      r   Ú"test_cancelTimeoutAlreadyCancelledÚ7TimeoutProtocolTests.test_cancelTimeoutAlreadyCancelled<  sX   € ð
 ×-Ñ-Ó/‰
ˆØ�‰�qÔà�‰×ÑÔ ð 	×ÑÔà×Ñ˜×,Ñ,×9Ñ9Õ:r   r7   N)r2   r3   r4   r5   rY   ra  rj  rm  rq  ru  r6   r7   r   r   r\  r\  ô  s    † ñòò,;ò&
;òõ;r   r\  c                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚTimeoutFactoryTestsiL  z'
Tests for L{policies.TimeoutFactory}.
c                 óð  • [         R                  " 5       U l        [        R                  " 5       n[
        Ul        [        U R                  US5      U l        U R                  R                  [        R                  " SSS5      5      U l        [        5       U l        U R                  U R                  l        U R                  R                  U R                  5        U R                  R                  U l        g)zY
Create a testable, deterministic clock, and a set of
server factory/protocol/transport.
rd  r}   r~   r^  N)r   r@  r`   r	   r_  r   rr   r„   rA   r   r�   r™   r   rS   r–   rƒ   rp  )r   r`  s     r   ÚsetUpÚTimeoutFactoryTests.setUpQ  s§   € ô
 —Z’Z“\ˆŒ
Ü!×/Ò/Ó1ˆÜ"0ˆÔÜ-¨d¯j©j¸.È!ÓLˆŒØ—\‘\×/Ñ/Ü×Ò  {°EÓ:ó
ˆŒ
ô :Ó;ˆŒØ"&§*¡*ˆ�‰ÔØ�
‰
×!Ñ! $§.¡.Ô1Ø ŸJ™J×6Ñ6ˆÕr   c                 ó  • U R                   R                  / SQ5        U R                  U R                  R                  5        U R                   R                  SS/5        U R                  U R                  R                  5        g)z–
Make sure that when a TimeoutFactory accepts a connection, it will
time out that connection if no data is read or written within the
timeout period.
)ç        ç      à?ç      ð?r  gš™™™™™Ù?r}  çš™™™™™É?N)r`   ÚpumprM  rp  r'   r—   r   s    r   Útest_timeoutÚ TimeoutFactoryTests.test_timeoutb  s]   € ð 	�
‰
�‰Ò1Ô2Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
�‰˜˜c˜
Ô#Ø�‰˜×)Ñ)×6Ñ6Õ7r   c                 óˆ  • U R                   R                  / SQ5        U R                  U R                  R                  5        U R
                  R                  S5        U R                   R                  / SQ5        U R                  U R                  R                  5        U R
                  R                  S/S-  5        U R                   R                  / SQ5        U R                  U R                  R                  5        U R                   R                  SS/5        U R                  U R                  R                  5        g)	zz
Make sure that writing data to a transport from a protocol
constructed by a TimeoutFactory resets the timeout countdown.
)r}  r~  r  ó   bytes bytes bytes©r}  r  r  r?  rd  r}  g       @N)	r`   r�  rM  rp  r'   r™   rT   rA  r—   r   s    r   Útest_sendAvoidsTimeoutÚ*TimeoutFactoryTests.test_sendAvoidsTimeoutp  sã   € ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
×ÑÐ-Ô.ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
× Ñ  ( ¨a¡Ô0ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
�‰˜˜c˜
Ô#Ø�‰˜×)Ñ)×6Ñ6Õ7r   c                 óÆ  • U R                   R                  / SQ5        U R                  U R                  R                  5        U R
                  R                  S5        U R                   R                  / SQ5        U R                  U R                  R                  5        U R                   R                  / SQ5        U R                  U R                  R                  5        g)zB
Make sure that receiving data also resets the timeout countdown.
)r}  r  r~  r…  r†  N)r`   r�  rM  rp  r'   r™   r0   r—   r   s    r   Útest_receiveAvoidsTimeoutÚ-TimeoutFactoryTests.test_receiveAvoidsTimeoutŒ  s™   € ð
 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
×ÑÐ 4Ô5ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
�‰šÔ(Ø�‰˜×)Ñ)×6Ñ6Õ7r   )r`   r„   r™   rS   rp  N)
r2   r3   r4   r5   rY   rz  r‚  r‡  rŠ  r6   r7   r   r   rx  rx  L  s   † ñò7ò"8ò8õ88r   rx  c                   óH   • \ rS rSrSrSrSrS rS rS r	SS	 jr
S
 rS rSrg)ÚTimeoutTesteri¡  z„
A testable protocol with timeout facility.

@ivar timedOut: set to C{True} if a timeout has been detected.
@type timedOut: C{bool}
rd  Fc                 ó   • Xl         g)z6
Initialize the protocol with a C{task.Clock} object.
Nrn   )r   r`   s     r   r   ÚTimeoutTester.__init__¬  s	   € ð �
r   c                 ó:   • U R                  U R                  5        g)z#
Upon connection, set the timeout.
N)re  ÚtimeOutr   s    r   r$   ÚTimeoutTester.connectionMade²  s   € ð 	�‰˜Ÿ™Õ%r   c                 ób   • U R                  5         [        R                  R                  X5        g)z
Reset the timeout on data.
N)ÚresetTimeoutr	   r•   r0   r.   s     r   r0   ÚTimeoutTester.dataReceived¸  s$   € ð 	×ÑÔÜ×Ñ×&Ñ& tÕ2r   Nc                 ó&   • U R                  S5        g)z4
On connection lost, cancel all timeout operations.
N)re  r(   s     r   r*   ÚTimeoutTester.connectionLost¿  s   € ð 	�‰˜Õr   c                 ó   • SU l         g)zH
Flags the timedOut variable to indicate the timeout of the connection.
TN)ÚtimedOutr   s    r   ÚtimeoutConnectionÚTimeoutTester.timeoutConnectionÅ  s   € ð ˆ�r   c                 óB   • U R                   R                  " X/UQ70 UD6$ )z4
Override callLater to use the deterministic clock.
rg   )r   Útimeoutrk   rb   rc   s        r   rh   ÚTimeoutTester.callLaterË  s#   € ð �z‰z×#Ò# GÐC°DÒC¸FÑCÐCr   )r`   r™  r   )r2   r3   r4   r5   rY   r‘  r™  r   r$   r0   r*   rš  rh   r6   r7   r   r   r�  r�  ¡  s2   † ñð €GØ€Hòò&ò3ôòõDr   r�  c                   óH   • \ 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)ÚTimeoutMixinTestsiÒ  z%
Tests for L{policies.TimeoutMixin}.
c                 ól   • [         R                  " 5       U l        [        U R                  5      U l        g)zI
Create a testable, deterministic clock and a C{TimeoutTester} instance.
N)r   r@  r`   r�  r™   r   s    r   rz  ÚTimeoutMixinTests.setUp×  s!   € ô —Z’Z“\ˆŒ
Ü" 4§:¡:Ó.ˆ�
r   c                 ó˜   • U R                   R                  S5        U R                  [        U R                  R
                  5      S5        g)z‚
Test that the callLater of the clock is used instead of
L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
rG  r    N)r™   re  rž   r!  r`   Úcallsr   s    r   Útest_overriddenCallLaterÚ*TimeoutMixinTests.test_overriddenCallLaterÞ  s5   € ð
 	�
‰
×Ñ˜bÔ!Ø×Ñœ˜TŸZ™Z×-Ñ-Ó.°Õ2r   c                 óR  • U R                   R                  [        5       5        U R                  R	                  / SQ5        U R                  U R                   R                  5        U R                  R	                  SS/5        U R                  U R                   R                  5        g)zY
Check that the protocol does timeout at the time specified by its
C{timeOut} attribute.
©r   r~  r  r  r   r  N)r™   r–   r   r`   r�  rM  r™  r—   r   s    r   r‚  ÚTimeoutMixinTests.test_timeoutæ  sn   € ð
 	�
‰
×!Ñ!¤/Ó"3Ô4ð 	�
‰
�‰Ò*Ô+Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
�‰˜˜C˜Ô!Ø�‰˜Ÿ
™
×+Ñ+Õ,r   c                 ó  • U R                   R                  [        5       5        U R                  R	                  / SQ5        U R                  U R                   R                  5        U R                   R                  S5        U R                  R	                  / SQ5        U R                  U R                   R                  5        U R                  R	                  SS/5        U R                  U R                   R                  5        g)zF
Check that receiving data is delaying the timeout of the connection.
r¨  s   hello there)r   r  r  r~  r   r  N)	r™   r–   r   r`   r�  rM  r™  r0   r—   r   s    r   Útest_noTimeoutÚ TimeoutMixinTests.test_noTimeoutó  s§   € ð 	�
‰
×!Ñ!¤/Ó"3Ô4à�
‰
�‰Ò*Ô+Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
×Ñ Ô/Ø�
‰
�‰Ò*Ô+Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
�‰˜˜C˜Ô!Ø�‰˜Ÿ
™
×+Ñ+Õ,r   c                 óö  • SU R                   l        U R                   R                  [        5       5        U R                   R	                  S5        U R                  U R                   R                  S5        U R                  R                  SS/5        U R                  U R                   R                  5        U R                  R                  SS/5        U R                  U R                   R                  5        g)za
Check that setting a new value for timeout cancel the previous value
and install a new timeout.
Nr    r   gÍÌÌÌÌÌì?r€  )r™   r‘  r–   r   re  rž   r`   r�  rM  r™  r—   r   s    r   Útest_resetTimeoutÚ#TimeoutMixinTests.test_resetTimeout  s§   € ð
 "ˆ�
‰
ÔØ�
‰
×!Ñ!¤/Ó"3Ô4à�
‰
×Ñ˜aÔ Ø×Ñ˜Ÿ™×+Ñ+¨QÔ/à�
‰
�‰˜˜C˜Ô!Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
�‰˜˜C˜Ô!Ø�‰˜Ÿ
™
×+Ñ+Õ,r   c                 óp  • SU R                   l        U R                   R                  [        5       5        U R                   R	                  S5        U R                  U R                   R                  5        U R                  R                  / SQ5        U R                  U R                   R                  5        g)z?
Setting the timeout to L{None} cancel any timeout operations.
é   N)r   r±  r±  r±  )
r™   r‘  r–   r   re  rÌ   r`   r�  rM  r™  r   s    r   rj  Ú$TimeoutMixinTests.test_cancelTimeout  sw   € ð ˆ�
‰
ÔØ�
‰
×!Ñ!¤/Ó"3Ô4à�
‰
×Ñ˜dÔ#Ø×Ñ˜$Ÿ*™*×,Ñ,Ô-à�
‰
�‰šÔ%Ø×Ñ˜Ÿ™×,Ñ,Õ-r   c                 ó¨  • SU R                   l        U R                  U R                   R                  S5      S5        U R                  U R                   R                  S5      S5        U R	                  U R                   R                  S5      5        U R                  U R                   R                  S5        U R                   R                  S5        g)z=
setTimeout should return the value of the previous timeout.
r±  rG  Nr    )r™   r‘  rž   re  rÌ   r   s    r   Útest_setTimeoutReturnÚ'TimeoutMixinTests.test_setTimeoutReturn  s™   € ð ˆ�
‰
Ôà×Ñ˜Ÿ™×.Ñ.¨rÓ2°AÔ6Ø×Ñ˜Ÿ™×.Ñ.¨tÓ4°bÔ9Ø×Ñ˜$Ÿ*™*×/Ñ/°Ó2Ô3Ø×Ñ˜Ÿ™×+Ñ+¨QÔ/ð 	�
‰
×Ñ˜dÕ#r   c                 óZ  • U R                   R                  S5        U R                  R                  5       S   R	                  5         U R                  U R                   R                  5        U R                   R                  S5        U R                  U R                   R                  5        g)z±
When the timeout was already cancelled from an external place,
calling setTimeout with C{None} to explicitly cancel it will clean
up the timeout without raising any exception.
rd  r   N)r™   re  r`   ÚgetDelayedCallsrt  rù   r‘  rÌ   r   s    r   Ú%test_setTimeoutCancleAlreadyCancelledÚ7TimeoutMixinTests.test_setTimeoutCancleAlreadyCancelled,  sx   € ð 	�
‰
×Ñ˜aÔ ð 	�
‰
×"Ñ"Ó$ QÑ'×.Ñ.Ô0Ø×Ñ˜TŸZ™Z×/Ñ/Ô0à�
‰
×Ñ˜dÔ#à×Ñ˜$Ÿ*™*×,Ñ,Õ-r   )r`   r™   N)r2   r3   r4   r5   rY   rz  r¥  r‚  r«  r®  rj  r´  r¸  r6   r7   r   r   r   r   Ò  s/   † ñò/ò3ò-ò-ò-ò .ò$õ.r   r   c                   ó$   • \ rS rSrSrS rS rSrg)Ú!LimitTotalConnectionsFactoryTestsi=  z/Tests for policies.LimitTotalConnectionsFactoryc                 óø  • [         R                  " 5       n[        R                  Ul        U R	                  SUR
                  5        UR                  S 5      nU R	                  SUR
                  5        UR                  S 5      nU R	                  SUR
                  5        UR                  S 5        U R	                  SUR
                  5        UR                  S 5        U R	                  SUR
                  5        g )Nr   r    r  )r   ÚLimitTotalConnectionsFactoryr	   r•   rž   ÚconnectionCountrA   r*   )r   r„   Úp1Úp2s       r   ÚtestConnectionCountingÚ8LimitTotalConnectionsFactoryTests.testConnectionCounting@  sÎ   € ä×7Ò7Ó9ˆÜ#×,Ñ,ˆÔð 	×Ñ˜˜G×3Ñ3Ô4ð ×"Ñ" 4Ó(ˆØ×Ñ˜˜G×3Ñ3Ô4Ø×"Ñ" 4Ó(ˆØ×Ñ˜˜G×3Ñ3Ô4ð 	×Ñ˜$ÔØ×Ñ˜˜G×3Ñ3Ô4Ø
×Ñ˜$ÔØ×Ñ˜˜G×3Ñ3Õ4r   c                 ó  ^• [         R                  " 5       m[        R                  Tl        STl        TR                  S 5      nU R                  U5        U R                  STR                  5        U R                  TR                  S 5      5        U R                  STR                  5         " U4S jS[        R                  5      nUTl
        STl        TR                  S 5      nUR                  S 5        U R                  TR                  5        U R                  STR                  5        UR                  S 5        U R                  STR                  5        UR                  S 5        U R                  STR                  5        g )Nr    c                   ó"   >• \ rS rSrU 4S jrSrg)ÚRLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocolie  c                 ó   >• STl         g rG   )Ú
overflowed)r   r„   s    €r   r$   ÚaLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocol.connectionMadef  s   ø€ Ø%)�Õ"r   r7   N)r2   r3   r4   r5   r$   r6   )r„   s   €r   ÚOverflowProtocolrÅ  e  s   ø† ÷*ð *r   rÉ  Fr  r   )r   r½  r	   r•   ÚconnectionLimitrA   rù   rž   r¾  rÌ   ÚoverflowProtocolrÇ  r–   r—   r*   )r   r=   rÉ  Úopr„   s       @r   ÚtestConnectionLimitingÚ8LimitTotalConnectionsFactoryTests.testConnectionLimitingT  sD  ø€ ä×7Ò7Ó9ˆÜ#×,Ñ,ˆÔØ"#ˆÔð ×!Ñ! $Ó'ˆØ×Ñ˜QÔØ×Ñ˜˜G×3Ñ3Ô4ð 	×Ñ˜'×/Ñ/°Ó5Ô6Ø×Ñ˜˜G×3Ñ3Ô4÷	*œx×0Ñ0ô 	*ð $4ˆÔ Ø"ˆÔð
 ×"Ñ" 4Ó(ˆØ
×Ñ˜$ÔØ�‰˜×*Ñ*Ô+Ø×Ñ˜˜G×3Ñ3Ô4ð 	
×Ñ˜ÔØ×Ñ˜˜G×3Ñ3Ô4Ø
×Ñ˜$ÔØ×Ñ˜˜G×3Ñ3Õ4r   r7   N)r2   r3   r4   r5   rY   rÁ  rÍ  r6   r7   r   r   r»  r»  =  s   † Ù9ò5õ($5r   r»  c                   ó   • \ rS rSrS rSrg)ÚWriteSequenceEchoProtocoli{  c                 ó’   • UR                  S5      S:w  a  U R                  R                  U/5        g [        R	                  X5        g )Ns   vector!éÿÿÿÿ)ÚfindrS   rA  rD   r0   )r   Úbytess     r   r0   Ú&WriteSequenceEchoProtocol.dataReceived|  s5   € Ø�:‰:�jÓ! RÓ'Ø�N‰N×(Ñ(¨%¨Õ1ä×%Ñ% dÕ2r   r7   N)r2   r3   r4   r5   r0   r6   r7   r   r   rÐ  rÐ  {  s   † õ3r   rÐ  c                   ó   • \ rS rSrSrS rSrg)ÚTestLoggingFactoryiƒ  Nc                 ó`   • U R                   b   S5       e[        5       U l         U R                   $ )Nzopen() called too many times)ÚopenFiler   )r   Únames     r   ÚopenÚTestLoggingFactory.open†  s+   € Ø�}‰}Ñ$ÐDÐ&DÓDÐ$Ü ›
ˆŒØ�}‰}Ðr   )rÙ  )r2   r3   r4   r5   rÙ  rÛ  r6   r7   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)ÚLoggingFactoryTestsiŒ  z.
Tests for L{policies.TrafficLoggingFactory}.
c                 óÌ  • [        5       n[        Ul        [        5       n[	        US5      nUR                  S5      nXBl        UR                  U5        UR                  R                  5       nU R                  SU5        U R                  UR                  5       5        UR                  S5        UR                  R                  5       nU R                  SR                  S5      U5        U R                  SR                  S5      U5        U R                  UR                  5       S5        UR                  5         UR                  S5        UR                  R                  5       nU R                  SR                  S/5      U5        U R                  UR                  5       S5        UR!                  5         UR                  R                  5       nU R                  S	U5        g
)zA
Check the output produced by L{policies.TrafficLoggingFactory}.
Útest©ú1.2.3.4i.  Ú*s   here are some bytesz	C 1: {!r}z	S 1: {!r}s"   prepare for vector! to the extremez
SV 1: {!r}ÚConnectionDoneN)rW   rÐ  r	   r   r×  rA   r–   rÙ  ÚgetvalueÚassertInrM  rB  r0   Úformatrž   rX  rú   )r   r`  Útr…   r=   Úvs         r   Útest_thingsGetLoggedÚ(LoggingFactoryTests.test_thingsGetLogged‘  sq  € ô  ›ˆÜ";ˆÔÜ,Ó.ˆÜ˜~¨vÓ6ˆØ�O‰OÐ-Ó.ˆØŒ
Ø	×Ñ˜Ôà�J‰J×ÑÓ!ˆØ�‰�c˜1ÔØ×Ñ˜Ÿ™›Ô#à	�‰Ð-Ô.à�J‰J×ÑÓ!ˆØ�‰�k×(Ñ(Ð)?Ó@À!ÔDØ�‰�k×(Ñ(Ð)?Ó@À!ÔDØ×Ñ˜Ÿ™›Ð$:Ô;à	�‰Œ	Ø	�‰Ð<Ô=Ø�J‰J×ÑÓ!ˆØ�‰�l×)Ñ)Ð+PÐ*QÓRÐTUÔVØ×Ñ˜Ÿ™›Ð$IÔJà	×ÑÔà�J‰J×ÑÓ!ˆØ�‰Ð&¨Õ*r   c                 ó‚  • [        5       n[        US5      nU R                  UR                  S5        UR	                  S5        U R                  UR                  S5        SUl        UR	                  S5        U R                  UR                  S5        UR                  5         U R                  UR                  S5        g)z7
Test counter management with the resetCounter method.
rà  r   rá  r    N)râ  i/  r  )rW   r×  rž   Ú_counterrA   rÙ  ÚresetCounter)r   r`  r…   s      r   Útest_counterÚ LoggingFactoryTests.test_counter³  s’   € ô  ›ˆÜ˜~¨vÓ6ˆØ×Ñ˜Ÿ™ QÔ'Ø	�‰Ð)Ô*Ø×Ñ˜Ÿ™ QÔ'àˆŒ
Ø	�‰Ð)Ô*Ø×Ñ˜Ÿ™ QÔ'à	�‰ÔØ×Ñ˜Ÿ™ QÕ'r   c                 óÜ  ^^	• / m/ m	UU	4S jnU R                  [        SU5        [        R                  " 5       n[        Ul        [
        R                  " US5      nUR                  [        R                  " SSS5      5      nUR                  [        R                  " SSS5      5      nS0 4nS	0 4nU R                  Xg/T5        U R                  UR                  UR                  /T	5        g
)zª
When the L{policies.TrafficLoggingFactory} builds a protocol, it
automatically opens a unique log file for that protocol and attaches
the logfile to the built protocol.
c                  óv   >• TR                  X45        [        5       nU S   Ul        TR                  U5        U$ )z@
Mock for the open call to prevent actually opening a log file.
r   )rÒ   r   rÚ  )rb   rc   ÚioÚ
open_callsÚopen_rvaluess      €€r   Úmocked_openÚULoggingFactoryTests.test_loggingFactoryOpensLogfileAutomatically.<locals>.mocked_openÍ  s:   ø€ ð ×Ñ˜t˜nÔ-Ü“ˆBØ˜1‘gˆBŒGØ×Ñ Ô#ØˆIr   rÛ  rà  r}   r~   r^  i:0  )ztest-1Úw)ztest-2rø  N)ÚpatchÚbuiltinsr	   r_  r   r   ÚTrafficLoggingFactoryrA   r   r�   rž   Úlogfile)
r   rö  r`  r„   Úfirst_protoÚsecond_protoÚ
first_callÚsecond_callrô  rõ  s
           @@r   Ú,test_loggingFactoryOpensLogfileAutomaticallyÚ@LoggingFactoryTests.test_loggingFactoryOpensLogfileAutomaticallyÄ  sÞ   ù€ ð ˆ
Øˆö	ð 	�
‰
”8˜V [Ô1ä!×/Ò/Ó1ˆÜ"0ˆÔÜ×0Ò0°ÀÓHˆØ×+Ñ+Ü×Ò  {°EÓ:ó
ˆð ×,Ñ,Ü×Ò  {°EÓ:ó
ˆð & rÐ*ˆ
Ø&¨Ð+ˆØ×Ñ˜*Ð2°JÔ?Ø×Ñ˜+×-Ñ-¨|×/CÑ/CÐDÀlÕSr   r7   N)	r2   r3   r4   r5   rY   rê  rï  r  r6   r7   r   r   rÞ  rÞ  Œ  s   † ñò +òD(õ"$Tr   rÞ  ).rY   rú  ró  r   Úzope.interfacer   r   r   Útwisted.internetr   r   r	   r
   r   Útwisted.internet.testingr   r   Útwisted.protocolsr   Útwisted.trialr   r•   r   ÚClientFactoryr9   rD   r_  rW   r_   r[   ru   rr   ÚTestCaserz   r€   r  r\  rx  ÚTimeoutMixinr�  r   r»  rÐ  rû  r×  rÞ  r7   r   r   Ú<module>r     sr  ðñó
 Ý ç @Ñ @ç DÕ Dß VÝ &Ý "ô�X×&Ñ&ô ô(�8×)Ñ)ô ô#�8×$Ñ$ô #ô ˆX×#Ñ#ô ô2 × :Ñ :ô 2ô*2˜X×4Ñ4ô 2ô*Z3�8×$Ñ$ô Z3ôz%�h×.Ñ.ô %ôY8�h×'Ñ'ô Y8ôxU;˜8×,Ñ,ô U;ôpR8˜(×+Ñ+ô R8ôj.D�H×%Ñ% x×'<Ñ'<ô .Dôbh.˜×)Ñ)ô h.ôV;5¨×(9Ñ(9ô ;5ô|3 ô 3ô˜×7Ñ7ô ô\T˜(×+Ñ+õ \Tr   