%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/test/__pycache__/test_policies.cpython-312.pyc

�

Ϫ�f"���@�dZddlZddlmZddlmZmZmZddlm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZddlmZGd	�d
ej*�ZGd�dej.�ZGd
�dej*�ZGd�dej4�ZGd�dej8�ZGd�dej<�ZGd�dej@�Z!Gd�dejD�Z"Gd�dej@�Z#Gd�dej@�Z$Gd�dej@�Z%Gd�d ej*ejL�Z'Gd!�d"ej@�Z(Gd#�d$ej@�Z)Gd%�d&e�Z*Gd'�d(ejV�Z,Gd)�d*ej@�Z-y)+z
Test code for policies.
�N)�StringIO)�	Interface�
implementedBy�implementer)�address�defer�protocol�reactor�task)�StringTransport� StringTransportWithDisconnection)�policies)�unittestc�0�eZdZdxZZdZd�Zd�Zd�Zd�Z	y)�SimpleProtocolr�c�h�tj�|_tj�|_y�N)r�Deferred�
dConnected�
dDisconnected��selfs �</usr/lib/python3/dist-packages/twisted/test/test_policies.py�__init__zSimpleProtocol.__init__s���.�.�*���"�^�^�-��rc�H�d|_|jjd�y�N��)�	connectedr�callbackrs r�connectionMadezSimpleProtocol.connectionMades�������� � ��$rc�H�d|_|jjd�yr)�disconnectedrr!�r�reasons  r�connectionLostzSimpleProtocol.connectionLost s��������#�#�B�'rc�.�|xj|z
c_yr)�buffer�r�datas  r�dataReceivedzSimpleProtocol.dataReceived$s�����t��rN)
�__name__�
__module__�__qualname__r r$r)rr"r'r,�rrrrs%�� � �I��
�F�.�%�(�rrc��eZdZd�Zd�Zy)�SillyFactoryc��||_yr��p)rr5s  rrzSillyFactory.__init__)s	����rc��|jSrr4)r�addrs  r�
buildProtocolzSillyFactory.buildProtocol,s���v�v�
rN)r-r.r/rr8r0rrr2r2(s���rr2c�(�eZdZdZd�Zd�Zd�Zd�Zy)�EchoProtocolFc��d|_y�NT��pausedrs r�pauseProducingzEchoProtocol.pauseProducing3s	����rc��d|_y)NFr=rs r�resumeProducingzEchoProtocol.resumeProducing6s	����rc��yrr0rs r�
stopProducingzEchoProtocol.stopProducing9s��rc�:�|jj|�yr)�	transport�writer*s  rr,zEchoProtocol.dataReceived<s�������T�"rN)r-r.r/r>r?rArCr,r0rrr:r:0s��
�F���
�#rr:c��eZdZdZeZy)�Serverz8
    A simple server factory using L{EchoProtocol}.
    N)r-r.r/�__doc__r:r	r0rrrHrH@s����HrrHc��eZdZdZd�Zd�Zy)�TestableThrottlingFactoryzH
    L{policies.ThrottlingFactory} using a L{task.Clock} for tests.
    c�X�tjj|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�rrO�args�kwargss    rrz"TestableThrottlingFactory.__init__Ms)��	�"�"�+�+�D�B�4�B�6�B���
rc�:�|jj||�S�z0
        Forward to the testable clock.
        �rO�	callLater�r�period�funcs   rrVz#TestableThrottlingFactory.callLaterV����z�z�#�#�F�D�1�1rN�r-r.r/rIrrVr0rrrKrKH�����2rrKc��eZdZdZd�Zd�Zy)�TestableTimeoutFactoryzE
    L{policies.TimeoutFactory} using a L{task.Clock} for tests.
    c�X�tjj|g|��i|��||_yrM)r�TimeoutFactoryrrOrPs    rrzTestableTimeoutFactory.__init__bs)��	���(�(��?��?��?���
rc�:�|jj||�SrTrUrWs   rrVz TestableTimeoutFactory.callLaterkrZrNr[r0rrr^r^]r\rr^c�p�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zy)�WrapperTestsz>
    Tests for L{WrappingFactory} and L{ProtocolWrapper}.
    c���t�}tj|�}|jt	j
ddd��}|j
|jj|�y)zf
        Make sure protocol.factory is the wrapped factory, not the wrapping
        factory.
        �TCP�	127.0.0.1�#N)	rHr�WrappingFactoryr8r�IPv4Address�assertIs�wrappedProtocol�factory)r�f�wfr5s    r�test_protocolFactoryAttributez*WrapperTests.test_protocolFactoryAttributewsT��

�H��
�
%�
%�a�
(�����W�0�0���R�H�I���
�
�a�'�'�/�/��3rc�~�Gd�dt�}t|�Gd�d��}ttj�tj�}tjtjd�|�}|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��eZdZy)�=WrapperTests.test_transportInterfaces.<locals>.IStubTransportN�r-r.r/r0rr�IStubTransportrr����rrtc��eZdZy)�<WrapperTests.test_transportInterfaces.<locals>.StubTransportNrsr0rr�
StubTransportrw�s��rrxN)rrrr�ProtocolWrapperr	�Protocolrh�makeConnection�
assertTrue�
providedByrE)rrtrx�proto�wrappers     r�test_transportInterfacesz%WrapperTests.test_transportInterfaces�s���	�Y�	�
�^�	$�	�	�
%�	�	�h�.�.�/��!�!�#���*�*�8�+C�+C�D�+I�5�Q�����}��/�����1�1�%�/�/�B�Crc��t�}tj|�}|jd|j	��y)z�
        L{WrappingFactory.logPrefix} is customized to mention both the original
        factory and the wrapping factory.
        zServer (WrappingFactory)N)rHrrh�assertEqual�	logPrefix)r�serverrls   r�test_factoryLogPrefixz"WrapperTests.test_factoryLogPrefix�s5��
����*�*�6�2�����3�W�5F�5F�5H�Irc��Gd�d�}|�}tj|�}|jd|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��eZdZy)�=WrapperTests.test_factoryLogPrefixFallback.<locals>.NoFactoryNrsr0rr�	NoFactoryr��rurr�zNoFactory (WrappingFactory)N)rrhr�r�)rr�r�rls    r�test_factoryLogPrefixFallbackz*WrapperTests.test_factoryLogPrefixFallback�s?��	�	�����*�*�6�2�����6��8I�8I�8K�Lrc���t�}tj|�}|jt	j
ddd��}|j
d|j��y)z{
        L{ProtocolWrapper.logPrefix} is customized to mention both the original
        protocol and the wrapper.
        rerfrgzEchoProtocol (ProtocolWrapper)N)rHrrhr8rrir�r�)rr�rlr	s    r�test_protocolLogPrefixz#WrapperTests.test_protocolLogPrefix�sX��
����*�*�6�2���(�(��)<�)<�U�K�QS�)T�U�����9�;M�8�;M�;M�;O�Prc���Gd�d�}t�}||_tj|�}|j	tjddd��}|jd|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��eZdZy)�?WrapperTests.test_protocolLogPrefixFallback.<locals>.NoProtocolNrsr0rr�
NoProtocolr��rurr�rerfrgzNoProtocol (ProtocolWrapper)N)	rHr	rrhr8rrir�r�)rr�r�rlr	s     r�test_protocolLogPrefixFallbackz+WrapperTests.test_protocolLogPrefixFallback�si��	�	����$����*�*�6�2���(�(��)<�)<�U�K�QS�)T�U�����7�9K��9K�9K�9M�Nrc���tjtjt��t	j
��}t
�}|j|�|S)zm
        Return L{policies.ProtocolWrapper} that has been connected to a
        L{StringTransport}.
        )rryrhrHr	rzrr{�rrrEs   r�_getWrapperzWrapperTests._getWrapper�sL��
�*�*��$�$�V�X�.��0A�0A�0C�
��$�%�	����y�)��rc��|j�}|j|j�|jj��y)zk
        L{policies.ProtocolWrapper.getHost} calls C{getHost} on the underlying
        transport.
        N)r�r��getHostrE�rrs  r�test_getHostzWrapperTests.test_getHost��8��
�"�"�$��������*�G�,=�,=�,E�,E�,G�Hrc��|j�}|j|j�|jj��y)zk
        L{policies.ProtocolWrapper.getPeer} calls C{getPeer} on the underlying
        transport.
        N)r�r��getPeerrEr�s  r�test_getPeerzWrapperTests.test_getPeer�r�rc���|j�}t�}|j|d�|j|jj
|�|j
|jj�y)z}
        L{policies.ProtocolWrapper.registerProducer} calls C{registerProducer}
        on the underlying transport.
        TN)r��object�registerProducerrjrE�producerr|�	streaming�rrr�s   r�test_registerProducerz"WrapperTests.test_registerProducer�s[��
�"�"�$���8��� � ��4�0��
�
�g�'�'�0�0�(�;�����)�)�3�3�4rc��|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�assertIsNonerEr�r�r�s   r�test_unregisterProducerz$WrapperTests.test_unregisterProducer�si��
�"�"�$���8��� � ��4�0��"�"�$����'�+�+�4�4�5����'�+�+�5�5�6rc���|j�}g��fd�|j_|j�|j�dg�y)zw
        L{policies.ProtocolWrapper.stopConsuming} calls C{stopConsuming} on
        the underlying transport.
        c�&���jd�Sr<��append��results�r�<lambda>z1WrapperTests.test_stopConsuming.<locals>.<lambda>s���&�-�-��2E�rTN)r�rE�
stopConsumingr�)rrr�s  @r�test_stopConsumingzWrapperTests.test_stopConsumingsD���
�"�"�$����*E����'���������$��(rc���g�G�fd�d�}tj|��}t�}|j|�|j	�|g�y)z}
        L{policies.WrappingFactory.startedConnecting} calls
        C{startedConnecting} on the underlying factory.
        c���eZdZ�fd�Zy)�4WrapperTests.test_startedConnecting.<locals>.Factoryc�(���j|�yrr�)r�	connectorr�s  �r�startedConnectingzFWrapperTests.test_startedConnecting.<locals>.Factory.startedConnectings����
�
�i�(rN)r-r.r/r�r�s�r�Factoryr�s���
)rr�N)rrhr�r�r�)rr�rr�r�s    @r�test_startedConnectingz#WrapperTests.test_startedConnectingsO���
��	)�	)��*�*�7�9�5���H�	��!�!�)�,�����)��-rc����g�G�fd�d�}tj|��}t�}t�}|j||�|j	�||fg�y)z�
        L{policies.WrappingFactory.clientConnectionLost} calls
        C{clientConnectionLost} on the underlying factory.
        c���eZdZ�fd�Zy)�7WrapperTests.test_clientConnectionLost.<locals>.Factoryc�,���j||f�yrr��rr�r&r�s   �r�clientConnectionLostzLWrapperTests.test_clientConnectionLost.<locals>.Factory.clientConnectionLost#�����
�
�y�&�1�2rN)r-r.r/r�r�s�rr�r�"����
3rr�N)rrhr�r�r��rr�rr�r&r�s     @r�test_clientConnectionLostz&WrapperTests.test_clientConnectionLosts^���
��	3�	3��*�*�7�9�5���H�	�����$�$�Y��7�����9�f�"5�!6�7rc����g�G�fd�d�}tj|��}t�}t�}|j||�|j	�||fg�y)z�
        L{policies.WrappingFactory.clientConnectionFailed} calls
        C{clientConnectionFailed} on the underlying factory.
        c���eZdZ�fd�Zy)�9WrapperTests.test_clientConnectionFailed.<locals>.Factoryc�,���j||f�yrr�r�s   �r�clientConnectionFailedzPWrapperTests.test_clientConnectionFailed.<locals>.Factory.clientConnectionFailed4r�rN)r-r.r/r�r�s�rr�r�3r�rr�N)rrhr�r�r�r�s     @r�test_clientConnectionFailedz(WrapperTests.test_clientConnectionFailed,s^���
��	3�	3��*�*�7�9�5���H�	�����&�&�y�&�9�����9�f�"5�!6�7rc�Z�tjtjt��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)rryrhrHr	rzr
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�2rN)r-r.r/rIror�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r0rrrcrcrs^���4�D�:J�M�Q�
O�
�I�I�	5�
7�	)�.� 8�"8�"3rrcc��eZdZd�Zd�Zy)rhc��|Srr0)rrmr5s   rr	zWrappingFactory.protocolQs���rc�x�tjj|�|jj	d�yr)rrh�startFactory�deferredr!rs rr�zWrappingFactory.startFactoryTs(��� � �-�-�d�3��
�
���t�$rN)r-r.r/r	r�r0rrrhrhPs���%rrhc�(�eZdZdZd�Zd�Zd�Zd�Zy)�ThrottlingTestsz2
    Tests for L{policies.ThrottlingFactory}.
    c����	�
���
���t�}d�td�D�\�	�
��tj|d��t	��}tj�|_tjd|d����j�j�
�	�
��
fd�}�	�
���fd�}�	fd	�}��
fd
�}��fd�}�
��fd�}|jj|�|jj|�|jj|�|jj|�|jj|�|jj|�|jS)
z�
        Full test using a custom server limiting number of connections.

        FIXME: https://twistedmatrix.com/trac/ticket/10012
        This is a flaky test.
        c3�0K�|]}t����y�wr)r)�.0�is  r�	<genexpr>z-ThrottlingTests.test_limit.<locals>.<genexpr>fs����=�q�.�*�=�s���rrf)�	interfacec����tjd�t����jj	��fd���jj	��fd���j
S)Nrfc�D��tjd�t���S�Nrf�r
�
connectTCPr2)�r�c2�ns ��rr�zAThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>r����'�,�,�[�!�\�"�=M�N�rc�D��tjd�t���Sr�r�)r��c3r�s ��rr�zAThrottlingTests.test_limit.<locals>._connect123.<locals>.<lambda>ur�r)r
r�r2r�addCallbackr)�results�c1r�r�r�s ����r�_connect123z/ThrottlingTests.test_limit.<locals>._connect123osT������{�A�|�B�/?�@��M�M�%�%�N�
�
�M�M�%�%�N�
��#�#�#rc�>���j���fD�cgc]}|j��c}gd���j���fD�cgc]}|j��c}gd���jt�jj��d�|Scc}wcc}w)N)rrr)rrrr�)r�r r$�len�	protocols�keys)r��cr�r�r�r�tServers  �����r�	_check123z-ThrottlingTests.test_limit.<locals>._check123ys������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�Bc�P���jj��jSr)rEr�r)r�r�s �r�_lose1z*ThrottlingTests.test_limit.<locals>._lose1s����L�L�'�'�)��#�#�#rc�\��tjd�t����jSr�)r
r�r2r)r��c4r�s ��r�	_connect4z-ThrottlingTests.test_limit.<locals>._connect4�s$������{�A�|�B�/?�@��=�=� rc�x���j�jd��j�jd�|S)Nrr)r�r r$)r�r�rs ��r�_check4z+ThrottlingTests.test_limit.<locals>._check4�s0������R�\�\�1�-����R�_�_�a�0��Nrc������fD]}|jj��tjtj�j
��j�jg�Sr)rEr�r�DeferredList�
maybeDeferred�
stopListeningr)r�r�r�r�r5s  ���r�_cleanupz,ThrottlingTests.test_limit.<locals>._cleanup�sb�����V�
-�����*�*�,�
-��%�%��'�'����8��$�$��$�$���
r)
rH�rangerrNrhrrr�r
�	listenTCPr��portr�)rr��wrapTServerr�r�r�r�r�r�r�r�r�r�r�r5r�s`        @@@@@@@r�
test_limitzThrottlingTests.test_limit^s������=�E�!�H�=���B��B��,�,�V�Q�7��%�g�.��$�~�~�/���
���a���D��
�I�I�K����	$�	�	�	$�
	!�	�
		�	���(�(��5����(�(��3����(�(��0����(�(��3����(�(��1����(�(��2��#�#�#rc��t�}ttj�|�}|j	tjddd��}t�}||_|j|�|jdgdz�|j|j�d�|j|jd�y)	zZ
        L{ThrottlingProtocol.writeSequence} is called on the underlying factory.
        rerfr�bytesr�sbytesbytesbytesbytes�N)rHrKr�Clockr8rrir
r	r{�
writeSequencer��value�writtenThisSecond)rr�r�r	rEs     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�7rc��t�}ttj�|d��}|j	tjddd��}t�}||_|j|�|j|_|jd�|jd�|j|j�d�|j|jd	�|j!|jj"�|j$j'd
�|j|jd�|j)|jj"�|j$j'd
�|j|jd�|j!|jj"�y)ze
        Check the writeLimit parameter: write data, and check for the pause
        status.
        �
)�
writeLimitrerfr�
0123456789�
abcdefghij�0123456789abcdefghijr��������?N)rHrKrrr8rrir
r	r{rkr�r,r�rr	�assertFalser>rO�advancer|�rr�r�r�trs     r�test_writeLimitzThrottlingTests.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�5rc��t�}ttj�|d��}|j	tjddd��}t�}||_|j|�|jd�|jd�|j|j�d�|j|jd	�|jjd
�|j|jd�|j|j d�|jjd
�|j|jd�|j|j d�|j#�|jd�|jd�|j|j�d�|j|jd	�|jjd
�|j|jd�|j|j d�|jjd
�|j|jd�|j|j d�y
)zb
        Check the readLimit parameter: read data and check for the pause
        status.
        r)�	readLimitrerfrrrrrrr>�	producingN)rHrKrrr8rrir
r	r{r,r�r�readThisSecondrOr�
producerState�clearrs     r�test_readLimitzThrottlingTests.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�����)�)�;�7rN)r-r.r/rIrr
rrr0rrr�r�Ys���@$�D
8�6�<%8rr�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�TimeoutProtocolTestsz0
    Tests for L{policies.TimeoutProtocol}.
    c��tj�}tj�}t|_t||d�}|j
tjddd��}t�}||_|j|�||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})
        Nrerf�90)rrr	�
ServerFactoryrr^r8rrir
r{)rrO�wrappedFactoryrlr~rEs      r�getProtocolAndClockz(TimeoutProtocolTests.getProtocolAndClock�sz���
�
���!�/�/�1��"0���(����E���%�%�g�&9�&9�%��e�&T�U��4�6�	�"�	��
���Y�'��u�~�rc��|j�\}}|jd�|j|j�|j	|j
j�|jd�|j�|j|j�|jd�|j	|j
j�y)z2
        Will cancel the ongoing timeout.
        �rN)
r$�
setTimeoutr��timeoutCallrrkr$r�
cancelTimeoutr��r�sutrOs   r�test_cancelTimeoutz'TimeoutProtocolTests.test_cancelTimeouts����-�-�/�
��U����q�����S�_�_�-�����,�,�9�9�:�
�
�
�a���������#�/�/�*�	�
�
�a������,�,�9�9�:rc���|j�\}}|j|j�|j�|j	|j
j�y)z<
        Does nothing if no timeout is already set.
        N)r$r�r(r)rrkr$r*s   r�test_cancelTimeoutNoTimeoutz0TimeoutProtocolTests.test_cancelTimeoutNoTimeout#sP���-�-�/�
��U����#�/�/�*�����	
����,�,�9�9�:rc���|j�\}}|j}|jd�|jd�|j	|j
�|j
�y)z@
        Does nothing if no timeout is already reached.
        r&N)r$rkr'rr|r$r))rr+rO�wrappedProtos    r�test_cancelTimeoutAlreadyCalledz4TimeoutProtocolTests.test_cancelTimeoutAlreadyCalled/sY���-�-�/�
��U��*�*�����q��
�
�
�a������1�1�2�	���rc���|j�\}}|jd�|jj�|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)rrkr$r*s   r�"test_cancelTimeoutAlreadyCancelledz7TimeoutProtocolTests.test_cancelTimeoutAlreadyCancelled=sZ��
�-�-�/�
��U����q������� �	��������,�,�9�9�:rN)	r-r.r/rIr$r,r.r1r4r0rrrr�s ����,;�&
;��
;rrc�(�eZdZdZd�Zd�Zd�Zd�Zy)�TimeoutFactoryTestsz/
    Tests for L{policies.TimeoutFactory}.
    c���tj�|_tj�}t
|_t
|j|d�|_|jjtjddd��|_t�|_
|j|j_|jj|j�|jj|_y)zq
        Create a testable, deterministic clock, and a set of
        server factory/protocol/transport.
        r&rerfr!N)rrrOr	r"rr^rlr8rrir~r
rEr{rkr0)rr#s  r�setUpzTimeoutFactoryTests.setUpRs���
�Z�Z�\��
�!�/�/�1��"0���-�d�j�j�.�!�L����\�\�/�/�����{�E�:�
��
�:�;���"&�*�*������
�
�!�!�$�.�.�1� �J�J�6�6��rc��|jjgd��|j|jj�|jjddg�|j|jj�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�pumprr0r$r|rs r�test_timeoutz TimeoutFactoryTests.test_timeoutcs]��	
�
�
���1�2�����*�*�7�7�8�	
�
�
����c�
�#�����)�)�6�6�7rc��|jjgd��|j|jj�|j
j
d�|jjgd��|j|jj�|j
jdgdz�|jjgd��|j|jj�|jjddg�|j|jj�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<rr&r:g@N)	rOr>rr0r$r~rFrr|rs r�test_sendAvoidsTimeoutz*TimeoutFactoryTests.test_sendAvoidsTimeoutqs���	
�
�
����(�����*�*�7�7�8�	
�
�
���-�.�	
�
�
����(�����*�*�7�7�8�	
�
�
� � �(��a��0�	
�
�
����(�����*�*�7�7�8�	
�
�
����c�
�#�����)�)�6�6�7rc���|jjgd��|j|jj�|j
j
d�|jjgd��|j|jj�|jjgd��|j|jj�y)zR
        Make sure that receiving data also resets the timeout countdown.
        )r:r<r;rArBN)rOr>rr0r$r~r,r|rs r�test_receiveAvoidsTimeoutz-TimeoutFactoryTests.test_receiveAvoidsTimeout�s���
	
�
�
����(�����*�*�7�7�8�	
�
�
��� 4�5�	
�
�
����(�����*�*�7�7�8�	
�
�
����(�����)�)�6�6�7rN)r-r.r/rIr8r?rCrEr0rrr6r6Ms���7�"8�8�88rr6c�>�eZdZdZdZdZd�Zd�Zd�Zdd�Z	d	�Z
d
�Zy)�
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)rrOs  rrzTimeoutTester.__init__�s����
rc�:�|j|j�y)z3
        Upon connection, set the timeout.
        N)r'�timeOutrs rr"zTimeoutTester.connectionMade�s��	
������%rc�d�|j�tjj||�y)z,
        Reset the timeout on data.
        N)�resetTimeoutr	rzr,r*s  rr,zTimeoutTester.dataReceived�s&��	
�������&�&�t�T�2rNc�&�|jd�y)zD
        On connection lost, cancel all timeout operations.
        N)r'r%s  rr'zTimeoutTester.connectionLost�s��	
����rc��d|_y)zX
        Flags the timedOut variable to indicate the timeout of the connection.
        TN)�timedOutrs r�timeoutConnectionzTimeoutTester.timeoutConnection�s����
rc�D�|jj||g|��i|��S)zD
        Override callLater to use the deterministic clock.
        rU)r�timeoutrYrQrRs     rrVzTimeoutTester.callLater�s'��$�t�z�z�#�#�G�T�C�D�C�F�C�Crr)r-r.r/rIrJrOrr"r,r'rPrVr0rrrGrG�s2����G��H��&�3���DrrGc�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�TimeoutMixinTestsz-
    Tests for L{policies.TimeoutMixin}.
    c�j�tj�|_t|j�|_y)zY
        Create a testable, deterministic clock and a C{TimeoutTester} instance.
        N)rrrOrGr~rs rr8zTimeoutMixinTests.setUp�s!���Z�Z�\��
�"�4�:�:�.��
rc��|jjd�|jt|jj
�d�y)z�
        Test that the callLater of the clock is used instead of
        L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
        rrN)r~r'r�r�rO�callsrs r�test_overriddenCallLaterz*TimeoutMixinTests.test_overriddenCallLater�s5��
	
�
�
���b�!�����T�Z�Z�-�-�.��2rc�R�|jjt��|jj	gd��|j|jj�|jj	ddg�|j|jj�y)zq
        Check that the protocol does timeout at the time specified by its
        C{timeOut} attribute.
        �rr;r<r<rr<N)r~r{rrOr>rrOr|rs rr?zTimeoutMixinTests.test_timeout�sn��
	
�
�
�!�!�/�"3�4�	
�
�
���*�+�������,�,�-��
�
����C��!�����
�
�+�+�,rc��|jjt��|jj	gd��|j|jj�|jjd�|jj	gd��|j|jj�|jj	ddg�|j|jj�y)zV
        Check that receiving data is delaying the timeout of the connection.
        rZshello there)rr<r<r;rr<N)	r~r{rrOr>rrOr,r|rs r�test_noTimeoutz TimeoutMixinTests.test_noTimeout�s���	
�
�
�!�!�/�"3�4��
�
���*�+�������,�,�-��
�
����/��
�
���*�+�������,�,�-��
�
����C��!�����
�
�+�+�,rc��d|j_|jjt��|jj	d�|j|jjd�|jjddg�|j|jj�|jjddg�|j|jj�y)zy
        Check that setting a new value for timeout cancel the previous value
        and install a new timeout.
        Nrrg�������?r=)r~rJr{rr'r�rOr>rrOr|rs r�test_resetTimeoutz#TimeoutMixinTests.test_resetTimeouts���
"��
�
���
�
�!�!�/�"3�4��
�
���a� �������+�+�Q�/��
�
����C��!�������,�,�-��
�
����C��!�����
�
�+�+�,rc�p�d|j_|jjt��|jj	d�|j|jj�|jjgd��|j|jj�y)zO
        Setting the timeout to L{None} cancel any timeout operations.
        �N)rr`r`r`)
r~rJr{rr'r�rOr>rrOrs rr,z$TimeoutMixinTests.test_cancelTimeoutsw����
�
���
�
�!�!�/�"3�4��
�
���d�#����$�*�*�,�,�-��
�
����%�������,�,�-rc��d|j_|j|jjd�d�|j|jjd�d�|j	|jjd��|j|jjd�|jjd�y)zM
        setTimeout should return the value of the previous timeout.
        r`rNr)r~rJr�r'r�rs r�test_setTimeoutReturnz'TimeoutMixinTests.test_setTimeoutReturns�����
�
��������.�.�r�2�A�6�������.�.�t�4�b�9����$�*�*�/�/��2�3�������+�+�Q�/�	
�
�
���d�#rc�Z�|jjd�|jj�dj	�|j|jj�|jjd�|j|jj�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&rN)r~r'rO�getDelayedCallsr3r�rJr�rs r�%test_setTimeoutCancleAlreadyCancelledz7TimeoutMixinTests.test_setTimeoutCancleAlreadyCancelled-sx��	
�
�
���a� �	
�
�
�"�"�$�Q�'�.�.�0����T�Z�Z�/�/�0��
�
���d�#����$�*�*�,�,�-rN)r-r.r/rIr8rXr?r\r^r,rbrer0rrrTrT�s/���/�3�-�-�-� .�$�.rrTc��eZdZdZd�Zd�Zy)�!LimitTotalConnectionsFactoryTestsz/Tests for policies.LimitTotalConnectionsFactoryc��tj�}tj|_|j	d|j
�|j
d�}|j	d|j
�|j
d�}|j	d|j
�|jd�|j	d|j
�|jd�|j	d|j
�y)Nrrr�)r�LimitTotalConnectionsFactoryr	rzr��connectionCountr8r')rrl�p1�p2s    r�testConnectionCountingz8LimitTotalConnectionsFactoryTests.testConnectionCountingAs����7�7�9��#�,�,���	
����G�3�3�4��
"�
"�4�
(������G�3�3�4�
�
"�
"�4�
(������G�3�3�4�	���$������G�3�3�4�
���$������G�3�3�4rc���tj��tj�_d�_�jd�}|j
|�|jd�j�|j�jd��|jd�j�G�fd�dtj�}|�_
d�_�jd�}|jd�|j�j�|jd�j�|jd�|jd�j�|jd�|jd�j�y)Nrc���eZdZ�fd�Zy)�RLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocolc���d�_yr<)�
overflowed)rrls �rr"zaLimitTotalConnectionsFactoryTests.testConnectionLimiting.<locals>.OverflowProtocol.connectionMadegs���%)��"rN)r-r.r/r")rls�r�OverflowProtocolrpfs���
*rrsFr�r)rrir	rz�connectionLimitr8r�r�rjr��overflowProtocolrrr{r|r')rr5rs�oprls    @r�testConnectionLimitingz8LimitTotalConnectionsFactoryTests.testConnectionLimitingUsD����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�4rN)r-r.r/rIrmrwr0rrrgrg>s��9�5�($5rrgc��eZdZd�Zy)�WriteSequenceEchoProtocolc��|jd�dk7r|jj|g�ytj	||�y)Nsvector!���)�findrErr:r,)r�bytess  rr,z&WriteSequenceEchoProtocol.dataReceived}s7���:�:�j�!�R�'��N�N�(�(�%��1��%�%�d�E�2rN)r-r.r/r,r0rrryry|s��3rryc��eZdZdZd�Zy)�TestLoggingFactoryNc�^�|j�Jd��t�|_|jS)Nzopen() called too many times)�openFiler)r�names  r�openzTestLoggingFactory.open�s+���}�}�$�D�&D�D�$� �
��
��}�}�r)r-r.r/r�r�r0rrrr�s���H�rrc�"�eZdZdZd�Zd�Zd�Zy)�LoggingFactoryTestsz6
    Tests for L{policies.TrafficLoggingFactory}.
    c���t�}t|_t�}t	|d�}|jd�}||_|j
|�|jj�}|jd|�|j|j��|jd�|jj�}|jdjd�|�|jdjd�|�|j|j�d�|j�|jd�|jj�}|jdjdg�|�|j|j�d�|j!�|jj�}|jd	|�y
)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)rHryr	r
rr8r{r��getvalue�assertInrrr,�formatr�rr�)rr#�trmr5�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���!���
�
�&��*rc��t�}t|d�}|j|jd�|j	d�|j|jd�d|_|j	d�|j|jd�|j
�|j|jd�y)zG
        Test counter management with the resetCounter method.
        r�rr�rN)r�i/r�)rHrr��_counterr8r��resetCounter)rr#rms   r�test_counterz LoggingFactoryTests.test_counter�s��� ����~�v�6��������Q�'�	���)�*�������Q�'���
�	���)�*�������Q�'�	����������Q�'rc����	�g�g�	��	fd�}|jtd|�tj�}t|_tj|d�}|jtjddd��}|jtjddd��}dif}d	if}|j||g��|j|j|jg�	�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�rr�)rQrR�io�
open_calls�open_rvaluess   ��r�mocked_openzULoggingFactoryTests.test_loggingFactoryOpensLogfileAutomatically.<locals>.mocked_open�s<���
���t�V�n�-���B��1�g�B�G�����#��Irr�r�rerfr!i:0)ztest-1�w)ztest-2r�N)�patch�builtinsr	r"rr�TrafficLoggingFactoryr8rrir��logfile)
rr�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�SrN)r-r.r/rIr�r�r�r0rrr�r��s��� +�D(�"$Trr�).rIr�r�r�zope.interfacerrr�twisted.internetrrr	r
r�twisted.internet.testingrr
�twisted.protocolsr�
twisted.trialrrzr�
ClientFactoryr2r:r"rHrNrKr`r^�TestCasercrhr�rr6�TimeoutMixinrGrTrgryr�rr�r0rr�<module>r�sr���
��@�@�D�D�V�&�"��X�&�&��(�8�)�)��
#�8�$�$�
#� �X�
#�
#��2�� :� :�2�*2�X�4�4�2�*[3�8�$�$�[3�|%�h�.�.�%�Y8�h�'�'�Y8�xU;�8�,�,�U;�pR8�(�+�+�R8�j.D�H�%�%�x�'<�'<�.D�bh.��)�)�h.�V;5��(9�(9�;5�|3��3���7�7��\T�(�+�+�\Tr

Zerion Mini Shell 1.0