§
    Ètºf"�  ã                   óþ  — 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j        ¦  «        Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Z G d„ dej         ¦  «        Z! G d„ dej"        ¦  «        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j&        ¦  «        Z' G d!„ d"ej         ¦  «        Z( G d#„ d$ej         ¦  «        Z) G d%„ d&e¦  «        Z* G d'„ d(ej+        ¦  «        Z, G d)„ d*ej         ¦  «        Z-dS )+z
Test code for policies.
é    N)ÚStringIO)Ú	InterfaceÚimplementedByÚimplementer)ÚaddressÚdeferÚprotocolÚreactorÚtask)ÚStringTransportÚ StringTransportWithDisconnection)Úpolicies)Úunittestc                   ó2   — e Zd ZdxZZdZd„ Zd„ Zd„ Zd„ Z	dS )ÚSimpleProtocolr   ó    c                 óf   — t          j        ¦   «         | _        t          j        ¦   «         | _        d S ©N)r   ÚDeferredÚ
dConnectedÚdDisconnected©Úselfs    úY/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/test/test_policies.pyÚ__init__zSimpleProtocol.__init__   s'   € Ýœ.Ñ*Ô*ˆŒÝ"œ^Ñ-Ô-ˆÔÐÐr   c                 óH   — d| _         | j                             d¦  «         d S ©Né   Ú )Ú	connectedr   Úcallbackr   s    r   ÚconnectionMadezSimpleProtocol.connectionMade   s%   € ØˆŒØŒ× Ò  Ñ$Ô$Ð$Ð$Ð$r   c                 óH   — d| _         | j                             d¦  «         d S r   )Údisconnectedr   r!   ©r   Úreasons     r   ÚconnectionLostzSimpleProtocol.connectionLost    s'   € ØˆÔØÔ×#Ò# BÑ'Ô'Ð'Ð'Ð'r   c                 ó&   — | xj         |z  c_         d S 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dS )ÚSillyFactoryc                 ó   — || _         d S 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ˆr   N)r-   r.   r/   r   r8   r0   r   r   r2   r2   (   s2   € € € € € ðð ð ðð ð ð ð r   r2   c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚEchoProtocolFc                 ó   — d| _         d S ©NT©Úpausedr   s    r   ÚpauseProducingzEchoProtocol.pauseProducing3   s   € ØˆŒˆˆr   c                 ó   — d| _         d S )NFr=   r   s    r   ÚresumeProducingzEchoProtocol.resumeProducing6   s   € ØˆŒˆˆr   c                 ó   — d S r   r0   r   s    r   ÚstopProducingzEchoProtocol.stopProducing9   s   € Øˆr   c                 ó:   — | j                              |¦  «         d S 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   sU   € € € € € Ø€Fðð ð ðð ð ðð ð ð#ð #ð #ð #ð #r   r:   c                   ó   — e Zd ZdZeZdS )ÚServerz8
    A simple server factory using L{EchoProtocol}.
    N)r-   r.   r/   Ú__doc__r:   r	   r0   r   r   rH   rH   @   s   € € € € € ðð ð €H€H€Hr   rH   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚTestableThrottlingFactoryzH
    L{policies.ThrottlingFactory} using a L{task.Clock} for tests.
    c                 óH   — t          j        j        | g|¢R i |¤Ž || _        dS ©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   s3   € õ 	Ô"Ô+¨DÐB°4ÐBÐBÐB¸6ÐBÐBÐBØˆŒ
ˆ
ˆ
r   c                 ó8   — | j                              ||¦  «        S ©z0
        Forward to the testable clock.
        ©rO   Ú	callLater©r   ÚperiodÚfuncs      r   rV   z#TestableThrottlingFactory.callLaterV   ó   € ð Œz×#Ò# F¨DÑ1Ô1Ð1r   N©r-   r.   r/   rI   r   rV   r0   r   r   rK   rK   H   ó<   € € € € € ðð ðð ð ð2ð 2ð 2ð 2ð 2r   rK   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚTestableTimeoutFactoryzE
    L{policies.TimeoutFactory} using a L{task.Clock} for tests.
    c                 óH   — t          j        j        | g|¢R i |¤Ž || _        dS rM   )r   ÚTimeoutFactoryr   rO   rP   s       r   r   zTestableTimeoutFactory.__init__b   s3   € õ 	ÔÔ(¨Ð?°Ð?Ð?Ð?¸Ð?Ð?Ð?ØˆŒ
ˆ
ˆ
r   c                 ó8   — | j                              ||¦  «        S rT   rU   rW   s      r   rV   z TestableTimeoutFactory.callLaterk   rZ   r   Nr[   r0   r   r   r^   r^   ]   r\   r   r^   c                   ór   — 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dS )ÚWrapperTestsz>
    Tests for L{WrappingFactory} and L{ProtocolWrapper}.
    c                 óÜ   — t          ¦   «         }t          j        |¦  «        }|                     t	          j        ddd¦  «        ¦  «        }|                      |j        j        |¦  «         dS )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   s_   € õ
 ‰HŒHˆÝÔ% aÑ(Ô(ˆØ×Ò�WÔ0°¸ÀRÑHÔHÑIÔIˆØ�Š�aÔ'Ô/°Ñ3Ô3Ð3Ð3Ð3r   c                 óª  —  G d„ dt           ¦  «        }t          |¦  «         G d„ d¦  «        ¦   «         }t          t          j        ¦  «         t          j        ¦   «         }t          j        t          j        d¦  «        |¦  «        }|                      |¦   «         ¦  «         |  	                    | 
                    |j        ¦  «        ¦  «         dS )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dS )ú=WrapperTests.test_transportInterfaces.<locals>.IStubTransportN©r-   r.   r/   r0   r   r   ÚIStubTransportrr   ˆ   ó   € € € € € ØˆDr   rt   c                   ó   — e Zd ZdS )ú<WrapperTests.test_transportInterfaces.<locals>.StubTransportNrs   r0   r   r   ÚStubTransportrw   ‹   s   € € € € € àˆDr   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ÀDÑ+IÔ+IÈ5ÑQÔQˆà×Ò˜}˜}™œÑ/Ô/Ð/Ø�Š˜×1Ò1°%´/ÑBÔBÑCÔCÐCÐCÐCr   c                 óš   — t          ¦   «         }t          j        |¦  «        }|                      d|                     ¦   «         ¦  «         dS )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ž   sF   € õ
 ‘”ˆÝÔ*¨6Ñ2Ô2ˆØ×ÒÐ3°W×5FÒ5FÑ5HÔ5HÑIÔIÐIÐIÐIr   c                 ó¬   —  G d„ d¦  «        } |¦   «         }t          j        |¦  «        }|                      d|                     ¦   «         ¦  «         dS )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dS )ú=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§   sp   € ð	ð 	ð 	ð 	ð 	ñ 	ô 	ð 	ð �‘”ˆÝÔ*¨6Ñ2Ô2ˆØ×ÒÐ6¸×8IÒ8IÑ8KÔ8KÑLÔLÐLÐLÐLr   c                 óâ   — t          ¦   «         }t          j        |¦  «        }|                     t	          j        ddd¦  «        ¦  «        }|                      d |j        ¦   «         ¦  «         dS )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´   si   € õ
 ‘”ˆÝÔ*¨6Ñ2Ô2ˆØ×(Ò(­Ô)<¸UÀKÐQSÑ)TÔ)TÑUÔUˆØ×ÒÐ9Ð;M¸8Ô;MÑ;OÔ;OÑPÔPÐPÐPÐPr   c                 ó
  —  G d„ d¦  «        }t          ¦   «         }||_        t          j        |¦  «        }|                     t          j        ddd¦  «        ¦  «        }|                      d |j        ¦   «         ¦  «         dS )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dS )ú?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¾   s˜   € ð	ð 	ð 	ð 	ð 	ñ 	ô 	ð 	õ ‘”ˆØ$ˆŒÝÔ*¨6Ñ2Ô2ˆØ×(Ò(­Ô)<¸UÀKÐQSÑ)TÔ)TÑUÔUˆØ×ÒÐ7Ð9K¸Ô9KÑ9MÔ9MÑNÔNÐNÐNÐNr   c                 óÔ   — t          j        t          j        t          ¦   «         ¦  «        t	          j        ¦   «         ¦  «        }t          ¦   «         }|                     |¦  «         |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Í   sY   € õ
 Ô*ÝÔ$¥V¡X¤XÑ.Ô.µÔ0AÑ0CÔ0Cñ
ô 
ˆõ $Ñ%Ô%ˆ	Ø×Ò˜yÑ)Ô)Ð)Øˆr   c                 ó¬   — |                       ¦   «         }|                      |                     ¦   «         |j                             ¦   «         ¦  «         dS )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Ù   óJ   € ð
 ×"Ò"Ñ$Ô$ˆØ×Ò˜ŸšÑ*Ô*¨GÔ,=×,EÒ,EÑ,GÔ,GÑHÔHÐHÐHÐHr   c                 ó¬   — |                       ¦   «         }|                      |                     ¦   «         |j                             ¦   «         ¦  «         dS )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                 óô   — |                       ¦   «         }t          ¦   «         }|                     |d¦  «         |                      |j        j        |¦  «         |                      |j        j        ¦  «         dS )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é   sl   € ð
 ×"Ò"Ñ$Ô$ˆÝ‘8”8ˆØ× Ò  ¨4Ñ0Ô0Ð0Ø�Š�gÔ'Ô0°(Ñ;Ô;Ð;Ø�Š˜Ô)Ô3Ñ4Ô4Ð4Ð4Ð4r   c                 ó  — |                       ¦   «         }t          ¦   «         }|                     |d¦  «         |                     ¦   «          |                      |j        j        ¦  «         |                      |j        j        ¦  «         dS )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ô   s€   € ð
 ×"Ò"Ñ$Ô$ˆÝ‘8”8ˆØ× Ò  ¨4Ñ0Ô0Ð0Ø×"Ò"Ñ$Ô$Ð$Ø×Ò˜'Ô+Ô4Ñ5Ô5Ð5Ø×Ò˜'Ô+Ô5Ñ6Ô6Ð6Ð6Ð6r   c                 ó¨   ‡— |                       ¦   «         }g Šˆfd„|j        _        |                     ¦   «          |                      ‰dg¦  «         dS )zw
        L{policies.ProtocolWrapper.stopConsuming} calls C{stopConsuming} on
        the underlying transport.
        c                  ó.   •— ‰                       d¦  «        S r<   ©Úappend©Úresults   €r   ú<lambda>z1WrapperTests.test_stopConsuming.<locals>.<lambda>  s   ø€ °&·-²-ÀÑ2EÔ2E€ r   TN)r”   rE   ÚstopConsumingr‚   )r   r   r­   s     @r   Útest_stopConsumingzWrapperTests.test_stopConsuming   s_   ø€ ð
 ×"Ò"Ñ$Ô$ˆØˆØ*EÐ*EÐ*EÐ*EˆÔÔ'Ø×ÒÑÔÐØ×Ò˜ $ Ñ(Ô(Ð(Ð(Ð(r   c                 óÖ   ‡— g Š G ˆfd„d¦  «        }t          j         |¦   «         ¦  «        }t          ¦   «         }|                     |¦  «         |                      ‰|g¦  «         dS )z}
        L{policies.WrappingFactory.startedConnecting} calls
        C{startedConnecting} on the underlying factory.
        c                   ó   •— e Zd Zˆ fd„ZdS )ú4WrapperTests.test_startedConnecting.<locals>.Factoryc                 ó2   •— ‰                      |¦  «         d S 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  s�   ø€ ð
 ˆð	)ð 	)ð 	)ð 	)ð 	)ð 	)ð 	)ñ 	)ô 	)ð 	)õ Ô*¨7¨7©9¬9Ñ5Ô5ˆÝ‘H”Hˆ	Ø×!Ò! )Ñ,Ô,Ð,Ø×Ò˜ ) Ñ-Ô-Ð-Ð-Ð-r   c                 óø   ‡— g Š G ˆfd„d¦  «        }t          j         |¦   «         ¦  «        }t          ¦   «         }t          ¦   «         }|                     ||¦  «         |                      ‰||fg¦  «         dS )zƒ
        L{policies.WrappingFactory.clientConnectionLost} calls
        C{clientConnectionLost} on the underlying factory.
        c                   ó   •— e Zd Zˆ fd„ZdS )ú7WrapperTests.test_clientConnectionLost.<locals>.Factoryc                 ó6   •— ‰                      ||f¦  «         d S r   rª   ©r   rµ   r&   r­   s      €r   ÚclientConnectionLostzLWrapperTests.test_clientConnectionLost.<locals>.Factory.clientConnectionLost#  ó    ø€ Ø—’˜y¨&Ð1Ñ2Ô2Ð2Ð2Ð2r   N)r-   r.   r/   r¾   r¬   s   €r   r·   r»   "  ó.   ø€ € € € € ð3ð 3ð 3ð 3ð 3ð 3ð 3r   r·   N)r   rh   rž   r¾   r‚   ©r   r·   r   rµ   r&   r­   s        @r   Útest_clientConnectionLostz&WrapperTests.test_clientConnectionLost  s    ø€ ð
 ˆð	3ð 	3ð 	3ð 	3ð 	3ð 	3ð 	3ñ 	3ô 	3ð 	3õ Ô*¨7¨7©9¬9Ñ5Ô5ˆÝ‘H”Hˆ	Ý‘”ˆØ×$Ò$ Y°Ñ7Ô7Ð7Ø×Ò˜ 9¨fÐ"5Ð!6Ñ7Ô7Ð7Ð7Ð7r   c                 óø   ‡— g Š G ˆfd„d¦  «        }t          j         |¦   «         ¦  «        }t          ¦   «         }t          ¦   «         }|                     ||¦  «         |                      ‰||fg¦  «         dS )z‡
        L{policies.WrappingFactory.clientConnectionFailed} calls
        C{clientConnectionFailed} on the underlying factory.
        c                   ó   •— e Zd Zˆ fd„ZdS )ú9WrapperTests.test_clientConnectionFailed.<locals>.Factoryc                 ó6   •— ‰                      ||f¦  «         d S 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ð 	3ð 	3ð 	3ð 	3ð 	3ñ 	3ô 	3ð 	3õ Ô*¨7¨7©9¬9Ñ5Ô5ˆÝ‘H”Hˆ	Ý‘”ˆØ×&Ò& y°&Ñ9Ô9Ð9Ø×Ò˜ 9¨fÐ"5Ð!6Ñ7Ô7Ð7Ð7Ð7r   c                 ór  — t          j        t          j        t          ¦   «         ¦  «        t	          j        ¦   «         ¦  «        }t          ¦   «         }||_        |                     |¦  «         |                      |j	        ¦  «         | 
                    ¦   «          |                      |j	        ¦  «         dS )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¤XÑ.Ô.µÔ0AÑ0CÔ0Cñ
ô 
ˆõ 5Ñ6Ô6ˆ	Ø$ˆ	ÔØ×Ò˜yÑ)Ô)Ð)à×Ò˜WÔ4Ñ5Ô5Ð5Ø× Ò Ñ"Ô"Ð"Ø×Ò˜'Ô1Ñ2Ô2Ð2Ð2Ð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ð 4ð 4ðDð Dð Dð:Jð Jð JðMð Mð MðQð Qð QðOð Oð Oð
ð 
ð 
ðIð Ið IðIð Ið Ið	5ð 	5ð 	5ð
7ð 
7ð 
7ð	)ð 	)ð 	)ð.ð .ð .ð 8ð 8ð 8ð"8ð 8ð 8ð"3ð 3ð 3ð 3ð 3r   rc   c                   ó   — e Zd Zd„ Zd„ ZdS )rh   c                 ó   — |S r   r0   )r   rm   r5   s      r   r	   zWrappingFactory.protocolQ  s   € Øˆr   c                 óx   — t           j                             | ¦  «         | j                             d ¦  «         d S r   )r   rh   ÚstartFactoryÚdeferredr!   r   s    r   rÐ   zWrappingFactory.startFactoryT  s5   € ÝÔ ×-Ò-¨dÑ3Ô3Ð3ØŒ×Ò˜tÑ$Ô$Ð$Ð$Ð$r   N)r-   r.   r/   r	   rÐ   r0   r   r   rh   rh   P  s2   € € € € € ðð ð ð%ð %ð %ð %ð %r   rh   c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚThrottlingTestsz2
    Tests for L{policies.ThrottlingFactory}.
    c                 óÚ  ‡ ‡	‡
‡‡‡‡‡— t          ¦   «         }d„ t          d¦  «        D ¦   «         \  Š	Š
ŠŠt          j        |d¦  «        Št	          ‰¦  «        }t          j        ¦   «         |_        t          j	        d|d¬¦  «        Š‰ 
                    ¦   «         j        Šˆ	ˆ
ˆˆfd„}ˆ	ˆ
ˆˆ ˆfd„}ˆ	fd	„}ˆˆfd
„}ˆˆ fd„}ˆ
ˆˆfd„}|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   ó2   K  — | ]}t          ¦   «         V — Œd S r   )r   )Ú.0Úis     r   ú	<genexpr>z-ThrottlingTests.test_limit.<locals>.<genexpr>f  s(   è è € Ð=Ð=¨q�.Ñ*Ô*Ð=Ð=Ð=Ð=Ð=Ð=r   é   é   r   rf   )Ú	interfacec                 óÐ   •— t          j        d‰t          ‰¦  «        ¦  «         ‰j                             ˆˆfd„¦  «         ‰j                             ˆˆfd„¦  «         ‰j        S )Nrf   c                 óJ   •— t          j        d‰t          ‰¦  «        ¦  «        S ©Nrf   ©r
   Ú
connectTCPr2   )ÚrÚc2Úns    €€r   r®   zAThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>r  ó   ø€ �'Ô,¨[¸!½\È"Ñ=MÔ=MÑNÔN€ r   c                 óJ   •— 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  s   ø€ ÝÔ˜{¨A­|¸BÑ/?Ô/?Ñ@Ô@Ð@ØŒM×%Ò%ØNÐNÐNÐNÐNñô ð ð ŒM×%Ò%ØNÐNÐNÐNÐNñô ð ð Ô#Ð#r   c                 ó  •— ‰                      d„ ‰‰‰fD ¦   «         g d¢¦  «         ‰                      d„ ‰‰‰fD ¦   «         g d¢¦  «         ‰                      t          ‰j                             ¦   «         ¦  «        d¦  «         | S )Nc                 ó   — g | ]	}|j         ‘Œ
S r0   )r    ©rÖ   Úcs     r   ú
<listcomp>zAThrottlingTests.test_limit.<locals>._check123.<locals>.<listcomp>z  s   € Ð@Ð@Ð@¨a˜aœkÐ@Ð@Ð@r   )r   r   r   c                 ó   — g | ]	}|j         ‘Œ
S r0   )r$   rí   s     r   rï   zAThrottlingTests.test_limit.<locals>._check123.<locals>.<listcomp>{  s   € ÐCÐCÐC°˜aœnÐCÐCÐCr   )r   r   r   rÚ   )r‚   ÚlenÚ	protocolsÚkeys)rè   ré   râ   ræ   r   ÚtServers    €€€€€r   Ú	_check123z-ThrottlingTests.test_limit.<locals>._check123y  s“   ø€ Ø×ÒÐ@Ð@°B¸¸B°<Ð@Ñ@Ô@À)À)À)ÑLÔLÐLØ×ÒÐCÐC°r¸2¸r°lÐCÑCÔCÀYÀYÀYÑOÔOÐOØ×Ò�S Ô!2×!7Ò!7Ñ!9Ô!9Ñ:Ô:¸AÑ>Ô>Ð>ØˆNr   c                 óD   •— ‰j                              ¦   «          ‰j        S r   )rE   rË   r   )rè   ré   s    €r   Ú_lose1z*ThrottlingTests.test_limit.<locals>._lose1  s    ø€ àŒL×'Ò'Ñ)Ô)Ð)ØÔ#Ð#r   c                 óX   •— 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                 ót   •— ‰                      ‰j        d¦  «         ‰                      ‰j        d¦  «         | S )Nr   r   )r‚   r    r$   )rè   rù   r   s    €€r   Ú_check4z+ThrottlingTests.test_limit.<locals>._check4ˆ  s8   ø€ Ø×Ò˜Rœ\¨1Ñ-Ô-Ð-Ø×Ò˜Rœ_¨aÑ0Ô0Ð0ØˆNr   c                 ó´   •— ‰‰fD ]}|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�  sc   ø€ Ø˜�Vð -ð -�Ø”×*Ò*Ñ,Ô,Ð,Ð,ÝÔ%åÔ'¨¬Ñ8Ô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´HÐ=Ñ=Ô=‰ˆˆB��BÝÔ,¨V°QÑ7Ô7ˆÝ% gÑ.Ô.ˆÝ$œ~Ñ/Ô/ˆÔõ Ô˜a ¸ÐDÑDÔDˆØ�IŠI‰KŒKÔˆð	$ð 	$ð 	$ð 	$ð 	$ð 	$ð 	$ð 	$ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð	$ð 	$ð 	$ð 	$ð 	$ð
	!ð 	!ð 	!ð 	!ð 	!ð 	!ð	ð 	ð 	ð 	ð 	ð 	ð
		ð 		ð 		ð 		ð 		ð 		ð 		ð 	Ô×(Ò(¨Ñ5Ô5Ð5ØÔ×(Ò(¨Ñ3Ô3Ð3ØÔ×(Ò(¨Ñ0Ô0Ð0ØÔ×(Ò(¨Ñ3Ô3Ð3ØÔ×(Ò(¨Ñ1Ô1Ð1ØÔ×(Ò(¨Ñ2Ô2Ð2ØÔ#Ð#r   c                 ó®  — t          ¦   «         }t          t          j        ¦   «         |¦  «        }|                     t          j        ddd¦  «        ¦  «        }t          ¦   «         }||_         |j	        |¦  «          |j
        dgdz  ¦  «         |                      |                     ¦   «         d¦  «         |                      |j        d¦  «         dS )	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©L¬L¸&ÑAÔAˆØ×(Ò(­Ô)<¸UÀKÐQRÑ)SÔ)SÑTÔTˆÝ4Ñ6Ô6ˆ	Ø%ˆ	ÔØˆÔ 	Ñ*Ô*Ð*àˆÔ ˜z¨A™~Ñ.Ô.Ð.Ø×Ò˜ŸšÑ*Ô*Ð,CÑDÔDÐDØ×Ò˜Ô2°BÑ7Ô7Ð7Ð7Ð7r   c                 óŽ  — t          ¦   «         }t          t          j        ¦   «         |d¬¦  «        }|                     t          j        ddd¦  «        ¦  «        }t          ¦   «         }||_        | 	                    |¦  «         |j
        |_        |                     d¦  «         |                     d¦  «         |                      |                     ¦   «         d¦  «         |                      |j        d	¦  «         |                      |j
        j        ¦  «         |j                             d
¦  «         |                      |j        d¦  «         |                      |j
        j        ¦  «         |j                             d
¦  «         |                      |j        d¦  «         |                      |j
        j        ¦  «         dS )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¯  s‹  € õ
 ‘”ˆÝ+­D¬J©L¬L¸&ÈRÐPÑPÔPˆØ×$Ò$¥WÔ%8¸ÀÈQÑ%OÔ%OÑPÔPˆÝ-Ñ/Ô/ˆØˆŒØ×Ò˜BÑÔÐØÔ,ˆŒà×Ò˜-Ñ(Ô(Ð(Ø×Ò˜-Ñ(Ô(Ð(Ø×Ò˜Ÿš™œÐ%<Ñ=Ô=Ð=Ø×Ò˜Ô2°BÑ7Ô7Ð7Ø×Ò˜Ô-Ô4Ñ5Ô5Ð5ð
 	Œ×Ò˜dÑ#Ô#Ð#Ø×Ò˜Ô2°AÑ6Ô6Ð6Ø�Š˜Ô,Ô3Ñ4Ô4Ð4àŒ×Ò˜dÑ#Ô#Ð#Ø×Ò˜Ô2°AÑ6Ô6Ð6Ø×Ò˜Ô-Ô4Ñ5Ô5Ð5Ð5Ð5r   c                 ój  — t          ¦   «         }t          t          j        ¦   «         |d¬¦  «        }|                     t          j        ddd¦  «        ¦  «        }t          ¦   «         }||_        | 	                    |¦  «         | 
                    d¦  «         | 
                    d¦  «         |                      |                     ¦   «         d¦  «         |                      |j        d	¦  «         |j                             d
¦  «         |                      |j        d¦  «         |                      |j        d¦  «         |j                             d
¦  «         |                      |j        d¦  «         |                      |j        d¦  «         |                     ¦   «          | 
                    d¦  «         | 
                    d¦  «         |                      |                     ¦   «         d¦  «         |                      |j        d	¦  «         |j                             d
¦  «         |                      |j        d¦  «         |                      |j        d¦  «         |j                             d
¦  «         |                      |j        d¦  «         |                      |j        d¦  «         dS )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Í  sb  € õ
 ‘”ˆÝ+­D¬J©L¬L¸&ÈBÐOÑOÔOˆØ×$Ò$¥WÔ%8¸ÀÈQÑ%OÔ%OÑPÔPˆÝ-Ñ/Ô/ˆØˆŒØ×Ò˜BÑÔÐà×Ò˜-Ñ(Ô(Ð(Ø×Ò˜-Ñ(Ô(Ð(Ø×Ò˜Ÿš™œÐ%<Ñ=Ô=Ð=Ø×Ò˜Ô/°Ñ4Ô4Ð4àŒ×Ò˜dÑ#Ô#Ð#Ø×Ò˜Ô/°Ñ3Ô3Ð3Ø×Ò˜Ô)¨8Ñ4Ô4Ð4àŒ×Ò˜dÑ#Ô#Ð#Ø×Ò˜Ô/°Ñ3Ô3Ð3Ø×Ò˜Ô)¨;Ñ7Ô7Ð7à
�Š‰
Œ
ˆ
Ø×Ò˜-Ñ(Ô(Ð(Ø×Ò˜-Ñ(Ô(Ð(Ø×Ò˜Ÿš™œÐ%<Ñ=Ô=Ð=Ø×Ò˜Ô/°Ñ4Ô4Ð4àŒ×Ò˜dÑ#Ô#Ð#Ø×Ò˜Ô/°Ñ3Ô3Ð3Ø×Ò˜Ô)¨8Ñ4Ô4Ð4àŒ×Ò˜dÑ#Ô#Ð#Ø×Ò˜Ô/°Ñ3Ô3Ð3Ø×Ò˜Ô)¨;Ñ7Ô7Ð7Ð7Ð7r   N)r-   r.   r/   rI   r  r  r  r!  r0   r   r   rÓ   rÓ   Y  s^   € € € € € ðð ð@$ð @$ð @$ðD8ð 8ð 8ð6ð 6ð 6ð<%8ð %8ð %8ð %8ð %8r   rÓ   c                   ó0   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚTimeoutProtocolTestsz0
    Tests for L{policies.TimeoutProtocol}.
    c                 ó6  — t          j        ¦   «         }t          j        ¦   «         }t          |_        t          ||d¦  «        }|                     t          j        ddd¦  «        ¦  «        }t          ¦   «         }||_        | 
                    |¦  «         ||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ú  s‰   € õ ”
‘”ˆå!Ô/Ñ1Ô1ˆÝ"0ˆÔå(¨°ÀÑEÔEˆà×%Ò%¥gÔ&9¸%ÀÈeÑ&TÔ&TÑUÔUˆå4Ñ6Ô6ˆ	Ø"ˆ	ÔØ×Ò˜YÑ'Ô'Ð'à�uˆ~Ðr   c                 ó¾  — |                       ¦   «         \  }}|                     d¦  «         |                      |j        ¦  «         |                      |j        j        ¦  «         |                     d¦  «         |                     ¦   «          |  	                    |j        ¦  «         |                     d¦  «         |                      |j        j        ¦  «         dS )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Ñ:Ô:Ð:à�Š�aÑÔÐØ×ÒÑÔÐà×Ò˜#œ/Ñ*Ô*Ð*ð 	�Š�aÑÔÐØ×Ò˜Ô,Ô9Ñ:Ô:Ð:Ð:Ð:r   c                 óÎ   — |                       ¦   «         \  }}|                      |j        ¦  «         |                     ¦   «          |                      |j        j        ¦  «         dS )z<
        Does nothing if no timeout is already set.
        N)r(  r¦   r,  r-  r  rk   r$   r.  s      r   Útest_cancelTimeoutNoTimeoutz0TimeoutProtocolTests.test_cancelTimeoutNoTimeout#  sc   € ð ×-Ò-Ñ/Ô/‰
ˆˆUØ×Ò˜#œ/Ñ*Ô*Ð*à×ÒÑÔÐð 	×Ò˜Ô,Ô9Ñ:Ô:Ð:Ð:Ð:r   c                 óò   — |                       ¦   «         \  }}|j        }|                     d¦  «         |                     d¦  «         |                      |j        ¦  «         |                     ¦   «          dS )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/  st   € ð ×-Ò-Ñ/Ô/‰
ˆˆUØÔ*ˆØ�Š�qÑÔÐà�Š�aÑÔÐØ�Š˜Ô1Ñ2Ô2Ð2ð 	×ÒÑÔÐÐÐr   c                 óö   — |                       ¦   «         \  }}|                     d¦  «         |j                             ¦   «          |                     ¦   «          |                      |j        j        ¦  «         dS )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=  ss   € ð
 ×-Ò-Ñ/Ô/‰
ˆˆUØ�Š�qÑÔÐàŒ×ÒÑ Ô Ð ð 	×ÒÑÔÐà×Ò˜Ô,Ô9Ñ:Ô:Ð:Ð:Ð:r   N)	r-   r.   r/   rI   r(  r0  r2  r5  r8  r0   r   r   r#  r#  õ  si   € € € € € ðð ðð ð ð,;ð ;ð ;ð&
;ð 
;ð 
;ðð ð ð;ð ;ð ;ð ;ð ;r   r#  c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚTimeoutFactoryTestsz/
    Tests for L{policies.TimeoutFactory}.
    c                 ó¸  — t          j        ¦   «         | _        t          j        ¦   «         }t
          |_        t          | j        |d¦  «        | _        | j                             t          j
        ddd¦  «        ¦  «        | _        t          ¦   «         | _        | j        | j        _        | j                             | j        ¦  «         | j        j        | _        dS )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   r4  )r   r'  s     r   ÚsetUpzTimeoutFactoryTests.setUpR  s­   € õ
 ”Z‘\”\ˆŒ
Ý!Ô/Ñ1Ô1ˆÝ"0ˆÔÝ-¨d¬j¸.È!ÑLÔLˆŒØ”\×/Ò/ÝÔ  {°EÑ:Ô:ñ
ô 
ˆŒ
õ :Ñ;Ô;ˆŒØ"&¤*ˆŒÔØŒ
×!Ò! $¤.Ñ1Ô1Ð1Ø œJÔ6ˆÔÐÐr   c                 óò   — | j                              g d¢¦  «         |                      | j        j        ¦  «         | j                              ddg¦  «         |                      | j        j        ¦  «         dS )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  r4  r$   r|   r   s    r   Útest_timeoutz TimeoutFactoryTests.test_timeoutc  sq   € ð 	Œ
�ŠÐ1Ð1Ð1Ñ2Ô2Ð2Ø×Ò˜Ô*Ô7Ñ8Ô8Ð8ð 	Œ
�Š˜˜c˜
Ñ#Ô#Ð#Ø�Š˜Ô)Ô6Ñ7Ô7Ð7Ð7Ð7r   c                 óN  — | j                              g d¢¦  «         |                      | j        j        ¦  «         | j                             d¦  «         | j                              g d¢¦  «         |                      | j        j        ¦  «         | j                             dgdz  ¦  «         | j                              g d¢¦  «         |                      | j        j        ¦  «         | j                              ddg¦  «         |                      | j        j        ¦  «         dS )	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   rB  r  r4  r$   r~   rF   r  r|   r   s    r   Útest_sendAvoidsTimeoutz*TimeoutFactoryTests.test_sendAvoidsTimeoutq  s  € ð 	Œ
�Š˜˜˜Ñ(Ô(Ð(Ø×Ò˜Ô*Ô7Ñ8Ô8Ð8ð 	Œ
×ÒÐ-Ñ.Ô.Ð.ð 	Œ
�Š˜˜˜Ñ(Ô(Ð(Ø×Ò˜Ô*Ô7Ñ8Ô8Ð8ð 	Œ
× Ò  ( ¨a¡Ñ0Ô0Ð0ð 	Œ
�Š˜˜˜Ñ(Ô(Ð(Ø×Ò˜Ô*Ô7Ñ8Ô8Ð8ð 	Œ
�Š˜˜c˜
Ñ#Ô#Ð#Ø�Š˜Ô)Ô6Ñ7Ô7Ð7Ð7Ð7r   c                 óœ  — | j                              g d¢¦  «         |                      | j        j        ¦  «         | j                             d¦  «         | j                              g d¢¦  «         |                      | j        j        ¦  «         | j                              g d¢¦  «         |                      | j        j        ¦  «         dS )zR
        Make sure that receiving data also resets the timeout countdown.
        )r>  r@  r?  rE  rF  N)rO   rB  r  r4  r$   r~   r,   r|   r   s    r   Útest_receiveAvoidsTimeoutz-TimeoutFactoryTests.test_receiveAvoidsTimeout�  s»   € ð
 	Œ
�Š˜˜˜Ñ(Ô(Ð(Ø×Ò˜Ô*Ô7Ñ8Ô8Ð8ð 	Œ
×ÒÐ 4Ñ5Ô5Ð5ð 	Œ
�Š˜˜˜Ñ(Ô(Ð(Ø×Ò˜Ô*Ô7Ñ8Ô8Ð8ð 	Œ
�Š˜˜˜Ñ(Ô(Ð(Ø�Š˜Ô)Ô6Ñ7Ô7Ð7Ð7Ð7r   N)r-   r.   r/   rI   r<  rC  rG  rI  r0   r   r   r:  r:  M  sZ   € € € € € ðð ð7ð 7ð 7ð"8ð 8ð 8ð8ð 8ð 8ð88ð 8ð 8ð 8ð 8r   r:  c                   ó@   — e Zd ZdZdZdZd„ Zd„ Zd„ Zdd„Z	d	„ Z
d
„ ZdS )Ú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                 ó   — || _         dS )zF
        Initialize the protocol with a C{task.Clock} object.
        N)rO   )r   rO   s     r   r   zTimeoutTester.__init__­  s   € ð ˆŒ
ˆ
ˆ
r   c                 ó:   — |                       | j        ¦  «         dS )z3
        Upon connection, set the timeout.
        N)r+  ÚtimeOutr   s    r   r"   zTimeoutTester.connectionMade³  s   € ð 	�Š˜œÑ%Ô%Ð%Ð%Ð%r   c                 ón   — |                       ¦   «          t          j                             | |¦  «         dS )z,
        Reset the timeout on data.
        N)ÚresetTimeoutr	   rz   r,   r*   s     r   r,   zTimeoutTester.dataReceived¹  s5   € ð 	×ÒÑÔÐÝÔ×&Ò& t¨TÑ2Ô2Ð2Ð2Ð2r   Nc                 ó0   — |                       d¦  «         dS )zD
        On connection lost, cancel all timeout operations.
        N)r+  r%   s     r   r'   zTimeoutTester.connectionLostÀ  s   € ð 	�Š˜ÑÔÐÐÐr   c                 ó   — d| _         dS )zX
        Flags the timedOut variable to indicate the timeout of the connection.
        TN)ÚtimedOutr   s    r   ÚtimeoutConnectionzTimeoutTester.timeoutConnectionÆ  s   € ð ˆŒˆˆr   c                 ó0   —  | j         j        ||g|¢R i |¤ŽS )zD
        Override callLater to use the deterministic clock.
        rU   )r   ÚtimeoutrY   rQ   rR   s        r   rV   zTimeoutTester.callLaterÌ  s+   € ð $ˆtŒzÔ# G¨TÐC°DÐCÐCÐC¸FÐCÐCÐCr   r   )r-   r.   r/   rI   rN  rS  r   r"   r,   r'   rT  rV   r0   r   r   rK  rK  ¢  sŽ   € € € € € ðð ð €GØ€Hðð ð ð&ð &ð &ð3ð 3ð 3ðð ð ð ðð ð ðDð Dð Dð Dð Dr   rK  c                   óB   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
S )ÚTimeoutMixinTestsz-
    Tests for L{policies.TimeoutMixin}.
    c                 óh   — t          j        ¦   «         | _        t          | j        ¦  «        | _        dS )zY
        Create a testable, deterministic clock and a C{TimeoutTester} instance.
        N)r   r
  rO   rK  r~   r   s    r   r<  zTimeoutMixinTests.setUpØ  s&   € õ ”Z‘\”\ˆŒ
Ý" 4¤:Ñ.Ô.ˆŒ
ˆ
ˆ
r   c                 ó”   — | j                              d¦  «         |                      t          | j        j        ¦  «        d¦  «         dS )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ß  sC   € ð
 	Œ
×Ò˜bÑ!Ô!Ð!Ø×Ò�˜TœZÔ-Ñ.Ô.°Ñ2Ô2Ð2Ð2Ð2r   c                 ó>  — | j                              t          ¦   «         ¦  «         | j                             g d¢¦  «         |                      | j         j        ¦  «         | j                             ddg¦  «         |                      | j         j        ¦  «         dS )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   rB  r  rS  r|   r   s    r   rC  zTimeoutMixinTests.test_timeoutç  s‹   € ð
 	Œ
×!Ò!¥/Ñ"3Ô"3Ñ4Ô4Ð4ð 	Œ
�ŠÐ*Ð*Ð*Ñ+Ô+Ð+Ø×Ò˜œÔ,Ñ-Ô-Ð-ØŒ
�Š˜˜C˜Ñ!Ô!Ð!Ø�Š˜œ
Ô+Ñ,Ô,Ð,Ð,Ð,r   c                 óè  — | j                              t          ¦   «         ¦  «         | j                             g d¢¦  «         |                      | j         j        ¦  «         | j                              d¦  «         | j                             g d¢¦  «         |                      | j         j        ¦  «         | j                             ddg¦  «         |                      | j         j        ¦  «         dS )zV
        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   rO   rB  r  rS  r,   r|   r   s    r   Útest_noTimeoutz TimeoutMixinTests.test_noTimeoutô  sÓ   € ð 	Œ
×!Ò!¥/Ñ"3Ô"3Ñ4Ô4Ð4àŒ
�ŠÐ*Ð*Ð*Ñ+Ô+Ð+Ø×Ò˜œÔ,Ñ-Ô-Ð-ØŒ
×Ò Ñ/Ô/Ð/ØŒ
�ŠÐ*Ð*Ð*Ñ+Ô+Ð+Ø×Ò˜œÔ,Ñ-Ô-Ð-ØŒ
�Š˜˜C˜Ñ!Ô!Ð!Ø�Š˜œ
Ô+Ñ,Ô,Ð,Ð,Ð,r   c                 óÊ  — d| j         _        | j                              t          ¦   «         ¦  «         | j                              d¦  «         |                      | j         j        d¦  «         | j                             ddg¦  «         |                      | j         j	        ¦  «         | j                             ddg¦  «         |  
                    | j         j	        ¦  «         dS )zy
        Check that setting a new value for timeout cancel the previous value
        and install a new timeout.
        Nr   r   gÍÌÌÌÌÌì?rA  )r~   rN  r{   r   r+  r‚   rO   rB  r  rS  r|   r   s    r   Útest_resetTimeoutz#TimeoutMixinTests.test_resetTimeout  sÁ   € ð
 "ˆŒ
ÔØŒ
×!Ò!¥/Ñ"3Ô"3Ñ4Ô4Ð4àŒ
×Ò˜aÑ Ô Ð Ø×Ò˜œÔ+¨QÑ/Ô/Ð/àŒ
�Š˜˜C˜Ñ!Ô!Ð!Ø×Ò˜œÔ,Ñ-Ô-Ð-ØŒ
�Š˜˜C˜Ñ!Ô!Ð!Ø�Š˜œ
Ô+Ñ,Ô,Ð,Ð,Ð,r   c                 óR  — d| j         _        | j                              t          ¦   «         ¦  «         | j                              d¦  «         |                      | j         j        ¦  «         | j                             g d¢¦  «         |                      | j         j	        ¦  «         dS )zO
        Setting the timeout to L{None} cancel any timeout operations.
        é   N)r   rd  rd  rd  )
r~   rN  r{   r   r+  r¦   rO   rB  r  rS  r   s    r   r0  z$TimeoutMixinTests.test_cancelTimeout  s�   € ð ˆŒ
ÔØŒ
×!Ò!¥/Ñ"3Ô"3Ñ4Ô4Ð4àŒ
×Ò˜dÑ#Ô#Ð#Ø×Ò˜$œ*Ô,Ñ-Ô-Ð-àŒ
�Š˜˜˜Ñ%Ô%Ð%Ø×Ò˜œÔ,Ñ-Ô-Ð-Ð-Ð-r   c                 ó¤  — d| j         _        |                      | j                              d¦  «        d¦  «         |                      | j                              d¦  «        d¦  «         |                      | j                              d¦  «        ¦  «         |                      | j         j        d¦  «         | j                              d¦  «         dS )zM
        setTimeout should return the value of the previous timeout.
        rd  r  Nr   )r~   rN  r‚   r+  r¦   r   s    r   Útest_setTimeoutReturnz'TimeoutMixinTests.test_setTimeoutReturn  s·   € ð ˆŒ
Ôà×Ò˜œ×.Ò.¨rÑ2Ô2°AÑ6Ô6Ð6Ø×Ò˜œ×.Ò.¨tÑ4Ô4°bÑ9Ô9Ð9Ø×Ò˜$œ*×/Ò/°Ñ2Ô2Ñ3Ô3Ð3Ø×Ò˜œÔ+¨QÑ/Ô/Ð/ð 	Œ
×Ò˜dÑ#Ô#Ð#Ð#Ð#r   c                 óL  — | j                              d¦  «         | j                             ¦   «         d                              ¦   «          |                      | j         j        ¦  «         | j                              d¦  «         |                      | j         j        ¦  «         dS )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   ÚgetDelayedCallsr7  rÊ   rN  r¦   r   s    r   Ú%test_setTimeoutCancleAlreadyCancelledz7TimeoutMixinTests.test_setTimeoutCancleAlreadyCancelled-  s�   € ð 	Œ
×Ò˜aÑ Ô Ð ð 	Œ
×"Ò"Ñ$Ô$ QÔ'×.Ò.Ñ0Ô0Ð0Ø×Ò˜TœZÔ/Ñ0Ô0Ð0àŒ
×Ò˜dÑ#Ô#Ð#à×Ò˜$œ*Ô,Ñ-Ô-Ð-Ð-Ð-r   N)r-   r.   r/   rI   r<  r\  rC  r`  rb  r0  rf  ri  r0   r   r   rX  rX  Ó  s–   € € € € € ðð ð/ð /ð /ð3ð 3ð 3ð-ð -ð -ð-ð -ð -ð-ð -ð -ð .ð .ð .ð$ð $ð $ð.ð .ð .ð .ð .r   rX  c                   ó   — e Zd ZdZd„ Zd„ ZdS )Ú!LimitTotalConnectionsFactoryTestsz/Tests for policies.LimitTotalConnectionsFactoryc                 ó  — t          j        ¦   «         }t          j        |_        |                      d|j        ¦  «         |                     d ¦  «        }|                      d|j        ¦  «         |                     d ¦  «        }|                      d|j        ¦  «         |                     d ¦  «         |                      d|j        ¦  «         |                     d ¦  «         |                      d|j        ¦  «         d S )Nr   r   rÚ   )r   ÚLimitTotalConnectionsFactoryr	   rz   r‚   ÚconnectionCountr8   r'   )r   rl   Úp1Úp2s       r   ÚtestConnectionCountingz8LimitTotalConnectionsFactoryTests.testConnectionCountingA  sò   € åÔ7Ñ9Ô9ˆÝ#Ô,ˆÔð 	×Ò˜˜GÔ3Ñ4Ô4Ð4ð ×"Ò" 4Ñ(Ô(ˆØ×Ò˜˜GÔ3Ñ4Ô4Ð4Ø×"Ò" 4Ñ(Ô(ˆØ×Ò˜˜GÔ3Ñ4Ô4Ð4ð 	×Ò˜$ÑÔÐØ×Ò˜˜GÔ3Ñ4Ô4Ð4Ø
×Ò˜$ÑÔÐØ×Ò˜˜GÔ3Ñ4Ô4Ð4Ð4Ð4r   c                 ó<  ‡— t          j        ¦   «         Št          j        ‰_        d‰_        ‰                     d ¦  «        }|                      |¦  «         |                      d‰j        ¦  «         |  	                    ‰                     d ¦  «        ¦  «         |                      d‰j        ¦  «          G ˆfd„dt          j        ¦  «        }|‰_
        d‰_        ‰                     d ¦  «        }|                     d ¦  «         |                      ‰j        ¦  «         |                      d‰j        ¦  «         |                     d ¦  «         |                      d‰j        ¦  «         |                     d ¦  «         |                      d‰j        ¦  «         d S )Nr   c                   ó   •— e Zd Zˆ fd„ZdS )úRLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocolc                 ó   •— d‰_         d S r<   )Ú
overflowed)r   rl   s    €r   r"   zaLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocol.connectionMadeg  s   ø€ Ø%)�Ô"Ð"Ð"r   N)r-   r.   r/   r"   )rl   s   €r   ÚOverflowProtocolrt  f  s.   ø€ € € € € ð*ð *ð *ð *ð *ð *ð *r   rw  FrÚ   r   )r   rm  r	   rz   ÚconnectionLimitr8   rÊ   r‚   rn  r¦   ÚoverflowProtocolrv  r{   r|   r'   )r   r5   rw  Úoprl   s       @r   ÚtestConnectionLimitingz8LimitTotalConnectionsFactoryTests.testConnectionLimitingU  s¥  ø€ åÔ7Ñ9Ô9ˆÝ#Ô,ˆÔØ"#ˆÔð ×!Ò! $Ñ'Ô'ˆØ×Ò˜QÑÔÐØ×Ò˜˜GÔ3Ñ4Ô4Ð4ð 	×Ò˜'×/Ò/°Ñ5Ô5Ñ6Ô6Ð6Ø×Ò˜˜GÔ3Ñ4Ô4Ð4ð	*ð 	*ð 	*ð 	*ð 	*ð 	*ð 	*�xÔ0ñ 	*ô 	*ð 	*ð $4ˆÔ Ø"ˆÔð
 ×"Ò" 4Ñ(Ô(ˆØ
×Ò˜$ÑÔÐØ�Š˜Ô*Ñ+Ô+Ð+Ø×Ò˜˜GÔ3Ñ4Ô4Ð4ð 	
×Ò˜ÑÔÐØ×Ò˜˜GÔ3Ñ4Ô4Ð4Ø
×Ò˜$ÑÔÐØ×Ò˜˜GÔ3Ñ4Ô4Ð4Ð4Ð4r   N)r-   r.   r/   rI   rq  r{  r0   r   r   rk  rk  >  s8   € € € € € Ø9Ð9ð5ð 5ð 5ð($5ð $5ð $5ð $5ð $5r   rk  c                   ó   — e Zd Zd„ ZdS )ÚWriteSequenceEchoProtocolc                 ó¨   — |                      d¦  «        dk    r| j                             |g¦  «         d S t                               | |¦  «         d S )Ns   vector!éÿÿÿÿ)ÚfindrE   r  r:   r,   )r   Úbytess     r   r,   z&WriteSequenceEchoProtocol.dataReceived}  sS   € Ø�:Š:�jÑ!Ô! RÒ'Ð'ØŒN×(Ò(¨%¨Ñ1Ô1Ð1Ð1Ð1å×%Ò% d¨EÑ2Ô2Ð2Ð2Ð2r   N)r-   r.   r/   r,   r0   r   r   r}  r}  |  s#   € € € € € ð3ð 3ð 3ð 3ð 3r   r}  c                   ó   — e Zd ZdZd„ ZdS )ÚTestLoggingFactoryNc                 óX   — | j         �
J d¦   «         ‚t          ¦   «         | _         | j         S )Nzopen() called too many times)ÚopenFiler   )r   Únames     r   ÚopenzTestLoggingFactory.open‡  s,   € ØŒ}Ð$Ð$Ð&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dS )ÚLoggingFactoryTestsz6
    Tests for L{policies.TrafficLoggingFactory}.
    c                 ó‚  — t          ¦   «         }t          |_        t          ¦   «         }t	          |d¦  «        }|                     d¦  «        }||_        |                     |¦  «         |j                             ¦   «         }|  	                    d|¦  «         |  
                    |                     ¦   «         ¦  «         |                     d¦  «         |j                             ¦   «         }|  	                    d                     d¦  «        |¦  «         |  	                    d                     d¦  «        |¦  «         |                      |                     ¦   «         d¦  «         |                     ¦   «          |                     d¦  «         |j                             ¦   «         }|  	                    d                     dg¦  «        |¦  «         |                      |                     ¦   «         d¦  «         |                     ¦   «          |j                             ¦   «         }|  	                    d	|¦  «         d
S )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   r}  r	   r   rƒ  r8   r{   r…  ÚgetvalueÚassertInr  r  r,   Úformatr‚   r   rË   )r   r'  Útrm   r5   Úvs         r   Útest_thingsGetLoggedz(LoggingFactoryTests.test_thingsGetLogged’  sã  € õ  ™œˆÝ";ˆÔÝ,Ñ.Ô.ˆÝ˜~¨vÑ6Ô6ˆØ�OŠOÐ-Ñ.Ô.ˆØˆŒ
Ø	×Ò˜ÑÔÐàŒJ×ÒÑ!Ô!ˆØ�Š�c˜1ÑÔÐØ×Ò˜Ÿš™œÑ#Ô#Ð#à	�ŠÐ-Ñ.Ô.Ð.àŒJ×ÒÑ!Ô!ˆØ�Š�k×(Ò(Ð)?Ñ@Ô@À!ÑDÔDÐDØ�Š�k×(Ò(Ð)?Ñ@Ô@À!ÑDÔDÐDØ×Ò˜Ÿš™œÐ$:Ñ;Ô;Ð;à	�Š‰	Œ	ˆ	Ø	�ŠÐ<Ñ=Ô=Ð=ØŒJ×ÒÑ!Ô!ˆØ�Š�l×)Ò)Ð+PÐ*QÑRÔRÐTUÑVÔVÐVØ×Ò˜Ÿš™œÐ$IÑJÔJÐJà	×ÒÑÔÐàŒJ×ÒÑ!Ô!ˆØ�ŠÐ&¨Ñ*Ô*Ð*Ð*Ð*r   c                 ó¤  — t          ¦   «         }t          |d¦  «        }|                      |j        d¦  «         |                     d¦  «         |                      |j        d¦  «         d|_        |                     d¦  «         |                      |j        d¦  «         |                     ¦   «          |                      |j        d¦  «         dS )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Ô6ˆØ×Ò˜œ QÑ'Ô'Ð'Ø	�ŠÐ)Ñ*Ô*Ð*Ø×Ò˜œ QÑ'Ô'Ð'àˆŒ
Ø	�ŠÐ)Ñ*Ô*Ð*Ø×Ò˜œ QÑ'Ô'Ð'à	�ŠÑÔÐØ×Ò˜œ QÑ'Ô'Ð'Ð'Ð'r   c                 óæ  ‡‡	— g Šg Š	ˆˆ	fd„}|                       t          d|¦  «         t          j        ¦   «         }t          |_        t          j        |d¦  «        }|                     t          j	        ddd¦  «        ¦  «        }|                     t          j	        ddd¦  «        ¦  «        }di f}d	i f}|  
                    ||g‰¦  «         |  
                    |j        |j        g‰	¦  «         d
S )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                  ó–   •— ‰                      | |f¦  «         t          ¦   «         }| d         |_        ‰                      |¦  «         |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Î  sJ   ø€ ð ×Ò˜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Ð1å!Ô/Ñ1Ô1ˆÝ"0ˆÔÝÔ0°ÀÑHÔHˆØ×+Ò+ÝÔ  {°EÑ:Ô:ñ
ô 
ˆð ×,Ò,ÝÔ  {°EÑ:Ô:ñ
ô 
ˆð & rÐ*ˆ
Ø&¨Ð+ˆØ×Ò˜* kÐ2°JÑ?Ô?Ð?Ø×Ò˜+Ô-¨|Ô/CÐDÀlÑSÔSÐSÐSÐSr   N)r-   r.   r/   rI   r•  r™  r©  r0   r   r   r‰  r‰  �  sQ   € € € € € ðð ð +ð  +ð  +ðD(ð (ð (ð"$Tð $Tð $Tð $Tð $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#  r:  ÚTimeoutMixinrK  rX  rk  r}  r£  rƒ  r‰  r0   r   r   ú<module>r²     s  ððð ð
 €€€Ø Ð Ð Ð Ð Ð à @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @à DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DØ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VØ &Ð &Ð &Ð &Ð &Ð &Ø "Ð "Ð "Ð "Ð "Ð "ðð ð ð ð �XÔ&ñ ô ð ð(ð ð ð ð �8Ô)ñ ô ð ð#ð #ð #ð #ð #�8Ô$ñ #ô #ð #ð ð ð ð ð ˆXÔ#ñ ô ð ð2ð 2ð 2ð 2ð 2 Ô :ñ 2ô 2ð 2ð*2ð 2ð 2ð 2ð 2˜XÔ4ñ 2ô 2ð 2ð*[3ð [3ð [3ð [3ð [3�8Ô$ñ [3ô [3ð [3ð|%ð %ð %ð %ð %�hÔ.ñ %ô %ð %ðY8ð Y8ð Y8ð Y8ð Y8�hÔ'ñ Y8ô Y8ð Y8ðxU;ð U;ð U;ð U;ð U;˜8Ô,ñ U;ô U;ð U;ðpR8ð R8ð R8ð R8ð R8˜(Ô+ñ R8ô R8ð R8ðj.Dð .Dð .Dð .Dð .D�HÔ% xÔ'<ñ .Dô .Dð .Dðbh.ð h.ð h.ð h.ð h.˜Ô)ñ h.ô h.ð h.ðV;5ð ;5ð ;5ð ;5ð ;5¨Ô(9ñ ;5ô ;5ð ;5ð|3ð 3ð 3ð 3ð 3 ñ 3ô 3ð 3ðð ð ð ð ˜Ô7ñ ô ð ð\Tð \Tð \Tð \Tð \T˜(Ô+ñ \Tô \Tð \Tð \Tð \Tr   