Ë
    oj"�  ã                   ó@  — d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZ ddlmZ  G d	„ d
ej*                  «      Z G d„ dej.                  «      Z G d„ dej*                  «      Z G d„ dej4                  «      Z G d„ dej8                  «      Z G d„ dej<                  «      Z G d„ dej@                  «      Z! G d„ dejD                  «      Z" G d„ dej@                  «      Z# G d„ dej@                  «      Z$ G d„ dej@                  «      Z% G d„ d ej*                  ejL                  «      Z' G d!„ d"ej@                  «      Z( G d#„ d$ej@                  «      Z) G d%„ d&e«      Z* G d'„ d(ejV                  «      Z, G d)„ d*ej@                  «      Z-y)+z
Test code for policies.
é    N)ÚStringIO)Ú	InterfaceÚimplementedByÚimplementer)ÚaddressÚdeferÚprotocolÚreactorÚtask)ÚStringTransportÚ StringTransportWithDisconnection)Úpolicies)Úunittestc                   ó0   — e Zd ZdxZZdZd„ Zd„ Zd„ Zd„ Z	y)ÚSimpleProtocolr   ó    c                 óh   — t        j                  «       | _        t        j                  «       | _        y ©N)r   ÚDeferredÚ
dConnectedÚdDisconnected©Úselfs    ú</usr/lib/python3/dist-packages/twisted/test/test_policies.pyÚ__init__zSimpleProtocol.__init__   s   € ÜŸ.™.Ó*ˆŒÜ"Ÿ^™^Ó-ˆÕr   c                 óH   — d| _         | j                  j                  d«       y ©Né   Ú )Ú	connectedr   Úcallbackr   s    r   ÚconnectionMadezSimpleProtocol.connectionMade   s   € ØˆŒØ�‰× Ñ  Õ$r   c                 óH   — d| _         | j                  j                  d«       y r   )Údisconnectedr   r!   ©r   Úreasons     r   ÚconnectionLostzSimpleProtocol.connectionLost    s   € ØˆÔØ×Ñ×#Ñ# BÕ'r   c                 ó.   — | xj                   |z  c_         y r   )Úbuffer©r   Údatas     r   ÚdataReceivedzSimpleProtocol.dataReceived$   s   € Ø�Š�tÑŽr   N)
Ú__name__Ú
__module__Ú__qualname__r    r$   r)   r   r"   r'   r,   © r   r   r   r      s%   „ Ø Ð €I�Ø€Fò.ò%ò(ór   r   c                   ó   — e Zd Zd„ Zd„ Zy)ÚSillyFactoryc                 ó   — || _         y r   ©Úp)r   r5   s     r   r   zSillyFactory.__init__)   s	   € Øˆ�r   c                 ó   — | j                   S r   r4   )r   Úaddrs     r   ÚbuildProtocolzSillyFactory.buildProtocol,   s   € Ø�v‰vˆr   N)r-   r.   r/   r   r8   r0   r   r   r2   r2   (   s   „ òór   r2   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚEchoProtocolFc                 ó   — d| _         y ©NT©Úpausedr   s    r   ÚpauseProducingzEchoProtocol.pauseProducing3   s	   € Øˆ�r   c                 ó   — d| _         y )NFr=   r   s    r   ÚresumeProducingzEchoProtocol.resumeProducing6   s	   € Øˆ�r   c                  ó   — y r   r0   r   s    r   ÚstopProducingzEchoProtocol.stopProducing9   s   € Ør   c                 ó:   — | j                   j                  |«       y r   )Ú	transportÚwriter*   s     r   r,   zEchoProtocol.dataReceived<   s   € Ø�‰×Ñ˜TÕ"r   N)r-   r.   r/   r>   r?   rA   rC   r,   r0   r   r   r:   r:   0   s   „ Ø€Fòòòó#r   r:   c                   ó   — e Zd ZdZeZy)ÚServerz8
    A simple server factory using L{EchoProtocol}.
    N)r-   r.   r/   Ú__doc__r:   r	   r0   r   r   rH   rH   @   s   „ ñð �Hr   rH   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚTestableThrottlingFactoryzH
    L{policies.ThrottlingFactory} using a L{task.Clock} for tests.
    c                 óX   — t        j                  j                  | g|¢­i |¤Ž || _        y©z˜
        @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   rO   ÚargsÚkwargss       r   r   z"TestableThrottlingFactory.__init__M   s)   € ô 	×"Ñ"×+Ñ+¨DÐB°4ÒB¸6ÒBØˆ�
r   c                 ó:   — | j                   j                  ||«      S ©z0
        Forward to the testable clock.
        ©rO   Ú	callLater©r   ÚperiodÚfuncs      r   rV   z#TestableThrottlingFactory.callLaterV   ó   € ð �z‰z×#Ñ# F¨DÓ1Ð1r   N©r-   r.   r/   rI   r   rV   r0   r   r   rK   rK   H   ó   „ ñòó2r   rK   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚTestableTimeoutFactoryzE
    L{policies.TimeoutFactory} using a L{task.Clock} for tests.
    c                 óX   — t        j                  j                  | g|¢­i |¤Ž || _        yrM   )r   ÚTimeoutFactoryr   rO   rP   s       r   r   zTestableTimeoutFactory.__init__b   s)   € ô 	×Ñ×(Ñ(¨Ð?°Ò?¸Ò?Øˆ�
r   c                 ó:   — | j                   j                  ||«      S rT   rU   rW   s      r   rV   z TestableTimeoutFactory.callLaterk   rZ   r   Nr[   r0   r   r   r^   r^   ]   r\   r   r^   c                   óp   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚWrapperTestsz>
    Tests for L{WrappingFactory} and L{ProtocolWrapper}.
    c                 óÚ   — t        «       }t        j                  |«      }|j                  t	        j
                  ddd«      «      }| j                  |j                  j                  |«       y)zf
        Make sure protocol.factory is the wrapped factory, not the wrapping
        factory.
        ÚTCPú	127.0.0.1é#   N)	rH   r   ÚWrappingFactoryr8   r   ÚIPv4AddressÚassertIsÚwrappedProtocolÚfactory)r   ÚfÚwfr5   s       r   Útest_protocolFactoryAttributez*WrapperTests.test_protocolFactoryAttributew   sT   € ô
 ‹HˆÜ×%Ñ% aÓ(ˆØ×ÑœW×0Ñ0°¸ÀRÓHÓIˆØ�‰�a×'Ñ'×/Ñ/°Õ3r   c                 ó~  —  G d„ dt         «      }t        |«       G d„ d«      «       }t        t        j                  «       t        j                  «       }t        j                  t        j                  d«      |«      }|j                   |«       «       | j                  |j                  |j                  «      «       y)z²
        The transport wrapper passed to the wrapped protocol's
        C{makeConnection} provides the same interfaces as are provided by the
        original transport.
        c                   ó   — e Zd Zy)ú=WrapperTests.test_transportInterfaces.<locals>.IStubTransportN©r-   r.   r/   r0   r   r   ÚIStubTransportrr   ˆ   ó   „ Ør   rt   c                   ó   — e Zd Zy)ú<WrapperTests.test_transportInterfaces.<locals>.StubTransportNrs   r0   r   r   ÚStubTransportrw   ‹   s   „ àr   rx   N)r   r   r   r   ÚProtocolWrapperr	   ÚProtocolrh   ÚmakeConnectionÚ
assertTrueÚ
providedByrE   )r   rt   rx   ÚprotoÚwrappers        r   Útest_transportInterfacesz%WrapperTests.test_transportInterfaces�   s’   € ô	œYô 	ô 
�^Ó	$÷	ð 	ó 
%ð	ô 	”h×.Ñ.Ô/ä×!Ñ!Ó#ˆÜ×*Ñ*¬8×+CÑ+CÀDÓ+IÈ5ÓQˆà×Ñ™}›Ô/Ø�‰˜×1Ñ1°%·/±/ÓBÕCr   c                 ó‚   — t        «       }t        j                  |«      }| j                  d|j	                  «       «       y)zƒ
        L{WrappingFactory.logPrefix} is customized to mention both the original
        factory and the wrapping factory.
        zServer (WrappingFactory)N)rH   r   rh   ÚassertEqualÚ	logPrefix)r   Úserverrl   s      r   Útest_factoryLogPrefixz"WrapperTests.test_factoryLogPrefixž   s5   € ô
 “ˆÜ×*Ñ*¨6Ó2ˆØ×ÑÐ3°W×5FÑ5FÓ5HÕIr   c                 ó�   —  G d„ d«      } |«       }t        j                  |«      }| j                  d|j                  «       «       y)z—
        If the wrapped factory doesn't have a L{logPrefix} method,
        L{WrappingFactory.logPrefix} falls back to the factory class name.
        c                   ó   — e Zd Zy)ú=WrapperTests.test_factoryLogPrefixFallback.<locals>.NoFactoryNrs   r0   r   r   Ú	NoFactoryrˆ   ­   ru   r   r‰   zNoFactory (WrappingFactory)N)r   rh   r‚   rƒ   )r   r‰   r„   rl   s       r   Útest_factoryLogPrefixFallbackz*WrapperTests.test_factoryLogPrefixFallback§   s?   € ÷	ñ 	ñ “ˆÜ×*Ñ*¨6Ó2ˆØ×ÑÐ6¸×8IÑ8IÓ8KÕLr   c                 óÐ   — t        «       }t        j                  |«      }|j                  t	        j
                  ddd«      «      }| j                  d |j                  «       «       y)z{
        L{ProtocolWrapper.logPrefix} is customized to mention both the original
        protocol and the wrapper.
        re   rf   rg   zEchoProtocol (ProtocolWrapper)N)rH   r   rh   r8   r   ri   r‚   rƒ   )r   r„   rl   r	   s       r   Útest_protocolLogPrefixz#WrapperTests.test_protocolLogPrefix´   sX   € ô
 “ˆÜ×*Ñ*¨6Ó2ˆØ×(Ñ(¬×)<Ñ)<¸UÀKÐQSÓ)TÓUˆØ×ÑÐ9Ð;M¸8×;MÑ;MÓ;OÕPr   c                 óò   —  G d„ d«      }t        «       }||_        t        j                  |«      }|j	                  t        j                  ddd«      «      }| j                  d |j                  «       «       y)z™
        If the wrapped protocol doesn't have a L{logPrefix} method,
        L{ProtocolWrapper.logPrefix} falls back to the protocol class name.
        c                   ó   — e Zd Zy)ú?WrapperTests.test_protocolLogPrefixFallback.<locals>.NoProtocolNrs   r0   r   r   Ú
NoProtocolr�   Ä   ru   r   r�   re   rf   rg   zNoProtocol (ProtocolWrapper)N)	rH   r	   r   rh   r8   r   ri   r‚   rƒ   )r   r�   r„   rl   r	   s        r   Útest_protocolLogPrefixFallbackz+WrapperTests.test_protocolLogPrefixFallback¾   si   € ÷	ñ 	ô “ˆØ$ˆŒÜ×*Ñ*¨6Ó2ˆØ×(Ñ(¬×)<Ñ)<¸UÀKÐQSÓ)TÓUˆØ×ÑÐ7Ð9K¸×9KÑ9KÓ9MÕNr   c                 óÂ   — t        j                  t        j                  t        «       «      t	        j
                  «       «      }t        «       }|j                  |«       |S )zm
        Return L{policies.ProtocolWrapper} that has been connected to a
        L{StringTransport}.
        )r   ry   rh   rH   r	   rz   r   r{   ©r   r   rE   s      r   Ú_getWrapperzWrapperTests._getWrapperÍ   sL   € ô
 ×*Ñ*Ü×$Ñ$¤V£XÓ.´×0AÑ0AÓ0Có
ˆô $Ó%ˆ	Ø×Ñ˜yÔ)Øˆr   c                 ó”   — | j                  «       }| j                  |j                  «       |j                  j                  «       «       y)zk
        L{policies.ProtocolWrapper.getHost} calls C{getHost} on the underlying
        transport.
        N)r”   r‚   ÚgetHostrE   ©r   r   s     r   Útest_getHostzWrapperTests.test_getHostÙ   ó8   € ð
 ×"Ñ"Ó$ˆØ×Ñ˜Ÿ™Ó*¨G×,=Ñ,=×,EÑ,EÓ,GÕHr   c                 ó”   — | j                  «       }| j                  |j                  «       |j                  j                  «       «       y)zk
        L{policies.ProtocolWrapper.getPeer} calls C{getPeer} on the underlying
        transport.
        N)r”   r‚   ÚgetPeerrE   r—   s     r   Útest_getPeerzWrapperTests.test_getPeerá   r™   r   c                 óò   — | j                  «       }t        «       }|j                  |d«       | j                  |j                  j
                  |«       | j                  |j                  j                  «       y)z}
        L{policies.ProtocolWrapper.registerProducer} calls C{registerProducer}
        on the underlying transport.
        TN)r”   ÚobjectÚregisterProducerrj   rE   Úproducerr|   Ú	streaming©r   r   r    s      r   Útest_registerProducerz"WrapperTests.test_registerProduceré   s[   € ð
 ×"Ñ"Ó$ˆÜ“8ˆØ× Ñ  ¨4Ô0Ø�‰�g×'Ñ'×0Ñ0°(Ô;Ø�‰˜×)Ñ)×3Ñ3Õ4r   c                 ó  — | j                  «       }t        «       }|j                  |d«       |j                  «        | j	                  |j
                  j                  «       | j	                  |j
                  j                  «       y)z�
        L{policies.ProtocolWrapper.unregisterProducer} calls
        C{unregisterProducer} on the underlying transport.
        TN)r”   rž   rŸ   ÚunregisterProducerÚassertIsNonerE   r    r¡   r¢   s      r   Útest_unregisterProducerz$WrapperTests.test_unregisterProducerô   si   € ð
 ×"Ñ"Ó$ˆÜ“8ˆØ× Ñ  ¨4Ô0Ø×"Ñ"Ô$Ø×Ñ˜'×+Ñ+×4Ñ4Ô5Ø×Ñ˜'×+Ñ+×5Ñ5Õ6r   c                 ó˜   ‡— | j                  «       }g Šˆfd„|j                  _        |j                  «        | j                  ‰dg«       y)zw
        L{policies.ProtocolWrapper.stopConsuming} calls C{stopConsuming} on
        the underlying transport.
        c                  ó&   •— ‰ j                  d«      S r<   ©Úappend©Úresults   €r   ú<lambda>z1WrapperTests.test_stopConsuming.<locals>.<lambda>  s   ø€ °&·-±-ÀÓ2E€ r   TN)r”   rE   ÚstopConsumingr‚   )r   r   r­   s     @r   Útest_stopConsumingzWrapperTests.test_stopConsuming   sD   ø€ ð
 ×"Ñ"Ó$ˆØˆÛ*Eˆ×ÑÔ'Ø×ÑÔØ×Ñ˜ $ Õ(r   c                 ó²   ‡— g Š G ˆfd„d«      }t        j                   |«       «      }t        «       }|j                  |«       | j	                  ‰|g«       y)z}
        L{policies.WrappingFactory.startedConnecting} calls
        C{startedConnecting} on the underlying factory.
        c                   ó   •— e Zd Zˆ fd„Zy)ú4WrapperTests.test_startedConnecting.<locals>.Factoryc                 ó(   •— ‰j                  |«       y r   rª   )r   Ú	connectorr­   s     €r   ÚstartedConnectingzFWrapperTests.test_startedConnecting.<locals>.Factory.startedConnecting  s   ø€ Ø—‘˜iÕ(r   N)r-   r.   r/   r¶   r¬   s   €r   ÚFactoryr³     s   ø„ õ)r   r·   N)r   rh   rž   r¶   r‚   )r   r·   r   rµ   r­   s       @r   Útest_startedConnectingz#WrapperTests.test_startedConnecting  sO   ø€ ð
 ˆ÷	)ó 	)ô ×*Ñ*©7«9Ó5ˆÜ“Hˆ	Ø×!Ñ! )Ô,Ø×Ñ˜ ) Õ-r   c                 óÌ   ‡— g Š G ˆfd„d«      }t        j                   |«       «      }t        «       }t        «       }|j                  ||«       | j	                  ‰||fg«       y)zƒ
        L{policies.WrappingFactory.clientConnectionLost} calls
        C{clientConnectionLost} on the underlying factory.
        c                   ó   •— e Zd Zˆ fd„Zy)ú7WrapperTests.test_clientConnectionLost.<locals>.Factoryc                 ó,   •— ‰j                  ||f«       y r   rª   ©r   rµ   r&   r­   s      €r   ÚclientConnectionLostzLWrapperTests.test_clientConnectionLost.<locals>.Factory.clientConnectionLost#  ó   ø€ Ø—‘˜y¨&Ð1Õ2r   N)r-   r.   r/   r¾   r¬   s   €r   r·   r»   "  ó   ø„ õ3r   r·   N)r   rh   rž   r¾   r‚   ©r   r·   r   rµ   r&   r­   s        @r   Útest_clientConnectionLostz&WrapperTests.test_clientConnectionLost  s^   ø€ ð
 ˆ÷	3ó 	3ô ×*Ñ*©7«9Ó5ˆÜ“Hˆ	Ü“ˆØ×$Ñ$ Y°Ô7Ø×Ñ˜ 9¨fÐ"5Ð!6Õ7r   c                 óÌ   ‡— g Š G ˆfd„d«      }t        j                   |«       «      }t        «       }t        «       }|j                  ||«       | j	                  ‰||fg«       y)z‡
        L{policies.WrappingFactory.clientConnectionFailed} calls
        C{clientConnectionFailed} on the underlying factory.
        c                   ó   •— e Zd Zˆ fd„Zy)ú9WrapperTests.test_clientConnectionFailed.<locals>.Factoryc                 ó,   •— ‰j                  ||f«       y r   rª   r½   s      €r   ÚclientConnectionFailedzPWrapperTests.test_clientConnectionFailed.<locals>.Factory.clientConnectionFailed4  r¿   r   N)r-   r.   r/   rÇ   r¬   s   €r   r·   rÅ   3  rÀ   r   r·   N)r   rh   rž   rÇ   r‚   rÁ   s        @r   Útest_clientConnectionFailedz(WrapperTests.test_clientConnectionFailed,  s^   ø€ ð
 ˆ÷	3ó 	3ô ×*Ñ*©7«9Ó5ˆÜ“Hˆ	Ü“ˆØ×&Ñ& y°&Ô9Ø×Ñ˜ 9¨fÐ"5Ð!6Õ7r   c                 óZ  — t        j                  t        j                  t        «       «      t	        j
                  «       «      }t        «       }||_        |j                  |«       | j                  |j                  «       |j                  «        | j                  |j                  «       y)zÉ
        L{policies.ProtocolWrapper.connectionLost} sets C{wrappedProtocol} to
        C{None} in order to break reference cycle between wrapper and wrapped
        protocols.
        :return:
        N)r   ry   rh   rH   r	   rz   r   r{   ÚassertIsNotNonerk   ÚloseConnectionr¦   r“   s      r   Útest_breakReferenceCyclez%WrapperTests.test_breakReferenceCycle=  sƒ   € ô ×*Ñ*Ü×$Ñ$¤V£XÓ.´×0AÑ0AÓ0Có
ˆô 5Ó6ˆ	Ø$ˆ	ÔØ×Ñ˜yÔ)à×Ñ˜W×4Ñ4Ô5Ø× Ñ Ô"Ø×Ñ˜'×1Ñ1Õ2r   N)r-   r.   r/   rI   ro   r€   r…   rŠ   rŒ   r‘   r”   r˜   rœ   r£   r§   r°   r¸   rÂ   rÈ   rÌ   r0   r   r   rc   rc   r   s^   „ ñò4òDò:JòMòQòOò
òIòIò	5ò
7ò	)ò.ò 8ò"8ó"3r   rc   c                   ó   — e Zd Zd„ Zd„ Zy)rh   c                 ó   — |S r   r0   )r   rm   r5   s      r   r	   zWrappingFactory.protocolQ  s   € Øˆr   c                 óx   — t         j                  j                  | «       | j                  j	                  d «       y r   )r   rh   ÚstartFactoryÚdeferredr!   r   s    r   rÐ   zWrappingFactory.startFactoryT  s(   € Ü× Ñ ×-Ñ-¨dÔ3Ø�‰×Ñ˜tÕ$r   N)r-   r.   r/   r	   rÐ   r0   r   r   rh   rh   P  s   „ òó%r   rh   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚThrottlingTestsz2
    Tests for L{policies.ThrottlingFactory}.
    c                 óÚ  ‡ ‡	‡
‡‡‡‡‡— t        «       }d„ t        d«      D «       \  Š	Š
ŠŠt        j                  |d«      Št	        ‰«      }t        j                  «       |_        t        j                  d|d¬«      Š‰j                  «       j                  Šˆ	ˆ
ˆˆfd„}ˆ	ˆ
ˆˆ ˆfd„}ˆ	fd	„}ˆˆfd
„}ˆˆ fd„}ˆ
ˆˆfd„}|j                  j                  |«       |j                  j                  |«       |j                  j                  |«       |j                  j                  |«       |j                  j                  |«       |j                  j                  |«       |j                  S )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   ó0   K  — | ]  }t        «       –— Œ y ­wr   )r   )Ú.0Úis     r   ú	<genexpr>z-ThrottlingTests.test_limit.<locals>.<genexpr>f  s   è ø€ Ò=¨qœ.×*Ñ=ùs   ‚é   é   r   rf   )Ú	interfacec                 óØ   •— t        j                  d‰t        ‰«      «       ‰j                  j	                  ˆˆfd„«       ‰j                  j	                  ˆˆfd„«       ‰j
                  S )Nrf   c                 óD   •— t        j                  d‰t        ‰«      «      S ©Nrf   ©r
   Ú
connectTCPr2   )ÚrÚc2Úns    €€r   r®   zAThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>r  ó   ø€ œ'×,Ñ,¨[¸!¼\È"Ó=MÓN€ r   c                 óD   •— t        j                  d‰t        ‰«      «      S rÞ   rß   )rá   Úc3rã   s    €€r   r®   zAThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>u  rä   r   )r
   rà   r2   r   ÚaddCallbackr   )ÚresultsÚc1râ   ræ   rã   s    €€€€r   Ú_connect123z/ThrottlingTests.test_limit.<locals>._connect123o  sT   ø€ Ü×Ñ˜{¨A¬|¸BÓ/?Ô@Ø�M‰M×%Ñ%ÜNôð �M‰M×%Ñ%ÜNôð ×#Ñ#Ð#r   c                 ó>  •— ‰j                  ‰‰‰fD �cg c]  }|j                  ‘Œ c}g d¢«       ‰j                  ‰‰‰fD �cg c]  }|j                  ‘Œ c}g d¢«       ‰j                  t        ‰j                  j                  «       «      d«       | S c c}w c c}w )N)r   r   r   )r   r   r   rÚ   )r‚   r    r$   ÚlenÚ	protocolsÚkeys)rè   Úcré   râ   ræ   r   ÚtServers     €€€€€r   Ú	_check123z-ThrottlingTests.test_limit.<locals>._check123y  s   ø€ Ø×Ñ°B¸¸B°<Ö@¨a˜aŸk›kÒ@Â)ÔLØ×Ñ°r¸2¸r°lÖC°˜aŸn›nÒCÂYÔOØ×ÑœS ×!2Ñ!2×!7Ñ!7Ó!9Ó:¸AÔ>ØˆNùò AùÚCs   ”BÁBc                 óP   •— ‰j                   j                  «        ‰j                  S r   )rE   rË   r   )rè   ré   s    €r   Ú_lose1z*ThrottlingTests.test_limit.<locals>._lose1  s   ø€ à�L‰L×'Ñ'Ô)Ø×#Ñ#Ð#r   c                 ó\   •— t        j                  d‰t        ‰«      «       ‰j                  S rÞ   )r
   rà   r2   r   )rè   Úc4rã   s    €€r   Ú	_connect4z-ThrottlingTests.test_limit.<locals>._connect4„  s$   ø€ Ü×Ñ˜{¨A¬|¸BÓ/?Ô@Ø—=‘=Ð r   c                 óx   •— ‰j                  ‰j                  d«       ‰j                  ‰j                  d«       | S )Nr   r   )r‚   r    r$   )rè   rõ   r   s    €€r   Ú_check4z+ThrottlingTests.test_limit.<locals>._check4ˆ  s0   ø€ Ø×Ñ˜RŸ\™\¨1Ô-Ø×Ñ˜RŸ_™_¨aÔ0ØˆNr   c                 óÜ   •— ‰‰fD ]  }|j                   j                  «        Œ t        j                  t        j                  ‰j
                  «      ‰j                  ‰j                  g«      S r   )rE   rË   r   ÚDeferredListÚmaybeDeferredÚstopListeningr   )rè   rï   râ   rõ   r5   s     €€€r   Ú_cleanupz,ThrottlingTests.test_limit.<locals>._cleanup�  sb   ø€ Ø˜�Vò -�Ø—‘×*Ñ*Õ,ð-ä×%Ñ%ä×'Ñ'¨¯©Ó8Ø×$Ñ$Ø×$Ñ$ðóð r   )rH   Úranger   rN   rh   r   r   rÑ   r
   Ú	listenTCPr–   Úportrç   )r   r„   ÚwrapTServerrê   rñ   ró   rö   rø   rý   ré   râ   ræ   rõ   rã   r5   rð   s   `        @@@@@@@r   Ú
test_limitz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                 óŠ  — t        «       }t        t        j                  «       |«      }|j	                  t        j                  ddd«      «      }t        «       }||_         |j                  |«        |j                  dgdz  «       | j                  |j                  «       d«       | j                  |j                  d«       y)	zZ
        L{ThrottlingProtocol.writeSequence} is called on the underlying factory.
        re   rf   r   ó   bytesrÙ   s   bytesbytesbytesbytesé   N)rH   rK   r   ÚClockr8   r   ri   r   r	   r{   ÚwriteSequencer‚   ÚvalueÚwrittenThisSecond)r   r„   rð   r	   rE   s        r   Útest_writeSequencez"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                 ó€  — t        «       }t        t        j                  «       |d¬«      }|j	                  t        j                  ddd«      «      }t        «       }||_        |j                  |«       |j                  |_        |j                  d«       |j                  d«       | j                  |j                  «       d«       | j                  |j                  d	«       | j!                  |j                  j"                  «       |j$                  j'                  d
«       | j                  |j                  d«       | j)                  |j                  j"                  «       |j$                  j'                  d
«       | j                  |j                  d«       | j!                  |j                  j"                  «       y)ze
        Check the writeLimit parameter: write data, and check for the pause
        status.
        é
   )Ú
writeLimitre   rf   r   ó
   0123456789ó
   abcdefghijó   0123456789abcdefghijr  çÍÌÌÌÌÌð?N)rH   rK   r   r  r8   r   ri   r   r	   r{   rk   r    r,   r‚   r  r	  ÚassertFalser>   rO   Úadvancer|   ©r   r„   rð   r   Útrs        r   Útest_writeLimitzThrottlingTests.test_writeLimit¯  sO  € ô
 “ˆÜ+¬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                 ó  — t        «       }t        t        j                  «       |d¬«      }|j	                  t        j                  ddd«      «      }t        «       }||_        |j                  |«       |j                  d«       |j                  d«       | j                  |j                  «       d«       | j                  |j                  d	«       |j                  j                  d
«       | j                  |j                  d«       | j                  |j                   d«       |j                  j                  d
«       | j                  |j                  d«       | j                  |j                   d«       |j#                  «        |j                  d«       |j                  d«       | j                  |j                  «       d«       | j                  |j                  d	«       |j                  j                  d
«       | j                  |j                  d«       | j                  |j                   d«       |j                  j                  d
«       | j                  |j                  d«       | j                  |j                   d«       y)zb
        Check the readLimit parameter: read data and check for the pause
        status.
        r  )Ú	readLimitre   rf   r   r  r  r  r  r  r>   Ú	producingN)rH   rK   r   r  r8   r   ri   r   r	   r{   r,   r‚   r  ÚreadThisSecondrO   r  ÚproducerStateÚclearr  s        r   Útest_readLimitz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   N)r-   r.   r/   rI   r  r
  r  r  r0   r   r   rÓ   rÓ   Y  s   „ ñò@$òD8ò6ó<%8r   rÓ   c                   ó.   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zy)ÚTimeoutProtocolTestsz0
    Tests for L{policies.TimeoutProtocol}.
    c                 ó  — t        j                  «       }t        j                  «       }t        |_        t        ||d«      }|j                  t        j                  ddd«      «      }t        «       }||_        |j                  |«       ||fS )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})
        Nre   rf   é90  )r   r  r	   ÚServerFactoryr   r^   r8   r   ri   r   r{   )r   rO   ÚwrappedFactoryrl   r~   rE   s         r   ÚgetProtocolAndClockz(TimeoutProtocolTests.getProtocolAndClockú  sz   € ô —
‘
“ˆä!×/Ñ/Ó1ˆÜ"0ˆÔä(¨°ÀÓEˆà×%Ñ%¤g×&9Ñ&9¸%ÀÈeÓ&TÓUˆä4Ó6ˆ	Ø"ˆ	ÔØ×Ñ˜YÔ'à�uˆ~Ðr   c                 ó°  — | j                  «       \  }}|j                  d«       | j                  |j                  «       | j	                  |j
                  j                  «       |j                  d«       |j                  «        | j                  |j                  «       |j                  d«       | j	                  |j
                  j                  «       y)z2
        Will cancel the ongoing timeout.
        é   r   N)
r$  Ú
setTimeoutrÊ   ÚtimeoutCallr  rk   r$   r  ÚcancelTimeoutr¦   ©r   ÚsutrO   s      r   Útest_cancelTimeoutz'TimeoutProtocolTests.test_cancelTimeout  s    € ð ×-Ñ-Ó/‰
ˆˆUØ�‰�qÔà×Ñ˜SŸ_™_Ô-Ø×Ñ˜×,Ñ,×9Ñ9Ô:à�‰�aÔØ×ÑÔà×Ñ˜#Ÿ/™/Ô*ð 	�‰�aÔØ×Ñ˜×,Ñ,×9Ñ9Õ:r   c                 óÊ   — | j                  «       \  }}| j                  |j                  «       |j                  «        | j	                  |j
                  j                  «       y)z<
        Does nothing if no timeout is already set.
        N)r$  r¦   r(  r)  r  rk   r$   r*  s      r   Útest_cancelTimeoutNoTimeoutz0TimeoutProtocolTests.test_cancelTimeoutNoTimeout#  sP   € ð ×-Ñ-Ó/‰
ˆˆUØ×Ñ˜#Ÿ/™/Ô*à×ÑÔð 	×Ñ˜×,Ñ,×9Ñ9Õ:r   c                 óÜ   — | j                  «       \  }}|j                  }|j                  d«       |j                  d«       | j	                  |j
                  «       |j                  «        y)z@
        Does nothing if no timeout is already reached.
        r&  N)r$  rk   r'  r  r|   r$   r)  )r   r+  rO   ÚwrappedProtos       r   Útest_cancelTimeoutAlreadyCalledz4TimeoutProtocolTests.test_cancelTimeoutAlreadyCalled/  sY   € ð ×-Ñ-Ó/‰
ˆˆUØ×*Ñ*ˆØ�‰�qÔà�‰�aÔØ�‰˜×1Ñ1Ô2ð 	×ÑÕr   c                 óê   — | j                  «       \  }}|j                  d«       |j                  j                  «        |j	                  «        | j                  |j                  j                  «       y)zm
        Does nothing if the timeout is cancelled from another part.
        Ex from another thread.
        r&  N)r$  r'  r(  Úcancelr)  r  rk   r$   r*  s      r   Ú"test_cancelTimeoutAlreadyCancelledz7TimeoutProtocolTests.test_cancelTimeoutAlreadyCancelled=  sZ   € ð
 ×-Ñ-Ó/‰
ˆˆUØ�‰�qÔà�‰×ÑÔ ð 	×ÑÔà×Ñ˜×,Ñ,×9Ñ9Õ:r   N)	r-   r.   r/   rI   r$  r,  r.  r1  r4  r0   r   r   r  r  õ  s    „ ñòò,;ò&
;òó;r   r  c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚTimeoutFactoryTestsz/
    Tests for L{policies.TimeoutFactory}.
    c                 óê  — t        j                  «       | _        t        j                  «       }t
        |_        t        | j                  |d«      | _        | j                  j                  t        j                  ddd«      «      | _        t        «       | _        | j                  | j                  _        | j                  j                  | j                  «       | j                  j                  | _        y)zq
        Create a testable, deterministic clock, and a set of
        server factory/protocol/transport.
        r&  re   rf   r!  N)r   r  rO   r	   r"  r   r^   rl   r8   r   ri   r~   r   rE   r{   rk   r0  )r   r#  s     r   ÚsetUpzTimeoutFactoryTests.setUpR  s§   € ô
 —Z‘Z“\ˆŒ
Ü!×/Ñ/Ó1ˆÜ"0ˆÔÜ-¨d¯j©j¸.È!ÓLˆŒØ—\‘\×/Ñ/Ü×Ñ  {°EÓ:ó
ˆŒ
ô :Ó;ˆŒØ"&§*¡*ˆ�‰ÔØ�
‰
×!Ñ! $§.¡.Ô1Ø ŸJ™J×6Ñ6ˆÕr   c                 ó  — | j                   j                  g d¢«       | j                  | j                  j                  «       | j                   j                  ddg«       | j                  | j                  j                  «       y)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)rO   Úpumpr  r0  r$   r|   r   s    r   Útest_timeoutz TimeoutFactoryTests.test_timeoutc  s]   € ð 	�
‰
�‰Ò1Ô2Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
�‰˜˜c˜
Ô#Ø�‰˜×)Ñ)×6Ñ6Õ7r   c                 óˆ  — | j                   j                  g d¢«       | j                  | j                  j                  «       | j
                  j                  d«       | j                   j                  g d¢«       | j                  | j                  j                  «       | j
                  j                  dgdz  «       | j                   j                  g d¢«       | j                  | j                  j                  «       | j                   j                  ddg«       | j                  | j                  j                  «       y)	z’
        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  r&  r:  g       @N)	rO   r>  r  r0  r$   r~   rF   r  r|   r   s    r   Útest_sendAvoidsTimeoutz*TimeoutFactoryTests.test_sendAvoidsTimeoutq  sã   € ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
×ÑÐ-Ô.ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
× Ñ  ( ¨a¡Ô0ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
�‰˜˜c˜
Ô#Ø�‰˜×)Ñ)×6Ñ6Õ7r   c                 óÆ  — | j                   j                  g d¢«       | j                  | j                  j                  «       | j
                  j                  d«       | j                   j                  g d¢«       | j                  | j                  j                  «       | j                   j                  g d¢«       | j                  | j                  j                  «       y)zR
        Make sure that receiving data also resets the timeout countdown.
        )r:  r<  r;  rA  rB  N)rO   r>  r  r0  r$   r~   r,   r|   r   s    r   Útest_receiveAvoidsTimeoutz-TimeoutFactoryTests.test_receiveAvoidsTimeout�  s™   € ð
 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
×ÑÐ 4Ô5ð 	�
‰
�‰šÔ(Ø×Ñ˜×*Ñ*×7Ñ7Ô8ð 	�
‰
�‰šÔ(Ø�‰˜×)Ñ)×6Ñ6Õ7r   N)r-   r.   r/   rI   r8  r?  rC  rE  r0   r   r   r6  r6  M  s   „ ñò7ò"8ò8ó88r   r6  c                   ó>   — e Zd ZdZdZdZd„ Zd„ Zd„ Zdd„Z	d	„ Z
d
„ Zy)ÚTimeoutTesterz”
    A testable protocol with timeout facility.

    @ivar timedOut: set to C{True} if a timeout has been detected.
    @type timedOut: C{bool}
    r&  Fc                 ó   — || _         y)zF
        Initialize the protocol with a C{task.Clock} object.
        N)rO   )r   rO   s     r   r   zTimeoutTester.__init__­  s   € ð ˆ�
r   c                 ó:   — | j                  | j                  «       y)z3
        Upon connection, set the timeout.
        N)r'  ÚtimeOutr   s    r   r"   zTimeoutTester.connectionMade³  s   € ð 	�‰˜Ÿ™Õ%r   c                 ód   — | j                  «        t        j                  j                  | |«       y)z,
        Reset the timeout on data.
        N)ÚresetTimeoutr	   rz   r,   r*   s     r   r,   zTimeoutTester.dataReceived¹  s&   € ð 	×ÑÔÜ×Ñ×&Ñ& t¨TÕ2r   Nc                 ó&   — | j                  d«       y)zD
        On connection lost, cancel all timeout operations.
        N)r'  r%   s     r   r'   zTimeoutTester.connectionLostÀ  s   € ð 	�‰˜Õr   c                 ó   — d| _         y)zX
        Flags the timedOut variable to indicate the timeout of the connection.
        TN)ÚtimedOutr   s    r   ÚtimeoutConnectionzTimeoutTester.timeoutConnectionÆ  s   € ð ˆ�r   c                 óD   —  | j                   j                  ||g|¢­i |¤ŽS )zD
        Override callLater to use the deterministic clock.
        rU   )r   ÚtimeoutrY   rQ   rR   s        r   rV   zTimeoutTester.callLaterÌ  s'   € ð $ˆt�z‰z×#Ñ# G¨TÐC°DÒC¸FÑCÐCr   r   )r-   r.   r/   rI   rJ  rO  r   r"   r,   r'   rP  rV   r0   r   r   rG  rG  ¢  s2   „ ñð €GØ€Hòò&ò3óòóDr   rG  c                   ó@   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zy
)ÚTimeoutMixinTestsz-
    Tests for L{policies.TimeoutMixin}.
    c                 ój   — t        j                  «       | _        t        | j                  «      | _        y)zY
        Create a testable, deterministic clock and a C{TimeoutTester} instance.
        N)r   r  rO   rG  r~   r   s    r   r8  zTimeoutMixinTests.setUpØ  s!   € ô —Z‘Z“\ˆŒ
Ü" 4§:¡:Ó.ˆ�
r   c                 ó˜   — | j                   j                  d«       | j                  t        | j                  j
                  «      d«       y)zš
        Test that the callLater of the clock is used instead of
        L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
        r  r   N)r~   r'  r‚   rì   rO   Úcallsr   s    r   Útest_overriddenCallLaterz*TimeoutMixinTests.test_overriddenCallLaterß  s5   € ð
 	�
‰
×Ñ˜bÔ!Ø×Ñœ˜TŸZ™Z×-Ñ-Ó.°Õ2r   c                 óR  — | j                   j                  t        «       «       | j                  j	                  g d¢«       | j                  | j                   j                  «       | j                  j	                  ddg«       | j                  | j                   j                  «       y)zq
        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   rO   r>  r  rO  r|   r   s    r   r?  zTimeoutMixinTests.test_timeoutç  sn   € ð
 	�
‰
×!Ñ!¤/Ó"3Ô4ð 	�
‰
�‰Ò*Ô+Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
�‰˜˜C˜Ô!Ø�‰˜Ÿ
™
×+Ñ+Õ,r   c                 ó  — | j                   j                  t        «       «       | j                  j	                  g d¢«       | j                  | j                   j                  «       | j                   j                  d«       | j                  j	                  g d¢«       | j                  | j                   j                  «       | j                  j	                  ddg«       | j                  | j                   j                  «       y)zV
        Check that receiving data is delaying the timeout of the connection.
        rZ  s   hello there)r   r<  r<  r;  r   r<  N)	r~   r{   r   rO   r>  r  rO  r,   r|   r   s    r   Útest_noTimeoutz TimeoutMixinTests.test_noTimeoutô  s§   € ð 	�
‰
×!Ñ!¤/Ó"3Ô4à�
‰
�‰Ò*Ô+Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
×Ñ Ô/Ø�
‰
�‰Ò*Ô+Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
�‰˜˜C˜Ô!Ø�‰˜Ÿ
™
×+Ñ+Õ,r   c                 óö  — d| j                   _        | j                   j                  t        «       «       | j                   j	                  d«       | j                  | j                   j                  d«       | j                  j                  ddg«       | j                  | j                   j                  «       | j                  j                  ddg«       | j                  | j                   j                  «       y)zy
        Check that setting a new value for timeout cancel the previous value
        and install a new timeout.
        Nr   r   gÍÌÌÌÌÌì?r=  )r~   rJ  r{   r   r'  r‚   rO   r>  r  rO  r|   r   s    r   Útest_resetTimeoutz#TimeoutMixinTests.test_resetTimeout  s§   € ð
 "ˆ�
‰
ÔØ�
‰
×!Ñ!¤/Ó"3Ô4à�
‰
×Ñ˜aÔ Ø×Ñ˜Ÿ™×+Ñ+¨QÔ/à�
‰
�‰˜˜C˜Ô!Ø×Ñ˜Ÿ™×,Ñ,Ô-Ø�
‰
�‰˜˜C˜Ô!Ø�‰˜Ÿ
™
×+Ñ+Õ,r   c                 óp  — d| j                   _        | j                   j                  t        «       «       | j                   j	                  d«       | j                  | j                   j                  «       | j                  j                  g d¢«       | j                  | j                   j                  «       y)zO
        Setting the timeout to L{None} cancel any timeout operations.
        é   N)r   r`  r`  r`  )
r~   rJ  r{   r   r'  r¦   rO   r>  r  rO  r   s    r   r,  z$TimeoutMixinTests.test_cancelTimeout  sw   € ð ˆ�
‰
ÔØ�
‰
×!Ñ!¤/Ó"3Ô4à�
‰
×Ñ˜dÔ#Ø×Ñ˜$Ÿ*™*×,Ñ,Ô-à�
‰
�‰šÔ%Ø×Ñ˜Ÿ™×,Ñ,Õ-r   c                 ó¨  — d| j                   _        | j                  | j                   j                  d«      d«       | j                  | j                   j                  d«      d«       | j	                  | j                   j                  d«      «       | j                  | j                   j                  d«       | j                   j                  d«       y)zM
        setTimeout should return the value of the previous timeout.
        r`  r  Nr   )r~   rJ  r‚   r'  r¦   r   s    r   Útest_setTimeoutReturnz'TimeoutMixinTests.test_setTimeoutReturn  s™   € ð ˆ�
‰
Ôà×Ñ˜Ÿ™×.Ñ.¨rÓ2°AÔ6Ø×Ñ˜Ÿ™×.Ñ.¨tÓ4°bÔ9Ø×Ñ˜$Ÿ*™*×/Ñ/°Ó2Ô3Ø×Ñ˜Ÿ™×+Ñ+¨QÔ/ð 	�
‰
×Ñ˜dÕ#r   c                 óZ  — | j                   j                  d«       | j                  j                  «       d   j	                  «        | j                  | j                   j                  «       | j                   j                  d«       | j                  | j                   j                  «       y)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.
        r&  r   N)r~   r'  rO   ÚgetDelayedCallsr3  rÊ   rJ  r¦   r   s    r   Ú%test_setTimeoutCancleAlreadyCancelledz7TimeoutMixinTests.test_setTimeoutCancleAlreadyCancelled-  sx   € ð 	�
‰
×Ñ˜aÔ ð 	�
‰
×"Ñ"Ó$ QÑ'×.Ñ.Ô0Ø×Ñ˜TŸZ™Z×/Ñ/Ô0à�
‰
×Ñ˜dÔ#à×Ñ˜$Ÿ*™*×,Ñ,Õ-r   N)r-   r.   r/   rI   r8  rX  r?  r\  r^  r,  rb  re  r0   r   r   rT  rT  Ó  s/   „ ñò/ò3ò-ò-ò-ò .ò$ó.r   rT  c                   ó   — e Zd ZdZd„ Zd„ Zy)Ú!LimitTotalConnectionsFactoryTestsz/Tests for policies.LimitTotalConnectionsFactoryc                 óö  — t        j                  «       }t        j                  |_        | j	                  d|j
                  «       |j                  d «      }| j	                  d|j
                  «       |j                  d «      }| j	                  d|j
                  «       |j                  d «       | j	                  d|j
                  «       |j                  d «       | j	                  d|j
                  «       y )Nr   r   rÚ   )r   ÚLimitTotalConnectionsFactoryr	   rz   r‚   ÚconnectionCountr8   r'   )r   rl   Úp1Úp2s       r   ÚtestConnectionCountingz8LimitTotalConnectionsFactoryTests.testConnectionCountingA  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                 ó  ‡— t        j                  «       Št        j                  ‰_        d‰_        ‰j                  d «      }| j                  |«       | j                  d‰j                  «       | j                  ‰j                  d «      «       | j                  d‰j                  «        G ˆfd„dt        j                  «      }|‰_
        d‰_        ‰j                  d «      }|j                  d «       | j                  ‰j                  «       | j                  d‰j                  «       |j                  d «       | j                  d‰j                  «       |j                  d «       | j                  d‰j                  «       y )Nr   c                   ó   •— e Zd Zˆ fd„Zy)úRLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocolc                 ó   •— d‰_         y r<   )Ú
overflowed)r   rl   s    €r   r"   zaLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocol.connectionMadeg  s   ø€ Ø%)�Õ"r   N)r-   r.   r/   r"   )rl   s   €r   ÚOverflowProtocolrp  f  s   ø„ õ*r   rs  FrÚ   r   )r   ri  r	   rz   ÚconnectionLimitr8   rÊ   r‚   rj  r¦   ÚoverflowProtocolrr  r{   r|   r'   )r   r5   rs  Úoprl   s       @r   ÚtestConnectionLimitingz8LimitTotalConnectionsFactoryTests.testConnectionLimitingU  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   N)r-   r.   r/   rI   rm  rw  r0   r   r   rg  rg  >  s   „ Ù9ò5ó($5r   rg  c                   ó   — e Zd Zd„ Zy)ÚWriteSequenceEchoProtocolc                 ó’   — |j                  d«      dk7  r| j                  j                  |g«       y t        j	                  | |«       y )Ns   vector!éÿÿÿÿ)ÚfindrE   r  r:   r,   )r   Úbytess     r   r,   z&WriteSequenceEchoProtocol.dataReceived}  s7   € Ø�:‰:�jÓ! RÒ'Ø�N‰N×(Ñ(¨%¨Õ1ä×%Ñ% d¨EÕ2r   N)r-   r.   r/   r,   r0   r   r   ry  ry  |  s   „ ó3r   ry  c                   ó   — e Zd ZdZd„ Zy)ÚTestLoggingFactoryNc                 ó^   — | j                   �J d«       ‚t        «       | _         | j                   S )Nzopen() called too many times)ÚopenFiler   )r   Únames     r   ÚopenzTestLoggingFactory.open‡  s+   € Ø�}‰}Ð$ÐDÐ&DÓDÐ$Ü ›
ˆŒØ�}‰}Ðr   )r-   r.   r/   r�  rƒ  r0   r   r   r  r  „  s   „ Ø€Hór   r  c                   ó"   — e Zd ZdZd„ Zd„ Zd„ Zy)ÚLoggingFactoryTestsz6
    Tests for L{policies.TrafficLoggingFactory}.
    c                 óÎ  — t        «       }t        |_        t        «       }t	        |d«      }|j                  d«      }||_        |j                  |«       |j                  j                  «       }| j                  d|«       | j                  |j                  «       «       |j                  d«       |j                  j                  «       }| j                  dj                  d«      |«       | j                  dj                  d«      |«       | j                  |j                  «       d«       |j                  «        |j                  d«       |j                  j                  «       }| j                  dj                  dg«      |«       | j                  |j                  «       d«       |j!                  «        |j                  j                  «       }| j                  d	|«       y
)zQ
        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)rH   ry  r	   r   r  r8   r{   r�  ÚgetvalueÚassertInr  r  r,   Úformatr‚   r  rË   )r   r#  Útrm   r5   Úvs         r   Útest_thingsGetLoggedz(LoggingFactoryTests.test_thingsGetLogged’  ss  € ô  ›ˆÜ";ˆÔÜ,Ó.ˆÜ˜~¨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                 ó‚  — t        «       }t        |d«      }| j                  |j                  d«       |j	                  d«       | j                  |j                  d«       d|_        |j	                  d«       | j                  |j                  d«       |j                  «        | j                  |j                  d«       y)zG
        Test counter management with the resetCounter method.
        r‡  r   rˆ  r   N)r‰  i/  rÚ   )rH   r  r‚   Ú_counterr8   r�  ÚresetCounter)r   r#  rm   s      r   Útest_counterz LoggingFactoryTests.test_counter´  s’   € ô  ›ˆÜ˜~¨vÓ6ˆØ×Ñ˜Ÿ™ QÔ'Ø	�‰Ð)Ô*Ø×Ñ˜Ÿ™ QÔ'àˆŒ
Ø	�‰Ð)Ô*Ø×Ñ˜Ÿ™ QÔ'à	�‰ÔØ×Ñ˜Ÿ™ QÕ'r   c                 óÔ  ‡‡	— g Šg Š	ˆˆ	fd„}| j                  t        d|«       t        j                  «       }t        |_        t        j                  |d«      }|j                  t        j                  ddd«      «      }|j                  t        j                  ddd«      «      }di f}d	i f}| j                  ||g‰«       | j                  |j                  |j                  g‰	«       y
)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                  óx   •— ‰j                  | |f«       t        «       }| d   |_        ‰j                  |«       |S )zX
            Mock for the open call to prevent actually opening a log file.
            r   )r«   r   r‚  )rQ   rR   ÚioÚ
open_callsÚopen_rvaluess      €€r   Úmocked_openzULoggingFactoryTests.test_loggingFactoryOpensLogfileAutomatically.<locals>.mocked_openÎ  s<   ø€ ð ×Ñ˜t V˜nÔ-Ü“ˆBØ˜1‘gˆBŒGØ×Ñ Ô#ØˆIr   rƒ  r‡  re   rf   r!  i:0  )ztest-1Úw)ztest-2rœ  N)ÚpatchÚbuiltinsr	   r"  r   r   ÚTrafficLoggingFactoryr8   r   ri   r‚   Úlogfile)
r   r›  r#  rl   Úfirst_protoÚsecond_protoÚ
first_callÚsecond_callr™  rš  s
           @@r   Ú,test_loggingFactoryOpensLogfileAutomaticallyz@LoggingFactoryTests.test_loggingFactoryOpensLogfileAutomaticallyÅ  sà   ù€ ð ˆ
Øˆõ	ð 	�
‰
”8˜V [Ô1ä!×/Ñ/Ó1ˆÜ"0ˆÔÜ×0Ñ0°ÀÓHˆØ×+Ñ+Ü×Ñ  {°EÓ:ó
ˆð ×,Ñ,Ü×Ñ  {°EÓ:ó
ˆð & rÐ*ˆ
Ø&¨Ð+ˆØ×Ñ˜* kÐ2°JÔ?Ø×Ñ˜+×-Ñ-¨|×/CÑ/CÐDÀlÕSr   N)r-   r.   r/   rI   r‘  r•  r¥  r0   r   r   r…  r…  �  s   „ ñò +òD(ó"$Tr   r…  ).rI   rž  r˜  r   Úzope.interfacer   r   r   Útwisted.internetr   r   r	   r
   r   Útwisted.internet.testingr   r   Útwisted.protocolsr   Útwisted.trialr   rz   r   ÚClientFactoryr2   r:   r"  rH   rN   rK   r`   r^   ÚTestCaserc   rh   rÓ   r  r6  ÚTimeoutMixinrG  rT  rg  ry  rŸ  r  r…  r0   r   r   ú<module>r®     sr  ðñó
 Ý ç @Ñ @ç DÕ Dß VÝ &Ý "ô�X×&Ñ&ô ô(�8×)Ñ)ô ô#�8×$Ñ$ô #ô ˆX×#Ñ#ô ô2 × :Ñ :ô 2ô*2˜X×4Ñ4ô 2ô*[3�8×$Ñ$ô [3ô|%�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   