%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�fM����dZddlZddlmZddlmZddlmZddlm	Z	m
Z
mZddlm
Z
ddlmZmZdd	lmZmZmZmZmZdd
lmZmZddlmZddlmZdd
lmZm Z ddl!m"Z"ddl#m$Z$m%Z%d�Z&ee�Gd�d��Z'eee'�ee�Gd�d��Z(eee'�Gd�de%�Z)Gd�de%�Z*Gd�d�Z+d d�Z,e fd�Z-dZ.Gd�de$�Z/y)!z�
Tests for (new code in) L{twisted.application.internet}.

@var AT_LEAST_ONE_ATTEMPT: At least enough seconds for L{ClientService} to make
    one attempt.
�N)�implementer)�verifyClass)�internet)�
ClientService�StreamServerEndpointService�TimerService)�task)�CancelledError�Deferred)�IFileDescriptorReceiver�IHalfCloseableProtocol�IListeningPort�IStreamClientEndpoint�IStreamServerEndpoint)�Factory�Protocol)�Clock)�StringTransport)�formatEvent�globalLogPublisher)�Failure)�SynchronousTestCase�TestCasec��y)zM
    A fake target function for testing TimerService which does nothing.
    N�r��H/usr/lib/python3/dist-packages/twisted/application/test/test_internet.py�fakeTargetFunctionr)s��	rc�F�eZdZdZdZdZdZe�ZdZ	d�Z
d�Zd�Zd�Z
y)�
FakeServeraq
    In-memory implementation of L{IStreamServerEndpoint}.

    @ivar result: The L{Deferred} resulting from the call to C{listen}, after
        C{listen} has been called.

    @ivar factory: The factory passed to C{listen}.

    @ivar cancelException: The exception to errback C{self.result} when it is
        cancelled.

    @ivar port: The L{IListeningPort} which C{listen}'s L{Deferred} will fire
        with.

    @ivar listenAttempts: The number of times C{listen} has been invoked.

    @ivar failImmediately: If set, the exception to fail the L{Deferred}
        returned from C{listen} before it is returned.
    Nrc�"�t�|_y�N)�FakePort�port��selfs r�__init__zFakeServer.__init__Ls���J��	rc�����xjdz
c_|�_t�fd����_�j�%�jj�j��jS)z�
        Return a Deferred and store it for future use.  (Implementation of
        L{IStreamServerEndpoint}).

        @param factory: the factory to listen with

        @return: a L{Deferred} stored in L{FakeServer.result}
        �c�:��|j�j�Sr")�errback�cancelException)�dr&s �r�<lambda>z#FakeServer.listen.<locals>.<lambda>Zs���1�9�9�T�=Q�=Q�3R�r)�	canceller)�listenAttempts�factoryr�result�failImmediatelyr+)r&r1s` r�listenzFakeServer.listenOsX���	
���q� ������)R�S������+��K�K���� 4� 4�5��{�{�rc�N�|jj|j�y)z�
        Test code should invoke this method after causing C{listen} to be
        invoked in order to fire the L{Deferred} previously returned from
        C{listen}.
        N)r2�callbackr$r%s r�startedListeningzFakeServer.startedListening_s��	
�����T�Y�Y�'rc�N�|jjjd�y)a
        Test code should invoke this method after causing C{stopListening} to
        be invoked on the port fired from the L{Deferred} returned from
        C{listen} in order to cause the L{Deferred} returned from
        C{stopListening} to fire.
        N)r$�deferredr6r%s r�stoppedListeningzFakeServer.stoppedListeninggs��	
�	�	���#�#�D�)r)�__name__�
__module__�__qualname__�__doc__r2r1r3r
r,r0r'r4r7r:rrrr r 0s9���(�F��G��O�$�&�O��N��� (�*rr c�&�eZdZdZdZd�Zd�Zd�Zy)r#zs
    Fake L{IListeningPort} implementation.

    @ivar deferred: The L{Deferred} returned by C{stopListening}.
    Nc�8�t�|_|jS)z`
        Stop listening.

        @return: a L{Deferred} stored in L{FakePort.deferred}
        )rr9r%s r�
stopListeningzFakePort.stopListening~s��!�
��
��}�}�rc��yr"rr%s r�getHostzFakePort.getHost����rc��yr"rr%s r�startListeningzFakePort.startListening�rDr)r;r<r=r>r9rArCrFrrrr#r#ts����H��
�
rr#c�Z�eZdZdZd�Zd�Zdd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zy)�EndpointServiceTestsz4
    Tests for L{twisted.application.internet}.
    c��t�|_t�|_t	|j|j�|_y)zp
        Construct a stub server, a stub factory, and a
        L{StreamServerEndpointService} to test.
        N)r �
fakeServerrr1r�svcr%s r�setUpzEndpointServiceTests.setUp�s,��
%�,����y���.�t������M��rc��|jj�|j|j|jj�y)z�
        L{StreamServerEndpointService.privilegedStartService} calls its
        endpoint's C{listen} method with its factory.
        N)rK�privilegedStartService�assertIdenticalr1rJr%s r�test_privilegedStartServicez0EndpointServiceTests.test_privilegedStartService�s2��
	
���'�'�)����T�\�\�4�?�?�+B�+B�CrNc��t�|j_d|j_|jt|xs|jj�y)a@
        L{StreamServerEndpointService.startService} should raise synchronously
        if the L{Deferred} returned by its wrapped
        L{IStreamServerEndpoint.listen} has already fired with an errback and
        the L{StreamServerEndpointService}'s C{_raiseSynchronously} flag has
        been set.  This feature is necessary to preserve compatibility with old
        behavior of L{twisted.internet.strports.service}, which is to return a
        service which synchronously raises an exception from C{startService}
        (so that, among other things, twistd will not start running).  However,
        since L{IStreamServerEndpoint.listen} may fail asynchronously, it is a
        bad idea to rely on this behavior.

        @param thunk: If specified, a callable to execute in place of
            C{startService}.
        TN)�ZeroDivisionErrorrJr3rK�_raiseSynchronously�assertRaises�startService)r&�thunks  r�(test_synchronousRaiseRaisesSynchronouslyz=EndpointServiceTests.test_synchronousRaiseRaisesSynchronously�s?�� +<�*=����'�'+����$����+�U�-K�d�h�h�6K�6K�Lrc�N�|j|jj�y)z�
        L{StreamServerEndpointService.privilegedStartService} should behave the
        same as C{startService} with respect to
        L{EndpointServiceTests.test_synchronousRaiseRaisesSynchronously}.
        N)rWrKrNr%s r�test_synchronousRaisePrivilegedz4EndpointServiceTests.test_synchronousRaisePrivileged�s��	
�5�5�d�h�h�6U�6U�Vrc���|jj�|jjj	t��|j
t
�}|jt|�d�y)a
        L{StreamServerEndpointService.startService} and
        L{StreamServerEndpointService.privilegedStartService} should both log
        an exception when the L{Deferred} returned from their wrapped
        L{IStreamServerEndpoint.listen} fails.
        r)N)	rKrUrJr2r+rR�flushLoggedErrors�assertEqual�len�r&�loggeds  r�test_failReportsErrorz*EndpointServiceTests.test_failReportsError�sU��	
�����������&�&�'8�':�;��'�'�(9�:������V��a�(rc��d|j_|jj�|jjjt
��|jt�}|jt|�d�y)aB
        L{StreamServerEndpointService.startService} and
        L{StreamServerEndpointService.privilegedStartService} should both log
        an exception when the L{Deferred} returned from their wrapped
        L{IStreamServerEndpoint.listen} fails asynchronously, even if
        C{_raiseSynchronously} is set.
        Tr)N)
rKrSrUrJr2r+rRr[r\r]r^s  r�!test_asynchronousFailReportsErrorz6EndpointServiceTests.test_asynchronousFailReportsError�sa��(,����$������������&�&�'8�':�;��'�'�(9�:������V��a�(rc���t�|j_|jj	�|jt�}|j
t|�d�y)z�
        Without the C{_raiseSynchronously} compatibility flag, failing
        immediately has the same behavior as failing later; it logs the error.
        r)N)rRrJr3rKrUr[r\r]r^s  r� test_synchronousFailReportsErrorz5EndpointServiceTests.test_synchronousFailReportsError�sH��
+<�*=����'��������'�'�(9�:������V��a�(rc���|jj�|j|j|jj�|j|jjd�y)z�
        L{StreamServerEndpointService.startService} sets the C{running} flag,
        and calls its endpoint's C{listen} method with its factory, if it
        has not yet been started.
        TN)rKrUrOr1rJr\�runningr%s r�test_startServiceUnstartedz/EndpointServiceTests.test_startServiceUnstarted�sL��	
���������T�\�\�4�?�?�+B�+B�C�������)�)�4�0rc���|j�|jj�|j|jj
d�|j|jjd�y)z�
        L{StreamServerEndpointService.startService} sets the C{running} flag,
        but nothing else, if the service has already been started.
        r)TN)rPrKrUr\rJr0rfr%s r�test_startServiceStartedz-EndpointServiceTests.test_startServiceStarted�sT��
	
�(�(�*�������������7�7��;�������)�)�4�0rc��|jj�|jj�|jj	�|jj�}g}|j
|j�|jt|�d�|jj�|jt|�d�|j|jj�y)z�
        L{StreamServerEndpointService.stopService} calls C{stopListening} on
        the L{IListeningPort} returned from its endpoint, returns the
        C{Deferred} from stopService, and sets C{running} to C{False}.
        rr)N)
rKrNrJr7rU�stopService�addCallback�appendr\r]r:�assertFalserf�r&r2�ls   r�test_stopServicez%EndpointServiceTests.test_stopService�s���	
���'�'�)����(�(�*����������%�%�'�������1�8�8�$�����Q���#����(�(�*�����Q���#�������)�)�*rc��|jj�|jj�}g}|j|j�|j|dg�|j|j
t�g�y)z�
        L{StreamServerEndpointService.stopService} cancels the L{Deferred}
        returned by C{listen} if it has not yet fired.  No error will be logged
        about the cancellation of the listen attempt.
        N)rKrNrk�addBothrmr\r[r
ros   r�#test_stopServiceBeforeStartFinishedz8EndpointServiceTests.test_stopServiceBeforeStartFinishedsh��	
���'�'�)����%�%�'�������q�x�x� �����T�F�#�����/�/��?��Drc�^�t�|j_|jj	�|jj�}g}|j
|j�|j|dg�|jt�}|jt|�d�y)z�
        L{StreamServerEndpointService.stopService} cancels the L{Deferred}
        returned by C{listen} if it has not fired yet.  An error will be logged
        if the resulting exception is not L{CancelledError}.
        Nr))rRrJr,rKrNrkrlrmr\r[r])r&r2rp�stoppingErrorss    r� test_stopServiceCancelStartErrorz5EndpointServiceTests.test_stopServiceCancelStartErrors���+<�*=����'����'�'�)����%�%�'�������1�8�8�$�����T�F�#��/�/�0A�B������^�,�a�0rr")r;r<r=r>rLrPrWrYr`rbrdrgrirqrtrwrrrrHrH�sH���N�D�M�(W�
)�)�)�1�1�+�$E�
1rrHc�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�TimerServiceTestsa)
    Tests for L{twisted.application.internet.TimerService}.

    @type timer: L{TimerService}
    @ivar timer: service to test

    @type clock: L{task.Clock}
    @ivar clock: source of time

    @type deferred: L{Deferred}
    @ivar deferred: deferred returned by L{TimerServiceTests.call}.
    c��td|j�|_tj�x|_|j_t
�|_y)z1
        Set up a timer service to test.
        �N)r�call�timerr	r�clockrr9r%s rrLzTimerServiceTests.setUp:s8��"�!�T�Y�Y�/��
�(,�
�
��4��
�T�Z�Z�%� �
��
rc��|jS)z�
        Function called by L{TimerService} being tested.

        @returns: C{self.deferred}
        @rtype: L{Deferred}
        )r9r%s rr|zTimerServiceTests.callBs���}�}�rc��|jj�|j|jjd�|j	|jj
tj�|j|j|jj
j�|j|jj
jd�y)z�
        When L{TimerService.startService} is called, it marks itself
        as running, creates a L{task.LoopingCall} and starts it.
        zService is startedzLoopingCall is startedN)
r}rU�
assertTruerf�assertIsInstance�_loopr	�LoopingCallrOr~r%s r�test_startServicez#TimerServiceTests.test_startServiceKs���
	
�
�
���!�����
�
�*�*�,@�A����d�j�j�.�.��0@�0@�A����T�Z�Z����)9�)9�)?�)?�@�����
�
�(�(�0�0�2J�Krc��g}|jdif|j_|jj�|j	dg|�y)zi
        When L{TimerService.startService} is called, it calls the function
        immediately.
        r"N)rmr}r|rUr\)r&r2s  r�$test_startServiceRunsCallImmediatelyz6TimerServiceTests.test_startServiceRunsCallImmediatelyVsA��
��!�=�=�'�2�6��
�
���
�
���!����$���(rc���tj���fd�}|jtd|�|jj�|j
�|jjj�y)z�
        L{TimerService.startService} uses L{internet._maybeGlobalReactor} to
        choose the reactor to pass to L{task.LoopingCall}
        uses the global reactor.
        c����Sr"r)�maybeReactor�
otherClocks �r�
getOtherClockzKTimerServiceTests.test_startServiceUsesGlobalReactor.<locals>.getOtherClockhs	����r�_maybeGlobalReactorN)	r	r�patchrr}rUrOr�r~)r&r�r�s  @r�"test_startServiceUsesGlobalReactorz4TimerServiceTests.test_startServiceUsesGlobalReactor`sX����Z�Z�\�
�	�	
�
�
�8�2�M�B��
�
���!����Z����)9�)9�)?�)?�@rc�b�|jj�|jj�}|j|�|j	d|jj
�|jjt��|j|j|�d�y)z�
        When L{TimerService.stopService} is called while a call is in progress.
        the L{Deferred} returned doesn't fire until after the call finishes.
        TN)r}rUrk�assertNoResultr\rfr9r6�objectrO�successResultOf�r&r-s  r�test_stopServiceWaitsz'TimerServiceTests.test_stopServiceWaitsos}��
	
�
�
���!��J�J�"�"�$�����A������t�z�z�1�1�2��
�
���v�x�(����T�1�1�!�4�d�;rc���|jj�|jjt	��|jj�}|j
|j|�d�y)z�
        When L{TimerService.stopService} is called while a call isn't in progress.
        the L{Deferred} returned has already been fired.
        N)r}rUr9r6r�rkrOr�r�s  r�test_stopServiceImmediatelyz-TimerServiceTests.test_stopServiceImmediately{sU��
	
�
�
���!��
�
���v�x�(��J�J�"�"�$�����T�1�1�!�4�d�;rc�f�|jj�|jjt	t���|j
t
�}|jdt|��|jj�}|j|j|�d�y)z�
        When function passed to L{TimerService} returns a deferred that errbacks,
        the exception is logged, and L{TimerService.stopService} doesn't raise an error.
        r)N)r}rUr9r+rrRr[r\r]rkrOr�)r&�errorsr-s   r�test_failedCallLogsErrorz*TimerServiceTests.test_failedCallLogsError�s���
	
�
�
���!��
�
���g�&7�&9�:�;��'�'�(9�:������C��K�(��J�J�"�"�$�����T�1�1�!�4�d�;rc�
�tdt�}|j�tj|�}|j�tj|�}t�}t|d|�}|j||�y)zq
        When pickling L{internet.TimerService}, it won't pickle
        L{internet.TimerService._loop}.
        r)r�N�
rrrU�pickle�dumpsrk�loadsr��getattrrO�r&r}�dumpedTimer�loadedTimer�nothing�values      r�$test_pickleTimerServiceNotPickleLoopz6TimerServiceTests.test_pickleTimerServiceNotPickleLoop�sj���Q� 2�3��
�����l�l�5�)��
�����l�l�;�/���(����W�g�6�����W�e�,rc�
�tdt�}|j�tj|�}|j�tj|�}t�}t|d|�}|j||�y)zy
        When pickling L{internet.TimerService}, it won't pickle
        L{internet.TimerService._loopFinished}.
        r)�
_loopFinishedNr�r�s      r�,test_pickleTimerServiceNotPickleLoopFinishedz>TimerServiceTests.test_pickleTimerServiceNotPickleLoopFinished�sj���Q� 2�3��
�����l�l�5�)��
�����l�l�;�/���(����_�g�>�����W�e�,rN)r;r<r=r>rLr|r�r�r�r�r�r�r�r�rrrryry,s;���#��	L�)�
A�
<�<�
<�-� -rryc��eZdZdZd�Zy)�ConnectInformationa�
    Information about C{endpointForTesting}

    @ivar connectQueue: a L{list} of L{Deferred} returned from C{connect}.  If
        these are not already fired, you can fire them with no value and they
        will trigger building a factory.

    @ivar constructedProtocols: a L{list} of protocols constructed.

    @ivar passedFactories: a L{list} of L{IProtocolFactory}; the ones actually
        passed to the underlying endpoint / i.e. the reactor.
    c�.�g|_g|_g|_yr")�connectQueue�constructedProtocols�passedFactoriesr%s rr'zConnectInformation.__init__�s�����$&��!�!��rN)r;r<r=r>r'rrrr�r��s���"rr�c�j���tt�G��fd�d��}t���|�fS)aD
    Make a sample endpoint for testing.

    @param fireImmediately: If true, fire all L{Deferred}s returned from
        C{connect} immedaitely.

    @return: a 2-tuple of C{(information, endpoint)}, where C{information} is a
        L{ConnectInformation} describing the operations in progress on
        C{endpoint}.
    c���eZdZ��fd�Zy)�.endpointForTesting.<locals>.ClientTestEndpointc�����t�}�jj��|j��fd��}�jj|��r|jd�|S)Nc����jd�}�jj|�t�}|j	|�|Sr")�
buildProtocolr�rmr�makeConnection)�ignored�protocol�	transportr1�infos   ��r�createProtocolzNendpointForTesting.<locals>.ClientTestEndpoint.connect.<locals>.createProtocol�sB���"�0�0��6���)�)�0�0��:�+�-�	��'�'�	�2��r)rr�rmrlr�r6)r&r1r2r��fireImmediatelyr�s `  ��r�connectz6endpointForTesting.<locals>.ClientTestEndpoint.connect�s`����Z�F�� � �'�'��0�
�
�
�
 � �
 �
���$�$�V�,������%��MrN)r;r<r=r�)r�r�s��r�ClientTestEndpointr��s���	rr�)rrr�)r�r�r�s` @r�endpointForTestingr��s;����&�'���(��$��D��#�%�%�%rc�t���g��j�j�|j��fd���fd�S)a6
    Catch the global log stream.

    @param testCase: The test case to add a cleanup to.

    @param logPublisher: the log publisher to add and remove observers for.

    @return: a 0-argument callable that returns a list of textual log messages
        for comparison.
    @rtype: L{list} of L{unicode}
    c�:���j�j�Sr")�removeObserverrm)�logPublisher�logss��rr.zcatchLogs.<locals>.<lambda>�s���� ;� ;�D�K�K� H�rc�@���D�cgc]
}t|���c}Scc}wr")r)�eventr�s �rr.zcatchLogs.<locals>.<lambda>�s���D�9�5�K��&�9���9s�)�addObserverrm�
addCleanup)�testCaser�r�s `@r�	catchLogsr��s1����D����T�[�[�)����H�I�9�9rgY@c���eZdZdZddefd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#y")#�ClientServiceTestsz%
    Tests for L{ClientService}.
    Tc�V�����
�i}|jt���|j|�|d�t|��\}}gx�|_G��fd�dt�}|�x|_}	t
||	fi|���
���
fd�}
�j|
�|r�
j�|�
fS)aL
        Create a L{ClientService} along with a L{ConnectInformation} indicating
        the connections in progress on its endpoint.

        @param fireImmediately: Should all of the endpoint connection attempts
            fire synchronously?
        @type fireImmediately: L{bool}

        @param startService: Should the L{ClientService} be started before
            being returned?
        @type startService: L{bool}

        @param protocolType: a 0-argument callable returning a new L{IProtocol}
            provider to be used for application-level protocol connections.

        @param kw: Arbitrary keyword arguments to be passed on to
            L{ClientService}

        @return: a 2-tuple of L{ConnectInformation} (for information about test
            state) and L{ClientService} (the system under test).  The
            L{ConnectInformation} has 2 additional attributes;
            C{applicationFactory} and C{applicationProtocols}, which refer to
            the unwrapped protocol factory and protocol instances passed in to
            L{ClientService} respectively.
        �r~r~�r�c�(���eZdZW�Z��fd�Z�xZS)�>ClientServiceTests.makeReconnector.<locals>.RememberingFactoryc�H��t�|�|�}�j|�|Sr")�superr�rm)r&�addrr2�	__class__�applicationProtocolss   ��rr�zLClientServiceTests.makeReconnector.<locals>.RememberingFactory.buildProtocol0s%�����.�t�4��$�+�+�F�3��
r)r;r<r=r�r��
__classcell__)r�r��protocolTypes@��r�RememberingFactoryr�-s���#�H�
�
rr�c���d�_�jr�j��j�j	�g�yr")�	_protocolrfrkr\�getDelayedCalls)r~r&�services���r�stopz0ClientServiceTests.makeReconnector.<locals>.stop9s9��� $�G������#�#�%�
���U�2�2�4�b�9r)	�updaterr�r�r�applicationFactoryrr�rU)r&r�rUr��kw�nkw�cq�endpointr�r1r�r�r~r�s`  `       @@@r�makeReconnectorz"ClientServiceTests.makeReconnectors����8���
�
���
�!��
�
�2���G���)�/�J���H�:<�;��r�6�	��	�+=�*>�>������'�9�S�9��	:�	
������� � �"��7�{�rc�x�|jd��\}}|jt|j�d�y)zL
        When the service is started, a connection attempt is made.
        Fr�r)N)r�r\r]r�)r&r�r�s   rr�z$ClientServiceTests.test_startServiceFs4���*�*�5�*�A���G�����R�_�_�-�q�1rc���|j�\}}|j}|j|jd�|jd}|j�|j|jd�y)a!
        Although somewhat obscure, L{IProtocolFactory} includes both C{doStart}
        and C{doStop} methods; ensure that when these methods are called on the
        factory that was passed to the reactor, the factory that was passed
        from the application receives them.
        rr)N)r�r�r\�numPortsr��doStart)r&r�r��firstAppFactory�firstPassedFactorys     r�test_startStopFactoryz(ClientServiceTests.test_startStopFactoryMsj���*�*�,���G��/�/������1�1�1�5��/�/��2���"�"�$�����1�1�1�5rc�<�|j�\}}|j�}|j|�|jd}|j	|j
jd�|jtt���|j|�y)z�
        When the service is stopped, no further connect attempts are made.  The
        returned L{Deferred} fires when all outstanding connections have been
        stopped.
        rTN)r�rkr�r�r\r��
disconnecting�connectionLostr�	Exceptionr��r&r�r�r-r�s     r�test_stopServiceWhileConnectedz1ClientServiceTests.test_stopServiceWhileConnected[s����*�*�,���G����!�����A���*�*�1�-������+�+�9�9�4�@�����	�� 4�5����Q�rc���|j�\}}|j�}|j|�|jd}|j	|j
jd�|j�|j|�|j	t|j�d�|jtt���|j	t|j�d�y)z�
        When L{ClientService} is restarted after having been connected, it
        waits to start connecting until after having disconnected.
        rTr)r{N)r�rkr�r�r\r�r�rUr]r�rr�r�s     r�#test_startServiceWaitsForDisconnectz6ClientServiceTests.test_startServiceWaitsForDisconnectis���
�*�*�,���G����!�����A���*�*�1�-������+�+�9�9�4�@��������A������R�4�4�5�q�9�����	�� 4�5�����R�4�4�5�q�9rc�F�|jd��\}}|jdjd�|jd}|j	�}|j|�|j
�}|j|�|j�|j|�|j|�|j|jjd�|jtt���|j|�|jdjd�|jt|j�d�|j!|j|�|j"d�|j	�}|j|�y)a%
        When L{ClientService} is stopping - that is,
        L{ClientService.stopService} has been called, but the L{Deferred} it
        returns has not fired yet - calling L{startService} will cause a new
        connection to be made, and new calls to L{whenConnected} to succeed.
        Fr�rNTr)r{)r�r�r6r�rkr��
whenConnectedrUr\r�r�r�rr�r�r]rOr�)r&r�r��first�stopped�nextProtocol�
secondStoppeds       r�test_startServiceWhileStoppingz1ClientServiceTests.test_startServiceWhileStoppingysX���*�*�5�*�A���G�
�����#�#�D�)��'�'��*���%�%�'�����G�$��,�,�.�����L�)��������L�)����G�$�������6�6��=�
���W�Y�[�1�2����W�%�
�����#�#�D�)�����R�4�4�5�q�9����� � ��.��0G�0G��0J�	
� �+�+�-�
����M�*rc��|jd��\}}|j�}|j|�|j|j	�t
�|j
�|jdjd�|j|jd|j|j	���y)a
        When L{ClientService} is stopped - that is,
        L{ClientService.stopService} has been called and the L{Deferred} it
        returns has fired - calling L{startService} will cause a new connection
        to be made, and new calls to L{whenConnected} to succeed.
        Fr����N)r�rkr��failureResultOfr�r
rUr�r6rOr�)r&r�r�r�s    r�test_startServiceWhileStoppedz0ClientServiceTests.test_startServiceWhileStopped�s����*�*�5�*�A���G��%�%�'�����W�%����W�2�2�4�n�E�����
�����$�$�T�*�����#�#�B�'��)=�)=�g�>S�>S�>U�)V�	
rc�(�ttt�Gd�dt��}|j	|��\}}|j
d}|j
tj|��|j
tj|��y)aC
        If the protocol objects returned by the factory given to
        L{ClientService} provide special "marker" interfaces for their
        transport - L{IHalfCloseableProtocol} or L{IFileDescriptorReceiver} -
        those interfaces will be provided by the protocol objects passed on to
        the reactor.
        c��eZdZdZy)�EClientServiceTests.test_interfacesForTransport.<locals>.FancyProtocolz9
            Provider of various interfaces.
            N)r;r<r=r>rrr�
FancyProtocolr�s��
rr)r�rN)rr
rrr�r�r��
providedBy)r&rr�r��
reactorFacings     r�test_interfacesForTransportz.ClientServiceTests.test_interfacesForTransport�s���
�+�-D�	E�	�H�	�
F�	�
�*�*�
�*�F���G��/�/��2�
����/�:�:�=�I�J����.�9�9�-�H�Irc��t�}|jd|��\}}|jdjt	��|jt�|jt|j�d�|j�}|jdjt	��|j|�y)zU
        When the service is stopped while retrying, the retry is cancelled.
        F�r�r~rr{r)N)rr�r�r+r��advance�AT_LEAST_ONE_ATTEMPTr\r]rkr��r&r~r�r�r-s     r�test_stopServiceWhileRetryingz0ClientServiceTests.test_stopServiceWhileRetrying�s�������*�*�5��*�N���G�
�����"�"�9�;�/�
�
�
�*�+�����R�_�_�-�q�1����!��
�����"�"�9�;�/����Q�rc��t�}|jd|��\}}|jt|j�d�|j|jd�|j
�}|j|�y)zv
        When the service is stopped while initially connecting, the connection
        attempt is cancelled.
        Frr)rN)rr�r\r]r�r�rkr�rs     r�test_stopServiceWhileConnectingz2ClientServiceTests.test_stopServiceWhileConnecting�sp��
����*�*�5��*�N���G�����R�_�_�-�q�1����B�O�O�A�.�/����!�����Q�rc��t�}|j|��\}}|j�}|j|j	�g�|j|j
|�|jd�y)zy
        When a client connects, the service keeps a reference to the new
        protocol and resets the delay.
        r�rN)rr�r�r\r�rOr�r�)r&r~r�r��awaitingProtocols     r�test_clientConnectedz'ClientServiceTests.test_clientConnected�st��
����*�*��*�7���G�"�0�0�2������.�.�0�"�5����� � �!1�2�B�4K�4K�A�4N�	
rc���t�}|jd|��\}}|jt|j�d�|jdjt
t���|j�}|j|�|jd��|jt�|jt|j�d�y)z�
        When a client connection fails, the service removes its reference
        to the protocol and tries again after a timeout.
        Frr)rc�,�|jt�Sr")�trapr
)r�s rr.z@ClientServiceTests.test_clientConnectionFailed.<locals>.<lambda>�s�����n�1M�rr{N)
rr�r\r]r�r+rr�r�r��
addErrbackr	r
)r&r~r�r�r�s     r�test_clientConnectionFailedz.ClientServiceTests.test_clientConnectionFailed�s���
����*�*�5��*�N���G�����R�_�_�-�q�1�
�����"�"�7�9�;�#7�8��-�-�/�
����M�*�	� � �!M�N�
�
�
�*�+�����R�_�_�-�q�1rc��t�}|j|d��\}}|jt|j�d�|jdjd�|jt|j�d�|j
|j|j��|jd�|jdjtt���|jt�|jt|j�d�|jdjd�|j
|j|j��|jd�y)z~
        When a client connection is lost, the service removes its reference
        to the protocol and calls retry.
        F)r~r�r)rNr{)rr�r\r]r�r6rOr�r�r�r�r�rr�r	r
)r&r~r�r�s    r�test_clientConnectionLostz,ClientServiceTests.test_clientConnectionLost�s2��
����*�*���*�N���G�����R�_�_�-�q�1�
�����#�#�D�)�����R�_�_�-�q�1����� � ��!6�!6�!8�9�2�;R�;R�ST�;U�	
�	����"�1�1�'�)�+�2F�G�
�
�
�*�+�����R�_�_�-�q�1�
�����#�#�D�)����� � ��!6�!6�!8�9�2�;R�;R�ST�;U�	
rc�>�t�}|j|��\}}|j�}|jdj	tt
���|j|j�t�|j|j�y)z�
        When a client connection is lost while the service is stopping, the
        protocol stopping deferred is called and the reference to the protocol
        is removed.
        r�rN)rr�rkr�r�r�IndentationErrorr�r�r
r��calledrs     r�&test_clientConnectionLostWhileStoppingz9ClientServiceTests.test_clientConnectionLostWhileStoppings{������*�*��*�7���G����!��
����"�1�1�'�:J�:L�2M�N����W�2�2�4�n�E�������!rc��|jdd��\}}|jt|j�d�|j	�|jt|j�d�t|�}|j	�|jt|j�d�|j
d|�d�y)z�
        If L{ClientService} is started when it's already started, it will log a
        complaint and do nothing else (in particular it will not make
        additional connections).
        F)r�rUrr)z$Duplicate ClientService.startServiceN)r�r\r]r�rUr��assertIn)r&r�r��messagess    r�test_startTwicez"ClientServiceTests.test_startTwices����*�*�5�u�*�U���G�����R�_�_�-�q�1���������R�_�_�-�q�1��T�?����������R�_�_�-�q�1��
�
�<�h�j��m�Lrc�6�t�}|jd|��\}}|j�}|j�}|jd��}|j|�|j|�|j|�|jdjd�|j
|�}|j
|�}|j
|�}	|j||�|j||	�|j||jd�y)z{
        L{ClientService.whenConnected} returns a L{Deferred} that fires when a
        connection is established.
        Frr)��failAfterFailuresrN)	rr�r�r�r�r6r�rOr�)
r&r~r�r��a�b�c�resultA�resultB�resultCs
          r�test_whenConnectedLaterz*ClientServiceTests.test_whenConnectedLater"s���
����*�*�5��*�N���G��!�!�#���!�!�#���!�!�A�!�6�����A�����A�����A��
�����#�#�D�)��&�&�q�)���&�&�q�)���&�&�q�)�����W�g�.����W�g�.����W�b�&=�&=�a�&@�Arc�@�t�}|jd|��\}}|j�}|jd��}|jd��}|jd��}|j|�|j|�|j|�|j|�t	t��}|jdj|�|j|�|j|j|t
�|�|j|�|j|�|jt�|jt|j�d�|j|�|j|�|j|�t	t��}	|jdj|	�|j|�|j|j|t
�|	�|j|�t}
|j|
�|jt|j�d�|j|�|j|�|jdjd�|j|�}|j|�}|j||�|j||j d�|jd��}
|j|
�}|j||�y)	z�
        L{ClientService.whenConnected} returns a L{Deferred} that fails, if
        asked, when some number of connections have failed.
        Frr)r"r{�rN)rr�r�r�rr�r�r+rOr�r	r
r\r]r6r�r�)r&r~r�r��a0�a1�a2�a3�f1�f2�AT_LEAST_TWO_ATTEMPTS�resultA0�resultA3�a4�resultA4s               r�test_whenConnectedFailsz*ClientServiceTests.test_whenConnectedFails7s���
����*�*�5��*�N���G�
�
"�
"�
$��
�
"�
"�Q�
"�
7��
�
"�
"�Q�
"�
7��
�
"�
"�Q�
"�
7�����B�����B�����B�����B��
�Y�[�
!��
�����"�"�2�&����B�����T�1�1�"�i�@�"�E����B�����B��
�
�
�*�+�����R�_�_�-�q�1����B�����B�����B��
�Y�[�
!��
�����"�"�2�&����B�����T�1�1�"�i�@�"�E����B�� 4��
�
�
�+�,�����R�_�_�-�q�1����B�����B��
�����#�#�D�)��'�'��+���'�'��+�����X�x�0����X�r�'>�'>�q�'A�B��
"�
"�Q�
"�
7���'�'��+�����X�x�0rc���t�}|jd|��\}}|j�}|j�}|jd��}|j|�|j|�|j|�|j	�|jt�|j|t�|j|t�|j|t�y)z�
        L{ClientService.whenConnected} returns a L{Deferred} that fails when
        L{ClientService.stopService} is called.
        Frr)r"N)	rr�r�r�rkr	r
r�r
)r&r~r�r�r$r%r&s       r�test_whenConnectedStopServicez0ClientServiceTests.test_whenConnectedStopServiceqs���
����*�*�5��*�N���G��!�!�#���!�!�#���!�!�A�!�6�����A�����A�����A������
�
�
�*�+����Q��/����Q��/����Q��/rc��t�}|jd|��\}}|jdjt	d��|j�}|j
|j�g�|j|�y)z�
        When L{ClientService.stopService} is called while waiting between
        connection attempts, the pending reconnection attempt is cancelled and
        the service is stopped immediately.
        Frr�
no connectionN)	rr�r�r+r�rkr\r�r�rs     r�test_retryCancelledz&ClientServiceTests.test_retryCancelled�su������*�*�5��*�N���G�
�����"�"�9�_�#=�>����!������.�.�0�"�5����Q�rc��t�}|jdd|��\}}|j�}|j|j	|��y)z�
        Calling L{ClientService.stopService} before
        L{ClientService.startService} returns a L{Deferred} that has
        already fired with L{None}.
        F)r�rUr~N�rr�rk�assertIsNoner�)r&r~�_r�r-s     r�"test_stopServiceBeforeStartServicez5ClientServiceTests.test_stopServiceBeforeStartService�sT������)�)�!��U�*�
�
��7�
���!�����$�.�.�q�1�2rc��t�}|jd|��\}}|j�}|jdj	td��|j
�|j�}|j|j|�jt�|j|j|�jt�y)z�
        L{ClientService.whenConnected} returns a L{Deferred} that
        errbacks with L{CancelledError} if
        L{ClientService.stopService} is called between connection
        attempts.
        Frrr<N)rr�r�r�r+r�rkr�r�r�r
)r&r~r�r��beforeErrbackAndStop�afterErrbackAndStops      r�'test_whenConnectedErrbacksOnStopServicez:ClientServiceTests.test_whenConnectedErrbacksOnStopService�s�������*�*�5��*�N���G�&�4�4�6��	�����"�"�9�_�#=�>�����%�3�3�5������ � �!5�6�<�<�n�	
�	
���� � �!4�5�;�;�^�	
rc�b�t�}|jd|��\}}|jdjd�|j	�}|j	�}|j
dj
tt���|j|�|j|�y)z�
        Calling L{ClientService.stopService} twice after it has
        connected (that is, stopping it while it is disconnecting)
        returns a L{Deferred} each time that fires when the
        disconnection has completed.
        FrrN)
rr�r�r6rkr�r�rrr��r&r~r�r��firstStopDeferred�secondStopDeferreds      r�"test_stopServiceWhileDisconnectingz5ClientServiceTests.test_stopServiceWhileDisconnecting�s�������*�*�5��*�N���G�
�����#�#�D�)�$�/�/�1��$�0�0�2��	����"�1�1�'�:J�:L�2M�N����.�/����/�0rc��t�}|jd|��\}}|jdjd�|j	�}|j�|j	�}|jdjtt���|j|�|j|�y)z�
        Calling L{ClientService.stopService} after calling a
        reconnection attempt returns a L{Deferred} that fires when the
        disconnection has completed.
        FrrN)rr�r�r6rkrUr�r�rrr�rHs      r�test_stopServiceWhileRestartingz2ClientServiceTests.test_stopServiceWhileRestarting�s�������*�*�5��*�N���G�
�����#�#�D�)�$�/�/�1������$�0�0�2��	����"�1�1�'�:J�:L�2M�N����.�/����/�0rc��t�}|jd|��\}}|j�}|j�}|j|j	|��|j|j	|��y)z�
        Calling L{ClientService.stopService} on a stopped service
        returns a L{Deferred} that has already fired with L{None}.
        FrNr?)r&r~rAr�rIrJs      r� test_stopServiceOnStoppedServicez3ClientServiceTests.test_stopServiceOnStoppedService�sv��
����)�)�%�u�)�M�
��7�#�/�/�1��$�0�0�2�����$�.�.�/@�A�B����$�.�.�/A�B�Crc�l��dg��fd�}|j|d��\}}|jd�d�y)z�
        The C{prepareConnection} callable is called after
        L{ClientService.startService} once the connection is made.
        rc� ���dxxdz
cc<y�Nrr)r��_proto�preparess �r�prepareConnectionz[ClientServiceTests.test_prepareConnectionCalledWhenServiceStarts.<locals>.prepareConnection������Q�K�1��KrT)rVrUr)N)r�r\)r&rVr�r�rUs    @r�-test_prepareConnectionCalledWhenServiceStartsz@ClientServiceTests.test_prepareConnectionCalledWhenServiceStarts�sG���
�3��	��*�*�/�d�+�
���G�	
����H�Q�K�(rc���g��fd�}|j|��\}}|j|jd�d�y)zf
        The C{prepareConnection} callable is passed the connected protocol
        instance.
        c�(���j|�yr"�rm)�proto�newProtocolss �rrVzVClientServiceTests.test_prepareConnectionCalledWithProtocol.<locals>.prepareConnection	s�������&r�rVrN)r�rOr�)r&rVr�r�r]s    @r�(test_prepareConnectionCalledWithProtocolz;ClientServiceTests.test_prepareConnectionCalledWithProtocolsN���
��	'��*�*�/�+�
���G�	
���R�4�4�Q�7��a��Irc�`��dg��fd�}t�}|j|d|��\}}|jdjt	d��|jd�d�|j
t�|jdjd�|jd�d�y)zf
        The C{prepareConnection} callback is invoked only once a connection is
        made.
        rc� ���dxxdz
cc<yrRrrSs �rrVz]ClientServiceTests.test_prepareConnectionCalledAfterConnectionMade.<locals>.prepareConnectionrWrF)rVr�r~zconnection attempt failedr)N)	rr�r�r+r�r\r	r
r6�r&rVr~r�r�rUs     @r�/test_prepareConnectionCalledAfterConnectionMadezBClientServiceTests.test_prepareConnectionCalledAfterConnectionMades����
�3��	�����*�*�/��e�+�
���G�	�����"�"�9�-H�#I�J�����H�Q�K�(�
�
�
�*�+�
�����#�#�D�)�����H�Q�K�(rc�2��dg��fd�}t�}|j||��\}}|jd�d�|jdj	tt
���|jt�|jd�d�y)z�
        The C{prepareConnection} callback is invoked each time a connection is
        made, including on reconnection.
        rc� ���dxxdz
cc<yrRrrSs �rrVzUClientServiceTests.test_prepareConnectionCalledOnReconnect.<locals>.prepareConnection/rWr�rVr~r)r{N)	rr�r\r�r�rrr	r
rbs     @r�'test_prepareConnectionCalledOnReconnectz:ClientServiceTests.test_prepareConnectionCalledOnReconnect(s����
�3��	�����*�*�/�u�+�
���G�	
����H�Q�K�(�	����"�1�1�'�:J�:L�2M�N�
�
�
�*�+�����H�Q�K�(rc���t���fd�}|j|��\}}|j|j��}|j	�|�y)a?
        The C{prepareConnection} return value is ignored when it does not
        indicate a failure. Even though the callback participates in the
        internal new-connection L{Deferred} chain for error propagation
        purposes, any successful result does not affect the ultimate return
        value.
        c����Sr"r)r\�sentinels �rrVzVClientServiceTests.test_prepareConnectionReturnValueIgnored.<locals>.prepareConnectionJs����Orr^N)r�r�r�r��assertNotIdentical)r&rVr�r�r2rjs     @r�(test_prepareConnectionReturnValueIgnoredz;ClientServiceTests.test_prepareConnectionReturnValueIgnored?sT����8��	��*�*�=N�*�O���G��%�%�g�&;�&;�&=�>������&�1rc����g�t����fd�}|j|��\}}|j�}|j|��j	d�|j|jd|j|��y)z�
        The C{prepareConnection} callable returns a deferred and calls to
        L{ClientService.whenConnected} wait until it fires.
        c�*���j|��Sr"r[)r\�newProtocolDeferredr]s ��rrVzVClientServiceTests.test_prepareConnectionReturningADeferred.<locals>.prepareConnectionZs�������&�&�&rr^Nr)rr�r�r�r6rOr�r�)r&rVr�r��whenConnectedDeferredror]s     @@r�(test_prepareConnectionReturningADeferredz;ClientServiceTests.test_prepareConnectionReturningADeferredRs����
��&�j��	'��*�*�=N�*�O���G� '� 5� 5� 7�����1�2��$�$�T�*�����#�#�A�&��(<�(<�=R�(S�	
rc�d�t�}d�}|j||��\}}|jd��}|j|�|j	t
�|j|�|j	t
�|j
t|j|�j�y)zs
        The connection attempt counts as a failure when the
        C{prepareConnection} callable throws.
        c��t��r")r)rTs rrVzJClientServiceTests.test_prepareConnectionThrows.<locals>.prepareConnectionps��"�$�$rrfr{r"N)
rr�r�r�r	r
rOrr��type)r&r~rVr�r�rps      r�test_prepareConnectionThrowsz/ClientServiceTests.test_prepareConnectionThrowsis���
���	%��*�*�/�u�+�
���G�!(� 5� 5�� 5� J�����1�2�
�
�
�*�+����1�2�
�
�
�*�+�����d�2�2�3H�I�N�N�	
rN)$r;r<r=r>rr�r�r�r�r�r�r�rrrrrrrr r*r8r:r=rBrFrKrMrOrXr_rcrgrlrqrurrrr�r��s����
#��H�A�F2�6� �:� +�8
�"J�( �
 �
�2�"
�*"�
M�B�*81�t0�& �3�
�21�.1�0D�
)�
J�)�.)�.2�&
�.
rr�)F)0r>r��zope.interfacer�zope.interface.verifyr�twisted.applicationr�twisted.application.internetrrr�twisted.internetr	�twisted.internet.deferr
r�twisted.internet.interfacesrr
rrr�twisted.internet.protocolrr�twisted.internet.taskr�twisted.internet.testingr�twisted.loggerrr�twisted.python.failurer�twisted.trial.unittestrrrr r#rHryr�r�r�r
r�rrr�<module>r�s���
��&�-�(���
"�;���8�'�4�:�*�@�	�
�
"�#�=*�=*�$�=*�@�!�:�.�
�^��
�
��
�6�!�:�.�V1�8�V1�rC-��C-�L"�"�( &�F&8�:�$��B

�,�B

r

Zerion Mini Shell 1.0