%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�����dZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
ddlmZmZddlmZddlmZddlmZ	dd	lmZeZerej4sdZGd
�de�ZGd�d
e�ZGd�de�ZGd�de�ZGd�de�ZdZ Gd�dejB�Z"eejFe
d�d�Gd�de��Z$eejJe
d�d�Gd�de��Z&Gd�dejN�Z(Gd�d ejR�Z*Gd!�d"e�Z+Gd#�d$�Z,Gd%�d&ejZ�Z.Gd'�d(e,�Z/Gd)�d*e�Z0Gd+�d,e�Z1Gd-�d.e�Z2y#e$rdZY��;wxYw)/zB
Tests for lots of functionality provided by L{twisted.internet}.
�N)�skipIf)�abstract�base�defer�error�
interfaces�protocol�reactor)�Deferred�passthru)�	Connector)�util)�TestCase)�sslc��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�ThreePhaseEventTestszQ
    Tests for the private implementation helpers for system event triggers.
    c�d�d�|_t�|_tj�|_y)zR
        Create a trigger, an argument, and an event to be used by tests.
        c��y�N�)�xs �</usr/lib/python3/dist-packages/twisted/test/test_internet.py�<lambda>z,ThreePhaseEventTests.setUp.<locals>.<lambda>(���N)�trigger�object�argr�_ThreePhaseEvent�event��selfs r�setUpzThreePhaseEventTests.setUp$s$��&����8����*�*�,��
rc��|jt|jjd|j|j
�y)zt
        L{_ThreePhaseEvent.addTrigger} should raise L{KeyError} when called
        with an invalid phase.
        �xxxN)�assertRaises�KeyErrorr �
addTriggerrrr!s r�test_addInvalidPhasez)ThreePhaseEventTests.test_addInvalidPhase,s/��
	
����d�j�j�+�+�U�D�L�L�$�(�(�	
rc���|jjd|j|j�|j	|jj
|j|jfifg�y)z�
        L{_ThreePhaseEvent.addTrigger} should accept C{'before'} as a phase, a
        callable, and some arguments and add the callable with the arguments to
        the before list.
        �beforeN)r r(rr�assertEqualr+r!s r�test_addBeforeTriggerz*ThreePhaseEventTests.test_addBeforeTrigger5�P��	
�
�
���h����d�h�h�?�������*�*�d�l�l�T�X�X�K��-L�,M�Nrc���|jjd|j|j�|j	|jj
|j|jfifg�y)z�
        L{_ThreePhaseEvent.addTrigger} should accept C{'during'} as a phase, a
        callable, and some arguments and add the callable with the arguments to
        the during list.
        �duringN)r r(rrr,r0r!s r�test_addDuringTriggerz*ThreePhaseEventTests.test_addDuringTrigger>r.rc���|jjd|j|j�|j	|jj
|j|jfifg�y)z�
        L{_ThreePhaseEvent.addTrigger} should accept C{'after'} as a phase, a
        callable, and some arguments and add the callable with the arguments to
        the after list.
        �afterN)r r(rrr,r3r!s r�test_addAfterTriggerz)ThreePhaseEventTests.test_addAfterTriggerGsP��	
�
�
���g�t�|�|�T�X�X�>�������)�)�T�\�\�D�H�H�;��,K�+L�Mrc���|jjd|j|j�}|jj	|�|j|jjg�y)z�
        L{_ThreePhaseEvent.removeTrigger} should accept an opaque object
        previously returned by L{_ThreePhaseEvent.addTrigger} and remove the
        associated trigger.
        r+N)r r(rr�
removeTriggerr,r+�r"�handles  r�test_removeTriggerz'ThreePhaseEventTests.test_removeTriggerPsP�����&�&�x����t�x�x�H���
�
� � ��(�������*�*�B�/rc�j�|jt|jjt	��y)z�
        L{_ThreePhaseEvent.removeTrigger} should raise L{ValueError} when given
        an object not previously returned by L{_ThreePhaseEvent.addTrigger}.
        N)r&�
ValueErrorr r6rr!s r�test_removeNonexistentTriggerz2ThreePhaseEventTests.test_removeNonexistentTriggerZs"��
	
���*�d�j�j�&>�&>���Irc���|jjd|j|j�}|jj	|�|jt|jj|�y)z�
        L{_ThreePhaseEvent.removeTrigger} should raise L{ValueError} the second
        time it is called with an object returned by
        L{_ThreePhaseEvent.addTrigger}.
        r+N)r r(rrr6r&r;r7s  r�test_removeRemovedTriggerz.ThreePhaseEventTests.test_removeRemovedTriggerasR�����&�&�x����t�x�x�H���
�
� � ��(����*�d�j�j�&>�&>��Grc��|jt|jjd|j|j
fif�y)z�
        L{_ThreePhaseEvent.removeTrigger} should raise L{ValueError} if it is
        given a trigger handle which resembles a valid trigger handle aside
        from its phase being incorrect.
        r%N)r&r'r r6rrr!s r�test_removeAlmostValidTriggerz2ThreePhaseEventTests.test_removeAlmostValidTriggerks7��	
����d�j�j�.�.�����t�x�x�k�SU�0V�	
rc�\�g}|jjd|jd�|jjd|jd�|jjd|jd�|jjd|jd�|jjd|jd�|jjd|jd	�|j|g�|jj	�|j|gd
��y)z�
        L{_ThreePhaseEvent.fireEvent} should call I{before}, I{during}, and
        I{after} phase triggers in that order.
        r3��firstr3r0�rCr0r+�rCr+��secondr+�rGr0�rGr3)rErFrDrHrBrIN)r r(�appendr,�	fireEvent�r"�eventss  r�test_fireEventz#ThreePhaseEventTests.test_fireEventus���
���
�
���g�v�}�}�6H�I��
�
���h��
�
�7J�K��
�
���h��
�
�7J�K��
�
���h��
�
�7K�L��
�
���h��
�
�7K�L��
�
���g�v�}�}�6I�J������$��
�
��������
�
	
rc���g}t��|jjd�fd��|jjd|jd�|jjd|jd�|j	|g�|jj�|j	|g��j
d�|j	|ddg�y)z�
        L{_ThreePhaseEvent.fireEvent} should wait for any L{Deferred} returned
        by a I{before} phase trigger before proceeding to I{during} events.
        r+c����Srr��beforeResults�rrz>ThreePhaseEventTests.test_asynchronousBefore.<locals>.<lambda>������rr0r3N)rr r(rJr,rK�callback)r"rMrRs  @r�test_asynchronousBeforez,ThreePhaseEventTests.test_asynchronousBefore�s����
���z���
�
���h�(<�=��
�
���h��
�
�x�@��
�
���g�v�}�}�g�>������$��
�
���������$����d�#�����(�G�!4�5rc���g}Gd�dt���fd�}|jjd|�|jjd|jd�|jjd|jd�|jj	�|j|ddg�|j
��}|jt|�d�y)z�
        If a before-phase trigger raises a synchronous exception, it should be
        logged and the remaining triggers should be run.
        c��eZdZy)�HThreePhaseEventTests.test_beforeTriggerException.<locals>.DummyExceptionN��__name__�
__module__�__qualname__rrr�DummyExceptionrX����rr]c������rr�r]s�r�raisingTriggerzHThreePhaseEventTests.test_beforeTriggerException.<locals>.raisingTrigger����� �"�"rr+r0�N��	Exceptionr r(rJrKr,�flushLoggedErrors�len�r"rMra�errorsr]s    @r�test_beforeTriggerExceptionz0ThreePhaseEventTests.test_beforeTriggerException�s����
��	�Y�	�	#�	
�
�
���h��7��
�
���h��
�
�x�@��
�
���h��
�
�x�@��
�
��������(�H�!5�6��'�'��7������V��a�(rc���g}Gd�dt���fd�}|jjd|�|jjd|jd�|jjd|jd�|jj	�|j|ddg�|j
��}|jt|�d�y)z�
        If a during-phase trigger raises a synchronous exception, it should be
        logged and the remaining triggers should be run.
        c��eZdZy)�HThreePhaseEventTests.test_duringTriggerException.<locals>.DummyExceptionNrYrrrr]rm�r^rr]c������rrr`s�rrazHThreePhaseEventTests.test_duringTriggerException.<locals>.raisingTrigger�rbrr0r3rcNrdrhs    @r�test_duringTriggerExceptionz0ThreePhaseEventTests.test_duringTriggerException�s����
��	�Y�	�	#�	
�
�
���h��7��
�
���h��
�
�x�@��
�
���g�v�}�}�g�>��
�
��������(�G�!4�5��'�'��7������V��a�(rc�t���g}��fd�}�jjd|jd���jjd|��jjd|jd��jtdt
�jj��j|ddg�y)z�
        If a before-phase trigger tries to remove another before-phase trigger
        which has already run, a warning should be emitted.
        c�<���jj��yr�r r6��beforeHandler"s��rr6zWThreePhaseEventTests.test_synchronousRemoveAlreadyExecutedBefore.<locals>.removeTrigger�s����J�J�$�$�\�2rr+rErFzdRemoving already-fired system event triggers will raise an exception in a future version of Twisted.N)r r(rJ�assertWarns�DeprecationWarning�__file__rKr,)r"rMr6rts`  @r�+test_synchronousRemoveAlreadyExecutedBeforez@ThreePhaseEventTests.test_synchronousRemoveAlreadyExecutedBefore�s����
��	3��z�z�,�,��f�m�m�%8�
��	
�
�
���h�
�6��
�
���h��
�
�7K�L�����
8���J�J� � �	
�	
����"5�7K�!L�Mrc�B���g}�jjd��fd���jjd|jd���jjd|jd��jj��j	|dg�y)z�
        If a before-phase trigger removes another before-phase trigger which
        has not yet run, the removed trigger should not be run.
        r+c�:���jj��Srrrrss��rrzJThreePhaseEventTests.test_synchronousRemovePendingBefore.<locals>.<lambda>������
�
�0H�0H��0V�rrErFN�r r(rJrKr,)r"rMrts` @r�#test_synchronousRemovePendingBeforez8ThreePhaseEventTests.test_synchronousRemovePendingBefore�����
���
�
���h�(V�W��z�z�,�,��f�m�m�%8�
��	
�
�
���h��
�
�7K�L��
�
��������"6�!7�8rc�B���g}�jjd��fd���jjd|jd���jjd|jd��jj��j	|dg�y)z
        If a before-phase trigger removes a during-phase trigger, the
        during-phase trigger should not be run.
        r+c�:���jj��Srrr��duringHandler"s��rrzJThreePhaseEventTests.test_synchronousBeforeRemovesDuring.<locals>.<lambda>�r{rr0r3Nr|�r"rMr�s` @r�#test_synchronousBeforeRemovesDuringz8ThreePhaseEventTests.test_synchronousBeforeRemovesDuring�sw���
���
�
���h�(V�W��z�z�,�,�X�v�}�}�h�O���
�
���g�v�}�}�g�>��
�
��������'��+rc���g}t��|jjd�fd��|jjd|jd�}|jjd|jd�|jj	�|jj|��j
d�|j|dg�y)z�
        If a before-phase trigger returns a L{Deferred} and later removes a
        during-phase trigger before the L{Deferred} fires, the during-phase
        trigger should not be run.
        r+c����SrrrQs�rrzKThreePhaseEventTests.test_asynchronousBeforeRemovesDuring.<locals>.<lambda>rSrr0r3N)rr r(rJrKr6rTr,)r"rMr�rRs   @r�$test_asynchronousBeforeRemovesDuringz9ThreePhaseEventTests.test_asynchronousBeforeRemovesDuring�s�������z���
�
���h�(<�=��z�z�,�,�X�v�}�}�h�O���
�
���g�v�}�}�g�>��
�
�����
�
� � ��.����d�#�����'��+rc�"����g��fd�}�jjd|��jjd��fd���jjd|���jj��j�dg�y)a
        If a before-phase trigger removes a during-phase trigger which is
        identical to an already-executed before-phase trigger aside from their
        phases, no warning should be emitted and the during-phase trigger
        should not be run.
        c�(���jd�y)Nr�rJ�rMs�rrz]ThreePhaseEventTests.test_synchronousBeforeRemovesConspicuouslySimilarDuring.<locals>.triggers����M�M�)�$rr+c�:���jj��Srrr)�
duringTriggerr"s��rrz^ThreePhaseEventTests.test_synchronousBeforeRemovesConspicuouslySimilarDuring.<locals>.<lambda>s����
�
�0H�0H��0W�rr0rN)r r(rKr,)r"rr�rMs` @@r�7test_synchronousBeforeRemovesConspicuouslySimilarDuringzLThreePhaseEventTests.test_synchronousBeforeRemovesConspicuouslySimilarDuring
sr�����	%�	
�
�
���h��0��
�
���h�(W�X��
�
�-�-�h��@�
��
�
��������)��-rc�B���g}�jjd��fd���jjd|jd���jjd|jd��jj��j	|dg�y)z�
        If a during-phase trigger removes another during-phase trigger which
        has not yet run, the removed trigger should not be run.
        r0c�:���jj��Srrrr�s��rrzJThreePhaseEventTests.test_synchronousRemovePendingDuring.<locals>.<lambda>%r{rrDrHNr|r�s` @r�#test_synchronousRemovePendingDuringz8ThreePhaseEventTests.test_synchronousRemovePendingDuringr~rc��g}|jjd|jd�|jjd|jd�|jjd|jd�|jj�|jj�|j	|gd��y)zm
        A trigger should only be called on the first call to
        L{_ThreePhaseEvent.fireEvent}.
        r+r0r3)r+r0r3Nr|rLs  r�test_triggersRunOncez)ThreePhaseEventTests.test_triggersRunOnce-s���
���
�
���h��
�
�x�@��
�
���h��
�
�x�@��
�
���g�v�}�}�g�>��
�
�����
�
��������!>�?rc����g���fd�}�jjd�jd��jjd|��jj��j	�ddg�y)z�
        The temporary list L{_ThreePhaseEvent.finishedBefore} should be emptied
        and the state reset to C{'BASE'} before the first during-phase trigger
        executes.
        c����jd��j�jjg��j�jjd�y)Nr0�BASE)rJr,r �finishedBefore�state)rMr"s��rr�zNThreePhaseEventTests.test_finishedBeforeTriggersCleared.<locals>.duringTriggerBsC����M�M�(�#����T�Z�Z�6�6��;����T�Z�Z�-�-�v�6rr+r0Nr|)r"r�rMs` @r�"test_finishedBeforeTriggersClearedz7ThreePhaseEventTests.test_finishedBeforeTriggersCleared:sd�����	7�
	
�
�
���h��
�
�x�@��
�
���h�
�6��
�
��������(�H�!5�6rN)rZr[r\�__doc__r#r)r-r1r4r9r<r>r@rNrUrjrorxr}r�r�r�r�r�r�rrrrrsw���-�
�O�O�N�0�J�H�
�
�66�")�*)�*N�09�
,�,� .�$9�@�7rrc�v�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zy)�SystemEventTestsa
    Tests for the reactor's implementation of the C{fireSystemEvent},
    C{addSystemEventTrigger}, and C{removeSystemEventTrigger} methods of the
    L{IReactorCore} interface.

    @ivar triggers: A list of the handles to triggers which have been added to
        the reactor.
    c��g|_y)zI
        Create an empty list in which to store trigger handles.
        N)�triggersr!s rr#zSystemEventTests.setUpWs����
rc���|jr>|jj�}	tj|�|jr�=yy#tt
f$rY� wxYw)zA
        Remove all remaining triggers from the reactor.
        N)r��popr
�removeSystemEventTriggerr;r'�r"rs  r�tearDownzSystemEventTests.tearDown]sR���m�m��m�m�'�'�)�G�
��0�0��9��m�m����)�
��
�s�A�A�Ac�j�tj|||�}|jj|�|S)zS
        Add a trigger to the reactor and remember it in C{self.triggers}.
        )r
�addSystemEventTriggerr�rJ)r"r �phase�func�ts     rr(zSystemEventTests.addTriggerhs/��
�)�)�%���=���
�
���Q���rc�d�tj|�|jj|�y)zd
        Remove a trigger by its handle from the reactor and from
        C{self.triggers}.
        N)r
r�r��remover�s  rr6zSystemEventTests.removeTriggerps$��
	�(�(��1��
�
���W�%rc���d}g��fd�}|j|||�|j�g�tj|�|j�dg�y)N�testc�(���jd�yrr�r�s�rrz<SystemEventTests._addSystemEventTriggerTest.<locals>.trigger|�����M�M�$�r�r(r,r
�fireSystemEvent)r"r��	eventTyperrMs    @r�_addSystemEventTriggerTestz+SystemEventTests._addSystemEventTriggerTestxsT����	���	 �	
����y�'�2������$����	�*�����$��(rc�&�|jd�y)z�
        L{IReactorCore.addSystemEventTrigger} should accept the C{'before'}
        phase and not call the given object until the right event is fired.
        r+N�r�r!s r�test_beforePhasez!SystemEventTests.test_beforePhase����
	
�'�'��1rc�&�|jd�y)z�
        L{IReactorCore.addSystemEventTrigger} should accept the C{'during'}
        phase and not call the given object until the right event is fired.
        r0Nr�r!s r�test_duringPhasez!SystemEventTests.test_duringPhase�r�rc�&�|jd�y)z�
        L{IReactorCore.addSystemEventTrigger} should accept the C{'after'}
        phase and not call the given object until the right event is fired.
        r3Nr�r!s r�test_afterPhasez SystemEventTests.test_afterPhase�s��
	
�'�'��0rc�P�d}|jt|jd|d��y)z�
        L{IReactorCore.addSystemEventTrigger} should reject phases other than
        C{'before'}, C{'during'}, or C{'after'}.
        r�r%c��yrrrrrrz4SystemEventTests.test_unknownPhase.<locals>.<lambda>�rrN)r&r'r()r"r�s  r�test_unknownPhasez"SystemEventTests.test_unknownPhase�s#��
�	����(�D�O�O�U�I�|�Trc����d}g��fd�}�fd�}|jd||�|jd||�|j�g�tj|�|j�ddg�y)z�
        L{IReactorCore.addSystemEventTrigger} should call triggers added to the
        C{'before'} phase before it calls triggers added to the C{'during'}
        phase.
        r�c�(���jd�y�Nr+r�r�s�r�
beforeTriggerzASystemEventTests.test_beforePreceedsDuring.<locals>.beforeTrigger������M�M�(�#rc�(���jd�y�Nr0r�r�s�rr�zASystemEventTests.test_beforePreceedsDuring.<locals>.duringTrigger�r�rr+r0Nr�)r"r�r�r�rMs    @r�test_beforePreceedsDuringz*SystemEventTests.test_beforePreceedsDuring�sn����	���	$�	$�	
����)�]�;�����)�]�;������$����	�*�����(�H�!5�6rc����d}g��fd�}�fd�}|jd||�|jd||�|j�g�tj|�|j�ddg�y)z�
        L{IReactorCore.addSystemEventTrigger} should call triggers added to the
        C{'during'} phase before it calls triggers added to the C{'after'}
        phase.
        r�c�(���jd�yr�r�r�s�rr�z@SystemEventTests.test_duringPreceedsAfter.<locals>.duringTrigger�r�rc�(���jd�y)Nr3r�r�s�r�afterTriggerz?SystemEventTests.test_duringPreceedsAfter.<locals>.afterTrigger������M�M�'�"rr0r3Nr�)r"r�r�r�rMs    @r�test_duringPreceedsAfterz)SystemEventTests.test_duringPreceedsAfter�sn����	���	$�	#�	
����)�]�;������L�9������$����	�*�����(�G�!4�5rc�>���t��d}g��fd�}�fd�}|jd||�|jd||�|j�g�tj|�|j�g��jd�|j�dg�y)z�
        If a trigger added to the C{'before'} phase of an event returns a
        L{Deferred}, the C{'during'} phase should be delayed until it is called
        back.
        r�c����Srr)�triggerDeferreds�rr�zBSystemEventTests.test_beforeReturnsDeferred.<locals>.beforeTrigger�s	���"�"rc�(���jd�yr�r�r�s�rr�zBSystemEventTests.test_beforeReturnsDeferred.<locals>.duringTrigger�r�rr+r0N�rr(r,r
r�rT)r"r�r�r�rMr�s    @@r�test_beforeReturnsDeferredz+SystemEventTests.test_beforeReturnsDeferred�s����#�*���	���	#�	$�	
����)�]�;�����)�]�;������$����	�*������$�� � ��&�����(��,rc������t��t��d}g��fd�}�fd�}�fd�}|jd||�|jd||�|jd||�|j�g�tj|�|j�g��jd�|j�g��jd�|j�dg�y)z�
        If more than one trigger added to the C{'before'} phase of an event
        return L{Deferred}s, the C{'during'} phase should be delayed until they
        are all called back.
        r�c����Srr��
firstDeferreds�r�firstBeforeTriggerzNSystemEventTests.test_multipleBeforeReturnDeferred.<locals>.firstBeforeTrigger��	��� � rc����Srr)�secondDeferreds�r�secondBeforeTriggerzOSystemEventTests.test_multipleBeforeReturnDeferred.<locals>.secondBeforeTrigger�s	���!�!rc�(���jd�yr�r�r�s�rr�zISystemEventTests.test_multipleBeforeReturnDeferred.<locals>.duringTrigger�r�rr+r0Nr�)r"r�r�r�r�rMr�r�s     @@@r�!test_multipleBeforeReturnDeferredz2SystemEventTests.test_multipleBeforeReturnDeferred�s����!�
�
�!����	���	!�	"�	$�	
����)�-?�@�����)�-@�A�����)�]�;������$����	�*������$����t�$������$�����%�����(��,rc�����d}g�t��t���fd�}�fd�}��fd�}�fd�}|jd||�|jd||�|jd||�|jd||�|j�g�tj|�|j�dg��jd�|j�ddg�y)	aa
        If a trigger added to the C{'before'} phase of an event calls back a
        L{Deferred} returned by an earlier trigger in the C{'before'} phase of
        the same event, the remaining C{'before'} triggers for that event
        should be run and any further L{Deferred}s waited on before proceeding
        to the C{'during'} events.
        r�c����Srrr�s�rr�zaSystemEventTests.test_subsequentBeforeTriggerFiresPriorBeforeDeferred.<locals>.firstBeforeTriggerr�rc�(���jd�yr)rTr�s�rr�zbSystemEventTests.test_subsequentBeforeTriggerFiresPriorBeforeDeferred.<locals>.secondBeforeTriggers����"�"�4�(rc�*���jd��Sr�r��rMr�s��r�thirdBeforeTriggerzaSystemEventTests.test_subsequentBeforeTriggerFiresPriorBeforeDeferred.<locals>.thirdBeforeTriggers����M�M�(�#�!�!rc�(���jd�yr�r�r�s�rr�z\SystemEventTests.test_subsequentBeforeTriggerFiresPriorBeforeDeferred.<locals>.duringTriggerr�rr+r0Nr�)	r"r�r�r�r�r�rMr�r�s	      @@@r�4test_subsequentBeforeTriggerFiresPriorBeforeDeferredzESystemEventTests.test_subsequentBeforeTriggerFiresPriorBeforeDeferreds�����	��� �
�
�!���	!�	)�	"�	$�	
����)�-?�@�����)�-@�A�����)�-?�@�����)�]�;������$����	�*�����(��,�����%�����(�H�!5�6rc���d}g��fd�}�fd�}|jd||�|j|jd||��|j�g�tj|�|j�dg�y)z�
        A trigger removed with L{IReactorCore.removeSystemEventTrigger} should
        not be called when the event fires.
        r�c�(���jd�y)NrCr�r�s�rr�zJSystemEventTests.test_removeSystemEventTrigger.<locals>.firstBeforeTrigger.r�rc�(���jd�y)NrGr�r�s�rr�zKSystemEventTests.test_removeSystemEventTrigger.<locals>.secondBeforeTrigger1r�rr+rCN)r(r6r,r
r�)r"r�r�r�rMs    @r�test_removeSystemEventTriggerz.SystemEventTests.test_removeSystemEventTrigger&sx���
�	���	#�	$�	
����)�-?�@����4�?�?�8�Y�@S�T�U������$����	�*�����'��+rc	�H�|jddd��}|j|�|jttj
d�|jttj
|�|jttj
|dd|dddzf�y)aM
        Passing an object to L{IReactorCore.removeSystemEventTrigger} which was
        not returned by a previous call to
        L{IReactorCore.addSystemEventTrigger} or which has already been passed
        to C{removeSystemEventTrigger} should result in L{TypeError},
        L{KeyError}, or L{ValueError} being raised.
        r0r�c��yrrrrrrzKSystemEventTests.test_removeNonExistentSystemEventTrigger.<locals>.<lambda>BrrNr)r%rc)r(r6r&�	TypeErrorr
r�r;r')r"�bs  r�(test_removeNonExistentSystemEventTriggerz9SystemEventTests.test_removeNonExistentSystemEventTrigger:s���
�O�O�H�f�l�;�����1�����)�W�%E�%E�t�L����*�g�&F�&F��J�����g�6�6��1��x�!�A�$�q�r�(�?R�8S�	
rc�\���	�g�d}t����fd�}�fd�}d}t��	��	fd�}�fd�}|jd||�|jd||�|jd||�|jd||�|j�g�tj|�|j�d	g�tj|�|j�d	d
g��jd�|j�gd���	jd�|j�gd
��y)z�
        L{IReactorCore.fireSystemEvent} should behave the same way for a
        particular system event regardless of whether Deferreds are being
        waited on for a different system event.
        zfirst-eventc�*���jd��S)N�r+rCr�)rMr�s��r�beforeFirstEventzQSystemEventTests.test_interactionBetweenDifferentEvents.<locals>.beforeFirstEventUs����M�M�-�.� � rc�(���jd�y)N�r3rCr�r�s�r�afterFirstEventzPSystemEventTests.test_interactionBetweenDifferentEvents.<locals>.afterFirstEventYs����M�M�,�-rzsecond-eventc�*���jd��S)N�r+rGr�r�s��r�beforeSecondEventzRSystemEventTests.test_interactionBetweenDifferentEvents.<locals>.beforeSecondEvent_s����M�M�.�/�!�!rc�(���jd�y)N�r3rGr�r�s�r�afterSecondEventzQSystemEventTests.test_interactionBetweenDifferentEvents.<locals>.afterSecondEventcs����M�M�-�.rr+r3r�r�N)r�r�r�)r�r�r�r�r�)
r"�
firstEventr�r��secondEventr�r�rMr�r�s
       @@@r�&test_interactionBetweenDifferentEventsz7SystemEventTests.test_interactionBetweenDifferentEventsJs"�����"�
� �
�
�	!�	.�%��!���	"�	/�	
����*�.>�?������_�=�����+�/@�A������.>�?������$�	���
�+�����"5�!6�7�	����,�����"5�7K�!L�M�	���t�$�����S�	
�
	����%�����
�	
rN)rZr[r\r�r#r�r(r6r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�r�Ms^����	��&�
)�2�2�1�U�7�*6�*-�0-�>"7�H,�(
� >
rr�c�X�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zy)�	TimeTestsz9
    Tests for the IReactorTime part of the reactor.
    c�\�tj�}|j||z
|z|�y)aN
        L{twisted.internet.reactor.seconds} should return something
        like a number.

        1. This test specifically does not assert any relation to the
           "system time" as returned by L{time.time} or
           L{twisted.python.runtime.seconds}, because at some point we
           may find a better option for scheduling calls than
           wallclock-time.
        2. This test *also* does not assert anything about the type of
           the result, because operations may not return ints or
           floats: For example, datetime-datetime == timedelta(0).
        N)r
�secondsr,)r"�nows  r�test_secondszTimeTests.test_seconds�s(���o�o�������s��S��#�.rc��tj}d�t_	tjdd��}|j|j	�d�|t_|j�y#|t_wxYw)z�
        L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
        should use the reactor's seconds factory
        to produce the time at which the DelayedCall will be called.
        c��y�N�drrrrrzITimeTests.test_callLaterUsesReactorSecondsInDelayedCall.<locals>.<lambda>�rr�c��yrrrrrrzITimeTests.test_callLaterUsesReactorSecondsInDelayedCall.<locals>.<lambda>�rr�iN)r
r�	callLaterr,�getTime�cancel�r"�oseconds�calls   r�-test_callLaterUsesReactorSecondsInDelayedCallz7TimeTests.test_callLaterUsesReactorSecondsInDelayedCall��\���?�?��%���	'��$�$�Q��5�D����T�\�\�^�S�1�&�G�O����
��'�G�O���7A1�1
A>c��tj}d�t_	tjdd��}|j|j�d�|t_|j	�y#|t_wxYw)z�
        L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
        should propagate its own seconds factory
        to the DelayedCall to use as its own seconds factory.
        c��yrrrrrrzWTimeTests.test_callLaterUsesReactorSecondsAsDelayedCallSecondsFactory.<locals>.<lambda>�rrrc��yrrrrrrzWTimeTests.test_callLaterUsesReactorSecondsAsDelayedCallSecondsFactory.<locals>.<lambda>�rrrN)r
rrr,r
rs   r�;test_callLaterUsesReactorSecondsAsDelayedCallSecondsFactoryzETimeTests.test_callLaterUsesReactorSecondsAsDelayedCallSecondsFactory�rrc��t�}tjd|jd�|j	|j
d�|S)zc
        Test that a DelayedCall really calls the function it is
        supposed to call.
        rN)rr
rrT�addCallbackr,�r"�ds  r�test_callLaterzTimeTests.test_callLater�s:��

�J�����!�Q�Z�Z��.�	�
�
�d�&�&��-��rc���tjdtt�}|j|j�|j
}|j
d�|j|j
|�y)zS
        A L{DelayedCall} that is reset will be scheduled at the new time.
        �rcN)r
rr�
addCleanupr
�time�reset�assertNotEqual)r"r�origTimes   r�test_callLaterResetzTimeTests.test_callLaterReset�sP��� � ��H�h�7��������$��9�9���
�
�1�
����D�I�I�x�0rc������g��fd�}tjd|�}|j�t�����fd�}tjdtjd|��S)zL
        Test that when a DelayedCall is cancelled it does not run.
        c�(���jd�yrr�)�calleds�r�functionz2TimeTests.test_cancelDelayedCall.<locals>.function�r�rrc���	�j�g��jd�y#t$r�j�YywxYwr)r,rT�
BaseException�errback)r'rr"s���r�checkz/TimeTests.test_cancelDelayedCall.<locals>.check�s@���
!�� � ���,��
�
�4� ��!�
��	�	��
�s�'�A�A)r
rr
r)r"r(rr,r'rs`   @@r�test_cancelDelayedCallz TimeTests.test_cancelDelayedCall�s[�����	 �� � ��H�-�����
�
�J��	!�	���!�W�.�.��5�9��rc��tjdd��}|j�|jtj
|j�y)z
        Test that cancelling a DelayedCall which has already been cancelled
        raises the appropriate exception.
        rc��yrrrrrrz;TimeTests.test_cancelCancelledDelayedCall.<locals>.<lambda>�rrN)r
rr
r&r�AlreadyCancelled)r"rs  r�test_cancelCancelledDelayedCallz)TimeTests.test_cancelCancelledDelayedCall�s9��
� � ��L�1�����
����%�0�0�$�+�+�>rc�Z����t�����fd�}tjd|���S)z�
        Test that cancelling a DelayedCall in the DelayedCall's function as
        that function is being invoked by the DelayedCall raises the
        appropriate exception.
        c���	�jtj�j��j	d�y#t
$r�j
�YywxYwr�r&r�
AlreadyCalledr
rTr*r+�rrr"s���r�laterz@TimeTests.test_cancelCalledDelayedCallSynchronous.<locals>.later��J���
!��!�!�%�"5�"5�t�{�{�C��
�
�4� ��!�
��	�	��
���*?�A�Ar�rr
r)r"r7rrs` @@r�'test_cancelCalledDelayedCallSynchronousz1TimeTests.test_cancelCalledDelayedCallSynchronous�s*���
�J��	!�� � ��E�*���rc�f�����t�����fd���fd�}tjd|���S)z|
        Test that cancelling a DelayedCall after it has run its function
        raises the appropriate exception.
        c���	�jtj�j��j	d�y#t
$r�j
�YywxYwrr4r6s���rr,zATimeTests.test_cancelCalledDelayedCallAsynchronous.<locals>.checkr8r9c�2��tjd��y�Nr)r
r)r,s�rr7zATimeTests.test_cancelCalledDelayedCallAsynchronous.<locals>.laters������a��'rrr:)r"r7rr,rs` @@@r�(test_cancelCalledDelayedCallAsynchronousz2TimeTests.test_cancelCalledDelayedCallAsynchronous
s/���

�J��	!�	(�� � ��E�*���rc���tjdd��}	|j|j�t	j�dzz
dk�|j�y#|j�wxYw)N�
c��yrrrrrrz-TimeTests.testCallLaterTime.<locals>.<lambda> rrrc)r
r�
assertTruerr r
rs  r�testCallLaterTimezTimeTests.testCallLaterTimesS�����b�,�/��	��O�O�A�I�I�K�4�9�9�;��+;�<�q�@�A�
�H�H�J��A�H�H�J�s�:A$�$A6c���tjdd�dd���t���jd�t���j	�t��tjdd�gtd���ddd	id
ftgi��t���j	�t���fd�}t
�j|�}tjd|jd��t��|S)Nrc��yrr)r�ys  rrz:TimeTests.testDelayedCallStringification.<locals>.<lambda>)rrrrB)rHrc��yrrrrrrz:TimeTests.testDelayedCallStringification.<locals>.<lambda>1rr�hello�worldy$@c���t��yr)�str)�ignored�dcs �r�
calledBackz<TimeTests.testDelayedCallStringification.<locals>.calledBack7s
�����Gr)	r
rrMr!r
�rangerrrT)r"rPrrOs   @r�testDelayedCallStringificationz(TimeTests.testDelayedCallStringification&s�����
�
�q�"3�S�B�
?���B��
������B��
�	�	���B��
�
�
�
�|�
�FK�B�i�
�")�7�!3�S� 9�7�C�
��	�B��
�	�	���B��	�
�J�"�"�:�.��
�
�
�q�!�*�*�d�
3���B���rc	���d�}tjdd�did�d�|�}|j|j�d�|j	d�|j|j�d�y)	z�
        Test that the C{seconds} argument to DelayedCall gets used instead of
        the default timing function, if it is not None.
        c��y)NrBrrrrrz9TimeTests.testDelayedCallSecondsOverride.<locals>.secondsEs��rrc��yrrrrrrz:TimeTests.testDelayedCallSecondsOverride.<locals>.<lambda>Irrrc��yrr)rOs rrz:TimeTests.testDelayedCallSecondsOverride.<locals>.<lambda>Irr��
N)r�DelayedCallr,rr!)r"rrOs   r�testDelayedCallSecondsOverridez(TimeTests.testDelayedCallSecondsOverride?sa��	��
�
�
�|�R��_�o�w�
��	
�������q�)�
������������r�*rN)rZr[r\r�rrrrr$r-r1r;r@rErRrZrrrr�r��sC���/�"
�
��1��6?��&�*��2+rr�c�f�eZdZeej
ed�d�d��Zd�Zd�Z	d�Z
d�Zy)�!CallFromThreadStopsAndWakeUpTestsNz-Nothing to wake up for without thread supportc�P��t���fd�}tj|��S)Nc�p��tjd�tj�jd�y)Ng�������?)r �sleepr
�callFromThreadrT)rs�r�wakez:CallFromThreadStopsAndWakeUpTests.testWakeUp.<locals>.wakeYs"����J�J�s�O��"�"�1�:�:�t�4r)rr
�callInThread)r"rars  @r�
testWakeUpz,CallFromThreadStopsAndWakeUpTests.testWakeUpQs&���
�J��	5�
	���T�"��rc��d|_y)NT)�stoppedr!s r�_stopCallFromThreadCallbackz=CallFromThreadStopsAndWakeUpTests._stopCallFromThreadCallbackas	����rc��tj|j|�tjd|j�yr?)r
r`�_callFromThreadCallback2rrfrs  r�_callFromThreadCallbackz9CallFromThreadStopsAndWakeUpTests._callFromThreadCallbackds.�����t�<�<�a�@����!�T�=�=�>rc��	|j|j�|jd�y#t$r|j	�YywxYwr)rDrerTr*r+rs  rrhz:CallFromThreadStopsAndWakeUpTests._callFromThreadCallback2hs?��	��O�O�D�L�L�)�

�J�J�t���	�	�
�I�I�K�	�s�/�A�
Ac�|�d|_tj�}tj|j
|�|S)z�
        Ensure that callFromThread from inside a callFromThread
        callback doesn't sit in an infinite loop and lets other
        things happen too.
        F)rerrr
r`rirs  r�testCallFromThreadStopsz9CallFromThreadStopsAndWakeUpTests.testCallFromThreadStopsqs2������N�N������t�;�;�Q�?��r)rZr[r\rr�IReactorThreadsr
rcrfrirhrlrrrr\r\PsE���&�J�&�&�w��5�5�7��
�	�
��?��	rr\c�B�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�DelayedTestsc�`�d|_d|_i|_tj�|_yr?)�finished�counter�timersrr�deferredr!s rr#zDelayedTests.setUp~s%����
����������(��
rc�b�|jj�D]}|j��yr)rs�valuesr
)r"r�s  rr�zDelayedTests.tearDown�s'�����#�#�%�	�A�
�H�H�J�	rc��|jj�}ttj��}g}|D]}||vs�|j|��|rd|_|j|dt|�z�y)Nrcz7Should have been missing no calls, instead was missing )	rsrv�listr
�getDelayedCallsrJrq�assertFalse�repr)r"�l1�l2�missingrOs     r�checkTimerszDelayedTests.checkTimers�s~��
�[�[�
�
�
!��
�'�)�)�+�
,�����	#�B���|����r�"�	#���D�M�����
��7�m�
�	
rc�>�|j|=|j�yr)rsr�r"�tags  rrTzDelayedTests.callback�s���K�K������rc�^�|j|�|jd|j�y)N�)rT�addTimerr�s  rrzDelayedTests.addCallback�s ���
�
�c���
�
�b�$�-�-�(rc�j�d|_|j|�|jjd�y)Nrc)rqrTrtr�s  r�donezDelayedTests.done�s'����
��
�
�c���
�
���t�$rc���tj|dz||j�|j|j<|xjdz
c_|j	�y)N�{�G�z�?rc)r
rrrrsr)r"�whenrTs   rr�zDelayedTests.addTimer�sJ��$+�$5�$5��4�K��4�<�<�%
����D�L�L�!�	
���������rc�v��ttd�sy�j��jd�j��jd�j
��jd�j
��j}�jd�j
��jd�j��jd�j
��j|j��j|=�j��jj�fd���jS)	Nry�#�����c�$���j�Sr)r)rr"s �rrz2DelayedTests.testGetDelayedCalls.<locals>.<lambda>�s���D�,<�,<�,>�r)�hasattrr
rr�r�rTrrrrsr
rt)r"�whichs` r�testGetDelayedCallsz DelayedTests.testGetDelayedCalls�s�����w� 1�2��	
�����
�
�b�$�)�)�$��
�
�b�$�-�-�(��
�
�b�$�-�-�(������
�
�b�$�-�-�(��
�
�b�$�*�*�+��
�
�b�$�-�-�(����E��!�!�#��K�K��������
�
�!�!�">�?��}�}�rc�����tjd�jjd���j	�j����fd�}�jj
|��jS)zM
        L{IDelayedCall.active} returns False once the call has run.
        r�Tc�F���j�j��|Sr)rz�active)�success�dcallr"s ��r�checkDeferredCallz3DelayedTests.test_active.<locals>.checkDeferredCall�s������U�\�\�^�,��Nr)r
rrtrTrDr�r)r"r�r�s` @r�test_activezDelayedTests.test_active�sY����!�!�$��
�
�(>�(>��E���������'�	�	
�
�
�!�!�"3�4��}�}�rN)rZr[r\r#r�rrTrr�r�r�r�rrrroro}s/��)��
�*�)�%�
��,
rroa�
import %(reactor)s
%(reactor)s.install()
from twisted.internet import reactor

class Foo:
    def __init__(self):
        reactor.callWhenRunning(self.start)
        self.timer = reactor.callLater(3, self.failed)
    def start(self):
        reactor.resolve('localhost').addBoth(self.done)
    def done(self, res):
        print('done', res)
        reactor.stop()
    def failed(self):
        print('failed')
        self.timer = None
        reactor.stop()
f = Foo()
reactor.run()
c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�ChildResolveProtocolc��||_yr)�onCompletion)r"r�s  r�__init__zChildResolveProtocol.__init__�s
��(��rc� �g|_g|_yr)�outputrr!s r�connectionMadez#ChildResolveProtocol.connectionMade�s�������
rc�:�|jj|�yr)r�rJ)r"�outs  r�outReceivedz ChildResolveProtocol.outReceived�s�������3�rc�:�|jj|�yr)rrJ)r"�errs  r�errReceivedz ChildResolveProtocol.errReceived�s���
�
���#�rc�v�|jj||j|jf�d|_yr)r�rTr�r)r"�reasons  r�processEndedz!ChildResolveProtocol.processEnded�s-�����"�"�F�D�K�K����#D�E� ��rN)rZr[r\r�r�r�r�r�rrrr�r��s��)�� ��!rr�z8cannot run test: reactor doesn't support IReactorProcessc��eZdZd�Zy)�ResolveTestsc�<��tjj�j��}t	|d�5}t
j}|jtd|iz�ddd�tjj�}tjjtj�|d<t�}t|�}tj |tj"dd|f|��fd�}|j%|�|S#1swY��xYw)N�wr
�
PYTHONPATH�pythonz-uc	���|\}}}dj|�}dtjjd�z}||k7r@�j	dj|j
�|dj|���yy)Nrsdone 127.0.0.1�asciiz�The child process failed to produce the desired results:
   Reason for termination was: {!r}
   Output stream was: {!r}
   Error stream was: {!r}
)�join�os�linesep�encode�fail�format�getErrorMessage)�resultr�r�r�expected_outputr"s     �r�
cbFinishedz1ResolveTests.testChildResolve.<locals>.cbFinishedsw���&,�#�V�V�U��X�X�f�%�F�/�"�*�*�2C�2C�G�2L�L�O���(��	�	�6�
�f�V�3�3�5�v�s�x�x���O��)r)r��path�abspath�mktemp�openr
r[�write�resolve_helper�environ�copy�pathsepr��sysrr��spawnProcess�
executabler)r"�
helperPath�
helperFile�reactorName�env�helperDeferred�helperProtor�s`       r�testChildResolvezResolveTests.testChildResolves�����W�W�_�_�T�[�[�]�3�
�
�*�c�
"�	H�j�!�,�,�K����^�y�+�.F�F�G�		H��j�j�o�o����J�J�O�O�C�H�H�5��L��!���*�>�:���������(�D�*�)E�s�	
�	�"	�"�"�:�.���E	H�	H�s�+D�DN)rZr[r\r�rrrr�r�s��
'rr�z&Nothing to test without thread supportc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�CallFromThreadTestsz-
    Task scheduling from threads tests.
    c�0�d|_t�|_yr?)rrrrtr!s rr#zCallFromThreadTests.setUp9s����� �
��
rc�.�tj|i|��y)z)
        Override in subclasses.
        N)r
r`)r"�args�kwargss   r�schedulezCallFromThreadTests.schedule=s��	����/��/rc�h���fd�}td�D]}�j|���jS)z�
        L{IReactorThreads.callFromThread} can be used to schedule a large
        number of calls in the reactor thread.
        c����xjdz
c_�jdk(r�jjd�yy)NrcrT�rrrtrTr!s�r�addAndMaybeFinishzVCallFromThreadTests.test_lotsOfThreadsAreScheduledCorrectly.<locals>.addAndMaybeFinishIs4����L�L�A��L��|�|�s�"��
�
�&�&�t�,�#rr)rQr�rt)r"r��is`  r�'test_lotsOfThreadsAreScheduledCorrectlyz;CallFromThreadTests.test_lotsOfThreadsAreScheduledCorrectlyCs6���	-�
�s��	-�A��M�M�+�,�	-��}�}�rc�v���g���fd�}�jj|��j�jd��j�jd��j�jd��jtj
�jjd��jS)zO
        Callbacks should be invoked in the order they were scheduled.
        c�.���j�gd��y)N)rcrrW)r,)�_�orderr"s ��rr,zECallFromThreadTests.test_threadsAreRunInScheduledOrder.<locals>.checkYs������U�I�.rrcrrWN)rtrr�rJr
r`rT)r"r,r�s` @r�"test_threadsAreRunInScheduledOrderz6CallFromThreadTests.test_threadsAreRunInScheduledOrderSs������	/�	
�
�
�!�!�%�(��
�
�e�l�l�A�&��
�
�e�l�l�A�&��
�
�e�l�l�A�&��
�
�g�,�,�d�m�m�.D�.D�d�K��}�}�rc����fd�}�j|��j�jd��jS)zU
        Scheduled tasks should not be run until the reactor starts running.
        c�J��d�_�jjd�y)NrcTr�r!s�r�incAndFinishzUCallFromThreadTests.test_scheduledThreadsNotRunUntilReactorRuns.<locals>.incAndFinishis����D�L��M�M�"�"�4�(rr)r�r,rrrt)r"r�s` r�+test_scheduledThreadsNotRunUntilReactorRunsz?CallFromThreadTests.test_scheduledThreadsNotRunUntilReactorRunsds6���
	)�	
�
�
�l�#�	
������q�)��}�}�rN)	rZr[r\r�r#r�r�r�r�rrrr�r�0s ��
�#�0�� �"rr�c��eZdZdZy)�
MyProtocolz
    Sample protocol.
    N)rZr[r\r�rrrr�r�us��rr�c��eZdZdZeZy)�	MyFactoryz
    Sample factory.
    N)rZr[r\r�r�r	rrrr�r�{s����Hrr�c��eZdZd�Zy)�
ProtocolTestsc��t�}|jd�}|j|j|�|j	||j
�yr)r��
buildProtocolr,�factory�assertIsInstancer	)r"r�r	s   r�testFactoryzProtocolTests.testFactory�sE���+���(�(��.������)�)�7�3����h��(8�(8�9rN)rZr[r\r�rrrr�r��s��:rr�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�
DummyProducera�
    Very uninteresting producer implementation used by tests to ensure the
    right methods are called by the consumer with which it is registered.

    @type events: C{list} of C{str}
    @ivar events: The producer/consumer related events which have happened to
    this producer.  Strings in this list may be C{'resume'}, C{'stop'}, or
    C{'pause'}.  Elements are added as they occur.
    c��g|_yrr�r!s rr�zDummyProducer.__init__�s	����rc�:�|jjd�y)N�resume�rMrJr!s r�resumeProducingzDummyProducer.resumeProducing�s�������8�$rc�:�|jjd�y)N�stopr�r!s r�
stopProducingzDummyProducer.stopProducing�s�������6�"rc�:�|jjd�y)N�pauser�r!s r�pauseProducingzDummyProducer.pauseProducing�s�������7�#rN)rZr[r\r�r�r�r�rrrrr�r��s����%�#�$rr�c�(�eZdZdZdZdZd�Zd�ZeZy)�SillyDescriptora
    A descriptor whose data buffer gets filled very fast.

    Useful for testing FileDescriptor's IConsumer interface, since
    the data buffer fills as soon as at least four characters are
    written to it, and gets emptied in a single doWrite() cycle.
    rWTc��t|�S)z(
        Always write all data.
        )rg)r"�datas  r�
writeSomeDatazSillyDescriptor.writeSomeData�s���4�y�rc��y)z1
        Do nothing: bypass the reactor.
        Nrr!s r�startWritingzSillyDescriptor.startWriting�rrN)	rZr[r\r��
bufferSize�	connectedrr�stopWritingrrrrr�s$����J��I���
�Krrc�,��eZdZdZ�fd�Z�fd�Z�xZS)�ReentrantProducera�
    Similar to L{DummyProducer}, but with a resumeProducing method which calls
    back into an L{IConsumer} method of the consumer against which it is
    registered.

    @ivar consumer: The consumer with which this producer has been or will
    be registered.

    @ivar methodName: The name of the method to call on the consumer inside
    C{resumeProducing}.

    @ivar methodArgs: The arguments to pass to the consumer method invoked in
    C{resumeProducing}.
    c�L��t�|��||_||_||_yr)�superr��consumer�
methodName�
methodArgs)r"rrr�	__class__s    �rr�zReentrantProducer.__init__�s#���
���� ��
�$���$��rc�|��t�|��t|j|j�|j
�yr)rr��getattrrrr)r"rs �rr�z!ReentrantProducer.resumeProducing�s+���
���!�/���
�
�t���/����Ar)rZr[r\r�r�r��
__classcell__)rs@rrr�s���
�%�B�Brrc�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�
ProducerTestsz<
    Test abstract.FileDescriptor's consumer interface.
    c��tj�}d|_t�}|j	|d�|j|jdg�|jt|jt�d�y)z�
        Verify that registering a non-streaming producer invokes its
        resumeProducing() method and that you can only register one producer
        at a time.
        rcrr�N)	r�FileDescriptorr	r��registerProducerr,rMr&�RuntimeError�r"�fd�dps   r�test_doubleProducerz!ProducerTests.test_doubleProducer�sb���
$�
$�
&�����
�_��
���B��"�������X�J�/����,��(;�(;�]�_�a�Prc��tj�}d|_t�}|j	|d�|j|jdg�y)z�
        Verify that registering a producer when the connection has already
        been closed invokes its stopProducing() method.
        rcrr�N)rr�disconnectedr�rr,rMrs   r�test_unconnectedFileDescriptorz,ProducerTests.test_unconnectedFileDescriptor�sF��
�
$�
$�
&�����
�_��
���B��"�������V�H�-rc�6�t�}t�}|j|d��|j|jdg�|jdd�=|dk(r|jgd��n|j
d�|j|jg�y)z�
        Pull consumers don't get their C{pauseProducing} method called if the
        descriptor buffer fills up.

        @param _methodName: Either 'write', or 'writeSequence', indicating
            which transport method to write data to.
        F��	streamingr�N�
writeSequence)�1�2�3�4s1234)rr�rr,rMr&r�)r"r�
descriptor�producers    r�_dontPausePullConsumerTestz(ProducerTests._dontPausePullConsumerTest�s���%�&�
� �?���#�#�H��#�>�������8�*�5��O�O�A����(��$�$�%=�>����W�%�������"�-rc�$�|jd�S)z�
        Verify that FileDescriptor does not call producer.pauseProducing() on a
        non-streaming pull producer in response to a L{IConsumer.write} call
        which results in a full write buffer. Issue #2286.
        r��r-r!s r�!test_dontPausePullConsumerOnWritez/ProducerTests.test_dontPausePullConsumerOnWrites���.�.�w�7�7rc�$�|jd�S)a@
        Like L{test_dontPausePullConsumerOnWrite}, but for a call to
        C{writeSequence} rather than L{IConsumer.write}.

        C{writeSequence} is not part of L{IConsumer}, but
        L{abstract.FileDescriptor} has supported consumery behavior in response
        to calls to L{writeSequence} forever.
        r&r/r!s r�)test_dontPausePullConsumerOnWriteSequencez7ProducerTests.test_dontPausePullConsumerOnWriteSequences���.�.��?�?rc���t�}|dk(rgd�}nd}t|||�}|j|d��t||�|�|j	|j
dg�|j
dd�=|j
�|j	|j
ddg�|j
dd�=|j
�|j	|j
ddg�y)Nr&)�s�psamsspamTr$r�r�)rrrrr,rM�doWrite)r"rr+rr,s     r�_reentrantStreamingProducerTestz-ProducerTests._reentrantStreamingProducerTests���$�&�
���(�&�D��D�$�Z��T�B���#�#�H��#�=�	(��
�J�'��-�	
������7�)�4��O�O�A��	����������8�W�*=�>��O�O�A��	����������8�W�*=�>rc�$�|jd�S)z�
        Verify that FileDescriptor tracks producer's paused state correctly.
        Issue #811, fixed in revision r12857.
        r��r7r!s r�)test_reentrantStreamingProducerUsingWritez7ProducerTests.test_reentrantStreamingProducerUsingWrite?s��
�3�3�G�<�<rc�$�|jd�S)a/
        Like L{test_reentrantStreamingProducerUsingWrite}, but for calls to
        C{writeSequence}.

        C{writeSequence} is B{not} part of L{IConsumer}, however
        C{abstract.FileDescriptor} has supported consumery behavior in response
        to calls to C{writeSequence} forever.
        r&r9r!s r�1test_reentrantStreamingProducerUsingWriteSequencez?ProducerTests.test_reentrantStreamingProducerUsingWriteSequenceFs���3�3�O�D�DrN)rZr[r\r�rr"r-r0r2r7r:r<rrrrr�s3���Q�	.�.�.8�	@�?�@=�	Errc���eZdZeej
ed�d�d��Zeejed�d�d��Z	eejed�d�eed�efd���Zy)	�PortStringificationTestsNzIReactorTCP is neededc��tjdtj��}|j	�j
}|j
t|�jt|��dd||fz�|j�S�Nr����%d not found in %s)
r
�	listenTCPr	�
ServerFactory�getHost�portr"rM�find�
stopListening�r"�p�portNos   r�testTCPz PortStringificationTests.testTCPSsm�����a��!7�!7�!9�:������!�!�������F�K�K��F��$�b�*>�&�!��*L�	
���� � rzIReactorUDP is neededc��tjdtj��}|j	�j
}|j
t|�jt|��dd||fz�|j�Sr@)
r
�	listenUDPr	�DatagramProtocolrErFr"rMrGrHrIs   r�testUDPz PortStringificationTests.testUDP\sm�����a��!:�!:�!<�=������!�!�������F�K�K��F��$�b�*>�&�!��*L�	
���� � rzIReactorSSL is neededzSSL support is missingc�n�tjtd�}tjdtj�|j||��}|j�j}|jt|�jt|��dd||fz�|j�S)Nz
server.pemrrArB)r�sibpathrwr
�	listenSSLr	rD�DefaultOpenSSLContextFactoryrErFr"rMrGrH)r"r�pemrJrKs     r�testSSLz PortStringificationTests.testSSLes����l�l�8�\�2�����
�x�%�%�'��)I�)I�#�s�)S�
������!�!�������F�K�K��F��$�b�*>�&�!��*L�	
���� � r)
rZr[r\rr�IReactorTCPr
rL�IReactorUDPrP�IReactorSSLrrVrrrr>r>Rs����&�
�&�&�w��5�5�7N�O�!�P�!��&�
�&�&�w��5�5�7N�O�!�P�!��&�
�&�&�w��5�5�7N�O���G�-�.��	!�/�P�	!rr>c��eZdZd�Zy)�ConnectorReprTestsc��tddt�dt��}d}|t|�|j�fz}|j	t|�|�y)N�	localhosti�rzA<twisted.internet.tcp.Connector instance at 0x%x disconnected %s>)r
r�id�getDestinationr,r{)r"�c�expects   r�
test_tcp_reprz ConnectorReprTests.test_tcp_reprtsM���k�3���!�V�X�>��W���2�a�5�!�"2�"2�"4�5�5������a��&�)rN)rZr[r\rbrrrr[r[ss��*rr[)3r�r�r�r �unittestr�twisted.internetrrrrrr	r
�twisted.internet.deferrr�twisted.internet.tcpr
�twisted.pythonr�twisted.trial.unittestrr�_ssl�ImportError�	supportedrr�r�r\ror��ProcessProtocolr��IReactorProcessr�rmr��Protocolr��Factoryr�r�r�rrrrr>r[rrr�<module>rps����

�
���X�X�X�5�*��+��,��C��s�}�}�
�C�k7�8�k7�\	{
�x�{
�|	B+��B+�J*��*�ZW�8�W�t��.!�8�3�3�!�&�"�
�"�"�7�D�1�1�>��(�8�(�	�(�V�"�
�"�"�7�D�1�1�,��>�(�>�	�>�B��"�"���� � ��:�H�:�$�$�0�h�-�-��4B�
�B�6wE�H�wE�t!�x�!�B*��*��{*��
�C��s�E;�;F�F

Zerion Mini Shell 1.0