%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�����dZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZddlmZddlmZddlmZddlmZmZmZddlmZdd	lmZmZmZdd
l m!Z!m"Z"ddl#m$Z$ddl%m&Z&e
d
�Z'Gd�d�Z(Gd�de)�Z*Gd�de*�Z+Gd�de*�Z,Gd�de,�Z-Gd�de,�Z.Gd�de,�Z/Gd�de*�Z0Gd�d�Z1d Z2d!egdfd"efd#�Z3e
d$�Z4Gd%�d&�Z5Gd'�d(�Z6e6�Z7d)ee'd"eee'fd*�Z8d)ee'd"e5fd+�Z9ee�Gd,�d-��Z:	d:d.ed/e;d!eed0e'fd1e<d2e<d"ee'fd3�Z=		d;d4ed0eee'ed5e<e'fffd6ee<d7eed"e
fd8�Z>gd9�Z?y)<z)
Scheduling utility methods and classes.
�N)�Callable�	Coroutine�Iterable�Iterator�List�NoReturn�Optional�Sequence�TypeVar�Union�cast)�implementer)�Version)�DelayedCall)�Deferred�ensureDeferred�
maybeDeferred)�ReactorNotRunning)�IDelayedCall�IReactorCore�IReactorTime)�log�reflect)�_getDeprecationWarningString)�Failure�_Tc�N�eZdZUdZdZeeed<dZdZ	ee
ded<dZeeed<dZ
dZeeed<dZeeed<d	ed
efdeded
dfd�Zed
ee
dfd��Zedeegefd
dfd��Zded
efd�Zddeded
e
dfd�Zdd�Zdd�Zdd�Zded
dfd�Zd
efd�Z y)�LoopingCalla�Call a function repeatedly.

    If C{f} returns a deferred, rescheduling will not take place until the
    deferred has fired. The result value is ignored.

    @ivar f: The function to call.
    @ivar a: A tuple of arguments to pass the function.
    @ivar kw: A dictionary of keyword arguments to pass to the function.
    @ivar clock: A provider of
        L{twisted.internet.interfaces.IReactorTime}.  The default is
        L{twisted.internet.reactor}. Feel free to set this to
        something else, but it probably ought to be set *before*
        calling L{start}.

    @ivar running: A flag which is C{True} while C{f} is scheduled to be called
        (or is currently being called). It is set to C{True} when L{start} is
        called and set to C{False} when L{stop} is called or if C{f} raises an
        exception. In either case, it will be C{False} by the time the
        C{Deferred} returned by L{start} fires its callback or errback.

    @ivar _realLastTime: When counting skips, the time at which the skip
        counter was last invoked.

    @ivar _runAtStart: A flag indicating whether the 'now' argument was passed
        to L{LoopingCall.start}.
    N�callF�	_deferred�interval�	starttime�
_realLastTime�f.�a�kw�returnc�d�||_||_||_ddlm}tt|�|_y�Nr��reactor)r$r%r&�twisted.internetr+r
r�clock)�selfr$r%r&r+s     �7/usr/lib/python3/dist-packages/twisted/internet/task.py�__init__zLoopingCall.__init__Ns(�����������,��,��0��
�c	��tdtdddd�d��}tj|td��|j
S)	z�
        DEPRECATED. L{Deferred} fired when loop stops or fails.

        Use the L{Deferred} returned by L{LoopingCall.start}.
        z*twisted.internet.task.LoopingCall.deferred�Twisted�rz the deferred returned by start())�replacement�)�
stacklevel)rr�warnings�warn�DeprecationWarningr )r.�
warningStrings  r/�deferredzLoopingCall.deferredVs?��5�8��I�r�1�a�(�:�
�
�
	�
�
�m�%7�A�F��~�~�r1�
countCallablec�4���dtf��fd�}||���S)a�
        An alternate constructor for L{LoopingCall} that makes available the
        number of calls which should have occurred since it was last invoked.

        Note that this number is an C{int} value; It represents the discrete
        number of calls that should have been made.  For example, if you are
        using a looping call to display an animation with discrete frames, this
        number would be the number of frames to advance.

        The count is normally 1, but can be higher. For example, if the reactor
        is blocked and takes too long to invoke the L{LoopingCall}, a Deferred
        returned from a previous call is not fired before an interval has
        elapsed, or if the callable itself blocks for longer than an interval,
        preventing I{itself} from being called.

        When running with an interval of 0, count will be always 1.

        @param countCallable: A callable that will be invoked each time the
            resulting LoopingCall is run, with an integer specifying the number
            of calls that should have been invoked.

        @return: An instance of L{LoopingCall} with call counting enabled,
            which provides the count as the first positional argument.

        @since: 9.0
        r'c����jj�}�jdk(r|�_�d�S�j}|�M�j�Jd���j}�j
r"�j�Jd��|�jz}�j
|�}�j
|�}||z
}|dkDr|�_�|�Sy)Nr�z(LoopingCall called before it was startedz&Looping call called with None interval)r-�secondsr!r#r"�_runAtStart�_intervalOf)�now�lastTime�lastInterval�thisInterval�countr=r.s     ��r/�counterz&LoopingCall.withCount.<locals>.counter�s�����*�*�$�$�&�C��}�}��!�%(��"�$�Q�'�'��)�)�H����N�N�.�>�=�>�.��>�>���#�#��
�
�1�@�?�@�1���
�
�-�H��+�+�H�5�L��+�+�C�0�L� �<�/�E��q�y�%(��"�$�U�+�+�r1)�object)�clsr=rIr.s ` @r/�	withCountzLoopingCall.withCountfs���:	��	�6�7�|���r1�tc��|j�J�|j�J�||jz
}t||jz�}|S)aD
        Determine the number of intervals passed as of the given point in
        time.

        @param t: The specified time (from the start of the L{LoopingCall}) to
            be measured in intervals

        @return: The C{int} number of intervals which have passed as of the
            given point in time.
        )r"r!�int)r.rM�elapsedTime�intervalNums    r/rCzLoopingCall._intervalOf�sK���~�~�)�)�)��}�}�(�(�(��$�.�.�(���+��
�
�5�6���r1rDc�"�|jrJd��|dkrtd��d|_t�x}|_|jj�|_||_||_|r	|�|S|j|j�|S)a�
        Start running function every interval seconds.

        @param interval: The number of seconds between calls.  May be
        less than one.  Precision will depend on the underlying
        platform, the available hardware, and the load on the system.

        @param now: If True, run this call right now.  Otherwise, wait
        until the interval has elapsed before beginning.

        @return: A Deferred whose callback will be invoked with
        C{self} when C{self.stop} is called, or whose errback will be
        invoked when the function raises an exception or returned a
        deferred that has its errback invoked.
        z.Tried to start an already running LoopingCall.rzinterval must be >= 0T)
�running�
ValueErrorrr r-rAr"r!rB�
_scheduleFrom)r.r!rDr<s    r/�startzLoopingCall.start�s��� �<�<�T�!T�T���a�<��4�5�5����%-�J�.��4�>����+�+�-��� ��
������F���
���t�~�~�.��r1c���|jsJd��d|_|j�K|jj�d|_|jdc}|_|�J�|j	|�yy)zStop running function.z1Tried to stop a LoopingCall that was not running.FN)rSr�cancelr �callback�r.�ds  r/�stopzLoopingCall.stop�si���|�|�S�S�S�|�����9�9� ��I�I�����D�I� $�����A�t�~��=� �=�
�J�J�t��!r1c��|jsJd��|j�\|jj�d|_|jj	�|_|j
|j
�yy)zT
        Skip the next iteration and reset the timer.

        @since: 11.1
        z2Tried to reset a LoopingCall that was not running.N)rSrrXr-rAr"rU�r.s r/�resetzLoopingCall.reset�sb���|�|�T�T�T�|��9�9� ��I�I�����D�I�!�Z�Z�/�/�1�D�N����t�~�~�.�	!r1c����dtddf�fd�}dtddf�fd�}d�_t�jg�j
��i�j��}|j|�|j|�y)N�resultr'c�����jr*�j�jj��y�jdc}�_|�J�|j��y�N)rSrUr-rAr rY)rar[r.s  �r/�cbz LoopingCall.__call__.<locals>.cb�sM����|�|��"�"�4�:�:�#5�#5�#7�8�$(�N�N�D�!��4�>��}�$�}��
�
�4� r1�failurec�f��d�_�jdc}�_|�J�|j|�y)NF)rSr �errback)rer[r.s  �r/�ebz LoopingCall.__call__.<locals>.eb�s2��� �D�L� $�����A�t�~��=� �=�
�I�I�g�r1)	rJrrrr$r%r&�addCallback�
addErrback)r.rdrhr[s`   r/�__call__zLoopingCall.__call__�sj���	!�v�	!�$�	!�	��	�D�	���	��$�&�&�5�4�6�6�5�T�W�W�5��	�
�
�b��	���R�r1�whenc�n���dtf��fd�}�jj|����_y)z�
        Schedule the next iteration of this looping call.

        @param when: The present time from whence the call is scheduled.
        r'c�����jdk(ry�j�J���jz
}�j�J��j|�jzz
}��|zk(r�jS|S)Nr)r!r")�
runningFor�untilNextIntervalr.rls  ��r/�howLongz*LoopingCall._scheduleFrom.<locals>.howLongs�����}�}��!���>�>�-�-�-�����.�J��=�=�,�,�,� $�
�
��d�m�m�1K� L���t�/�/�/��}�}�$�%�$r1N)�floatr-�	callLaterr)r.rlrqs`` r/rUzLoopingCall._scheduleFrom�s+���	%��	%�:�J�J�(�(���D�9��	r1c��t|jdd�}|�9t|jdd�}|� t|jdd�}|�|�d|��}|�tj|j�}dj	|j
|tj|j�tj|j��S)N�__qualname__�__name__�im_class�.z LoopingCall<{!r}>({}, *{}, **{}))�getattrr$r�	safe_repr�formatr!r%r&)r.�func�imClasss   r/�__repr__zLoopingCall.__repr__%s����t�v�v�~�t�4���<��4�6�6�:�t�4�D���!�$�&�&�*�d�;���&�%�Y�a��v�.�D��<��$�$�T�V�V�,�D�1�8�8��M�M�����d�f�f�%����d�g�g�&�	
�	
r1)T�r'N)!rv�
__module__ru�__doc__rr	r�__annotations__rSr rr!rrrBr"r#rrJr0�propertyr<�classmethodrOrLrC�boolrVr\r_rkrU�strr~�r1r/rr*s?���6$(�D�(�<�
 �'��G�37�I�x���/�0�7� $�H�h�u�o�$��K�!%�I�x���%�%)�M�8�E�?�)�1�(�3��;�/�1�V�1�6�1�d�1��
�(�8�M�#:�;�
��
��9�h��u�f�}�&=�9�-�9��9�v�U��s��"�e��$��(�=�:Q��@	�/��($:�%�$:�D�$:�L
�#�
r1rc��eZdZdZy)�SchedulerErrorz�
    The operation could not be completed because the scheduler or one of its
    tasks was in an invalid state.  This exception should not be raised
    directly, but is a superclass of various scheduler-state-related
    exceptions.
    N�rvr�rur�r�r1r/r�r�:s��r1r�c��eZdZdZy)�SchedulerStoppedzt
    The operation could not complete because the scheduler was stopped in
    progress or was already stopped.
    Nr�r�r1r/r�r�C���r1r�c��eZdZdZy)�TaskFinishedz�
    The operation could not complete because the task was already completed,
    stopped, encountered an error or otherwise permanently stopped running.
    Nr�r�r1r/r�r�Jr�r1r�c��eZdZdZy)�TaskDonezR
    The operation could not complete because the task was already completed.
    Nr�r�r1r/r�r�Q���r1r�c��eZdZdZy)�TaskStoppedzH
    The operation could not complete because the task was stopped.
    Nr�r�r1r/r�r�Wr�r1r�c��eZdZdZy)�
TaskFailedz]
    The operation could not complete because the task died with an unhandled
    error.
    Nr�r�r1r/r�r�]r�r1r�c��eZdZdZy)�	NotPausedz^
    This exception is raised when a task is resumed which was not previously
    paused.
    Nr�r�r1r/r�r�dr�r1r�c�$�eZdZdZdd�Zdefd�Zy)�_Timerg{�G�z�?r'Nc�P�tj�|jz|_yrc)�time�	MAX_SLICE�endr^s r/r0z_Timer.__init__ns���9�9�;����/��r1c�D�tj�|jk\Src)r�r�r^s r/rkz_Timer.__call__qs���y�y�{�d�h�h�&�&r1r)rvr�rur�r0r�rkr�r1r/r�r�ks���I�0�'�$�'r1r�g:�0�yE>�callabler'c�V�ddlm}tt|�j	t
|�Sr))r,r+r
rrs�_EPSILON)r�r+s  r/�_defaultSchedulerr�xs��(���g�&�0�0��8�D�Dr1�_TaskResultTc��eZdZdZdeeddddfd�Zdeeefd�Zdd	�Z	dd
�Z
dedeeee
fddfd
�Zdd�Zdd�Zdd�Zy)�CooperativeTaskaU
    A L{CooperativeTask} is a task object inside a L{Cooperator}, which can be
    paused, resumed, and stopped.  It can also have its completion (or
    termination) monitored.

    @see: L{Cooperator.cooperate}

    @ivar _iterator: the iterator to iterate when this L{CooperativeTask} is
        asked to do work.

    @ivar _cooperator: the L{Cooperator} that this L{CooperativeTask}
        participates in, which is used to re-insert it upon resume.

    @ivar _deferreds: the list of L{Deferred}s to fire when this task
        completes, fails, or finishes.

    @ivar _pauseCount: the number of times that this L{CooperativeTask} has
        been paused; if 0, it is running.

    @ivar _completionState: The completion-state of this L{CooperativeTask}.
        L{None} if the task is not yet completed, an instance of L{TaskStopped}
        if C{stop} was called to stop this task early, of L{TaskFailed} if the
        application code in the iterator raised an exception which caused it to
        terminate, and of L{TaskDone} if it terminated normally via raising
        C{StopIteration}.
    �iterator�
cooperator�
Cooperatorr'Nc�z�||_||_g|_d|_d|_d|_|j
|�y)zq
        A private constructor: to create a new L{CooperativeTask}, see
        L{Cooperator.cooperate}.
        rN)�	_iterator�_cooperator�
_deferreds�_pauseCount�_completionState�_completionResult�_addTask)r.r�r�s   r/r0zCooperativeTask.__init__�s@��"���%���BD������:>���SW������D�!r1c��t�}|j�|jj|�|S|j�J�|j|j�|S)a�
        Get a L{Deferred} notification of when this task is complete.

        @return: a L{Deferred} that fires with the C{iterator} that this
            L{CooperativeTask} was created with when the iterator has been
            exhausted (i.e. its C{next} method has raised C{StopIteration}), or
            fails with the exception raised by C{next} if it raises some other
            exception.

        @rtype: L{Deferred}
        )rr�r��appendr�rYrZs  r/�whenDonezCooperativeTask.whenDone�s[��/7�j��� � �(��O�O�"�"�1�%����)�)�5�5�5�
�J�J�t�-�-�.��r1c��|j�|xjdz
c_|jdk(r|jj|�yy)a@
        Pause this L{CooperativeTask}.  Stop doing work until
        L{CooperativeTask.resume} is called.  If C{pause} is called more than
        once, C{resume} must be called an equal number of times to resume this
        task.

        @raise TaskFinished: if this task has already finished or completed.
        r@N)�_checkFinishr�r��_removeTaskr^s r/�pausezCooperativeTask.pause�sH��	
�������A������q� ����(�(��.�!r1c���|jdk(r
t��|xjdzc_|jdk(r)|j�|jj	|�yyy)z�
        Resume processing of a paused L{CooperativeTask}.

        @raise NotPaused: if this L{CooperativeTask} is not paused.
        rr@N)r�r�r�r�r�r^s r/�resumezCooperativeTask.resume�sa�����q� ��+�����A������q� �T�%:�%:�%B����%�%�d�+�&C� r1�completionState�deferredResultc��||_||_|js|jj	|�|j
D]}|j
|��y)a
        @param completionState: a L{SchedulerError} exception or a subclass
            thereof, indicating what exception should be raised when subsequent
            operations are performed.

        @param deferredResult: the result to fire all the deferreds with.
        N)r�r�r�r�r�r�rY)r.r�r�r[s    r/�
_completeWithzCooperativeTask._completeWith�sR��!0���!/���������(�(��.����	'�A�
�J�J�~�&�	'r1c�z�|j�|jt�tt���y)z�
        Stop further processing of this task.

        @raise TaskFinished: if this L{CooperativeTask} has previously
            completed, via C{stop}, completion, or failure.
        N)r�r�r�rr^s r/r\zCooperativeTask.stop�s)��	
�������;�=�'�+�-�*@�Ar1c�4�|j�|j�y)zk
        If this task has been stopped, raise the appropriate subclass of
        L{TaskFinished}.
        N)r�r^s r/r�zCooperativeTask._checkFinish�s!��
� � �,��'�'�'�-r1c�x��	t�j�}t|t�r4�j	�dt
ddf�fd�}|j
�fd�|�yy#t$r'�jt��j�Yyt$r%�jt�t��YywxYw)z�
        Perform one unit of work for this task, retrieving one item from its
        iterator, stopping if there are no further items in the iterator, and
        pausing if the result was a L{Deferred}.
        rer'Nc�:���jt�|�yrc)r�r�)rer.s �r/�	failLaterz/CooperativeTask._oneWorkUnit.<locals>.failLaters����&�&�z�|�W�=r1c�$���j�Src)r�)rar.s �r/�<lambda>z.CooperativeTask._oneWorkUnit.<locals>.<lambda>s
���4�;�;�=�r1)�nextr��
isinstancerr�r�addCallbacks�
StopIterationr�r��
BaseExceptionr�)r.rar�s`  r/�_oneWorkUnitzCooperativeTask._oneWorkUnits����
	M��$�.�.�)�F��&�(�+��
�
��>�w�>�4�>��#�#�$@�)�L�
,���	;����x�z�4�>�>�:��	8����z�|�W�Y�7�	8�s�A�-B9�*B9�8B9r)rvr�rur�rr�r0rr�r�r�r�rrr�r\r�r�r�r1r/r�r��s����6
"� ��.�
"�<H�
"�	
�
"��(�8�L�#9�:��(/�
,�'�'�'��h�|�4�g�=�>�'�
�	'�6B�(�Mr1r�c	��eZdZdZeedfdegegeffdeegdfgefdefd�Z		dde
ed	ee
e
ed
e
e
efd�Zde
ed
efd�Zd
ed
dfd�Zd
ed
dfd�Zd
eefd�Zdd�ZdZdd�Zdd�Zdd�Zed
efd��Zy)r�a�
    Cooperative task scheduler.

    A cooperative task is an iterator where each iteration represents an
    atomic unit of work.  When the iterator yields, it allows the
    L{Cooperator} to decide which of its tasks to execute next.  If the
    iterator yields a L{Deferred} then work will pause until the
    L{Deferred} fires and completes its callback chain.

    When a L{Cooperator} has more than one task, it distributes work between
    all tasks.

    There are two ways to add tasks to a L{Cooperator}, L{cooperate} and
    L{coiterate}.  L{cooperate} is the more useful of the two, as it returns a
    L{CooperativeTask}, which can be L{paused<CooperativeTask.pause>},
    L{resumed<CooperativeTask.resume>} and L{waited
    on<CooperativeTask.whenDone>}.  L{coiterate} has the same effect, but
    returns only a L{Deferred} that fires when the task is done.

    L{Cooperator} can be used for many things, including but not limited to:

      - running one or more computationally intensive tasks without blocking
      - limiting parallelism by running a subset of the total tasks
        simultaneously
      - doing one thing, waiting for a L{Deferred} to fire,
        doing the next thing, repeat (i.e. serializing a sequence of
        asynchronous tasks)

    Multiple L{Cooperator}s do not cooperate with each other, so for most
    cases you should use the L{global cooperator<task.cooperate>}.
    T�terminationPredicateFactory�	schedulerN�startedc�x�g|_td�|_||_||_d|_d|_||_y)aA
        Create a scheduler-like object to which iterators may be added.

        @param terminationPredicateFactory: A no-argument callable which will
        be invoked at the beginning of each step and should return a
        no-argument callable which will return True when the step should be
        terminated.  The default factory is time-based and allows iterators to
        run for 1/100th of a second at a time.

        @param scheduler: A one-argument callable which takes a no-argument
        callable and should invoke it at some future point.  This will be used
        to schedule each step of this Cooperator.

        @param started: A boolean which indicates whether iterators should be
        stepped as soon as they are added, or if they will be queued up until
        L{Cooperator.start} is called.
        r�NF)�_tasks�iter�
_metarator�_terminationPredicateFactory�
_scheduler�_delayedCall�_stopped�_started)r.r�r�r�s    r/r0zCooperator.__init__>s;��..0���59�"�X���,G��)�#���48�����
���
r1r��doneDeferredr'c�t�|�
t�}t||�j�}|j|�|S)a�
        Add an iterator to the list of iterators this L{Cooperator} is
        currently running.

        Equivalent to L{cooperate}, but returns a L{Deferred} that will
        be fired when the task is done.

        @param doneDeferred: If specified, this will be the Deferred used as
            the completion deferred.  It is suggested that you use the default,
            which creates a new Deferred for you.

        @return: a Deferred that will fire when the iterator finishes.
        )rr�r��
chainDeferred)r.r�r�r�s    r/�	coiteratezCooperator.coiterate]s@��$��#�:�L�5D��d�6
�
�(�*�	�	���|�,��r1c��t||�S)a	
        Start running the given iterator as a long-running cooperative task, by
        calling next() on it as a periodic timed event.

        @param iterator: the iterator to invoke.

        @return: a L{CooperativeTask} object representing this task.
        )r�)r.r�s  r/�	cooperatezCooperator.cooperatews���x��.�.r1�taskc��|jrG|jj|�|jt	�tt	���y|jj|�|j
�y)zH
        Add a L{CooperativeTask} object to this L{Cooperator}.
        N)r�r�r�r�r�r�_reschedule�r.r�s  r/r�zCooperator._addTask�sX���=�=��K�K���t�$����/�1�7�;K�;M�3N�O��K�K���t�$����r1c��|jj|�|js/|jr"|jj�d|_yyy)zF
        Remove a L{CooperativeTask} from this L{Cooperator}.
        N)r��remover�rXr�s  r/r�zCooperator._removeTask�sF��	
�����4� ��{�{�t�0�0����$�$�&� $�D�� 1�{r1c#��K�|j�}|jrF|jD]}|��|�s�yt|j�|_|jr�Eyy�w)z�
        Yield all L{CooperativeTask} objects in a loop as long as this
        L{Cooperator}'s termination condition has not been met.
        N)r�r�r�r�)r.�
terminatorrMs   r/�_tasksWhileNotStoppedz Cooperator._tasksWhileNotStopped�sX����
�6�6�8�
��k�k��_�_�
�����<��
�#�4�;�;�/�D�O��k�k�s�7A&�)A&�$A&c�|�d|_|j�D]}|j��|j�y)z)
        Run one scheduler tick.
        N)r�r�r�r��r.�taskObjs  r/�_tickzCooperator._tick�s<��!����1�1�3�	#�G�� � �"�	#����r1Fc��|jsd|_y|j�.|jr!|j	|j
�|_yyy�NT)r��_mustScheduleOnStartr�r�r�r�r^s r/r�zCooperator._reschedule�sC���}�}�(,�D�%�����$���� $����
�
� ;�D��*5�$r1c�^�d|_d|_|jr|`|j�yy)z)
        Begin scheduling steps.
        FTN)r�r�r�r�r^s r/rVzCooperator.start�s2����
���
��$�$��)�����%r1c���d|_|jD]-}|jt�t	t����/g|_|j
�"|j
j
�d|_yy)z�
        Stop scheduling steps.  Errback the completion Deferreds of all
        iterators which have been added and forget about them.
        TN)r�r�r�r�rr�rXr�s  r/r\zCooperator.stop�so��
��
��{�{�	S�G��!�!�"2�"4�g�>N�>P�6Q�R�	S�������(����$�$�&� $�D��)r1c�8�|jxr
|jS)z�
        Is this L{Cooperator} is currently running?

        @return: C{True} if the L{Cooperator} is running, C{False} otherwise.
        @rtype: C{bool}
        )r�r�r^s r/rSzCooperator.running�s���}�}�2�T�]�]�!2�2r1rcr)rvr�rur�r�r�rr�rr0rr�r	rr�r�r�r�r�rr�r�r�r�rVr\r�rSr�r1r/r�r�s,���DIO�BS��	 �%-�b�(�2�t�8�2D�.D�%E� ��X�b�$�h�/�0�,�>�?� ��	 �DDH���<�(���x���(>�?�@��
�(�<�(�	)�	�4	/�(�<�"8�	/�_�	/�
�_�
��
�%��%�D�%�0�x��'@�0��!��<��%��3��3��3r1r�r�c�,�tj|�S)a%
    Cooperatively iterate over the given iterator, dividing runtime between it
    and all other iterators which have been passed to this function and not yet
    exhausted.

    @param iterator: the iterator to invoke.

    @return: a Deferred that will fire when the iterator finishes.
    )�_theCooperatorr��r�s r/r�r��s���#�#�H�-�-r1c�,�tj|�S)aS
    Start running the given iterator as a long-running cooperative task, by
    calling next() on it as a periodic timed event.

    This is very useful if you have computationally expensive tasks that you
    want to run without blocking the reactor.  Just break each task up so that
    it yields frequently, pass it in here and the global L{Cooperator} will
    make sure work is distributed between them without blocking longer than a
    single iteration of a single task.

    @param iterator: the iterator to invoke.

    @return: a L{CooperativeTask} object representing this task.
    )r�r�r�s r/r�r��s���#�#�H�-�-r1c
��eZdZdZdZdd�Zdefd�Zdd�Zded	e	d
e
fde
de
def
d
�Zde
efd�Zdeddfd�Zdeeddfd�Zy)�Clockz�
    Provide a deterministic, easily-controlled implementation of
    L{IReactorTime.callLater}.  This is commonly useful for writing
    deterministic unit tests for code which schedules events using this API.
    gr'Nc��g|_yrc��callsr^s r/r0zClock.__init__s	��(*��
r1c��|jS)a
        Pretend to be time.time().  This is used internally when an operation
        such as L{IDelayedCall.reset} needs to determine a time value
        relative to the current time.

        @return: The time which should be considered the current time.
        )�rightNowr^s r/rAz
Clock.secondss���}�}�r1c�>�|jjd���y)zR
        Sort the pending calls according to the time they are scheduled.
        c�"�|j�Src)�getTime)r%s r/r�z"Clock._sortCalls.<locals>.<lambda>s��a�i�i�k�r1)�keyN)r��sortr^s r/�
_sortCallszClock._sortCallss��	
�
�
���1��2r1�delayr�.�argsr&c	���t|j�|z||||jjd�|j�}|jj	|�|j�|S)zL
        See L{twisted.internet.interfaces.IReactorTime.callLater}.
        c��yrcr�)�cs r/r�z!Clock.callLater.<locals>.<lambda>$s�r1)rrAr�r�r�r)r.rr�rr&�dcs      r/rszClock.callLaters_����L�L�N�U�"�����J�J�����L�L�
��	
�
�
���"�������	r1c��|jS)zQ
        See L{twisted.internet.interfaces.IReactorTime.getDelayedCalls}
        r�r^s r/�getDelayedCallszClock.getDelayedCalls+s���z�z�r1�amountc���|xj|z
c_|j�|jr�|jdj�|j	�kr�|jjd�}d|_|j|ji|j��|j�|jr0|jdj�|j	�kr��yyyy)z�
        Move time on this clock forward by the given amount and run whatever
        pending calls should be run.

        @param amount: The number of seconds which to advance this clock's
        time.
        rr@N)
r�rr�r�rA�pop�calledr|rr&)r.rrs   r/�advancez
Clock.advance1s���	
�
�
���
������j�j�T�Z�Z��]�2�2�4�����F��:�:�>�>�!�$�D��D�K��D�I�I�t�y�y�,�D�G�G�,��O�O��	�j�j�T�Z�Z��]�2�2�4�����F�j�F�jr1�timingsc�4�|D]}|j|��y)zB
        Advance incrementally by the given set of times.
        N)r)r.rrs   r/�pumpz
Clock.pumpAs���	!�F��L�L�� �	!r1r)rvr�rur�r�r0rrrArrrJrrsr
r
rrrr�r1r/r�r��s�����H�+����3����&.�s�F�{�&;��DJ��RX��	��&��,�!7���e���� !�H�U�O�!��!r1r�r-r.rr&c�������dttddf�fd�}dtdtf���fd�}t|�}|j|�|j	||j
d��|S)a+
    Call the given function after a certain period of time has passed.

    @param clock: The object which will be used to schedule the delayed
        call.

    @param delay: The number of seconds to wait before calling the function.

    @param callable: The callable to call after the delay, or C{None}.

    @param args: The positional arguments to pass to C{callable}.

    @param kw: The keyword arguments to pass to C{callable}.

    @return: A deferred that fires with the result of the callable when the
        specified time has elapsed.
    r<r'Nc�&���j�yrc)rX)r<�delayedCalls �r/�deferLaterCancelz$deferLater.<locals>.deferLaterCancelbs������r1rac�����y��i���Srcr�)rarr�r&s ���r/rdzdeferLater.<locals>.cbes��������$��$�$r1)rrJrrirsrY)	r-rr�rr&rrdr[rs	  ```   @r/�
deferLaterrIsb���2�8�F�#3����%�6�%�b�%�
�/�0�A��M�M�"���/�/�%����T�:�K��Hr1�mainzDeferred[_T]�argv�_reactorc�P����	���ddlm}tt|��t	|�g|����}d�d�	d
�	fd�}�jdd|�d	td
tddf��fd��d	tddf���	fd�}|j|��j�tj��y)au
    Call C{main} and run the reactor until the L{Deferred} it returns fires or
    the coroutine it returns completes.

    This is intended as the way to start up an application with a well-defined
    completion condition.  Use it to write clients or one-off asynchronous
    operations.  Prefer this to calling C{reactor.run} directly, as this
    function will also:

      - Take care to call C{reactor.stop} once and only once, and at the right
        time.
      - Log any failures from the C{Deferred} returned by C{main}.
      - Exit the application when done, with exit code 0 in case of success and
        1 in case of failure. If C{main} fails with a C{SystemExit} error, the
        code returned is used.

    The following demonstrates the signature of a C{main} function which can be
    used with L{react}::

      async def main(reactor, username, password):
          return "ok"

      task.react(main, ("alice", "secret"))

    @param main: A callable which returns a L{Deferred} or
        coroutine. It should take the reactor as its first
        parameter, followed by the elements of C{argv}.

    @param argv: A list of arguments to pass to C{main}. If omitted the
        callable will be invoked with no additional arguments.

    @param _reactor: An implementation detail to allow easier unit testing.  Do
        not supply this parameter.

    @since: 12.3
    Nrr*Fr'c�
��d�yr�r�)�stoppings�r/�
onShutdownzreact.<locals>.onShutdown�s����r1�before�shutdownra�stopReactorc���|r��J�	�j�t|t�rE|j	t
��|jj�ytj|d�d�yy#t$rY�awxYw)Nzmain function encountered errorr@)
r\rr�r�check�
SystemExit�value�coder�err)rar"rr's  ��r/r\zreact.<locals>.stop�sw�����'�'�'�
��
�
���f�g�&��|�|�J�'�3��|�|�(�(������ A�B���
'��%�
��
�s�A/�/	A;�:A;c�L���r
�|d�y��J��j�|d�y)NFT)�callWhenRunning)rarr\rs ���r/�cbFinishzreact.<locals>.cbFinish�s.���������'�'�'��$�$�T�6�4�8r1r)r,r+r
rr�addSystemEventTriggerrJr��addBoth�run�sys�exit)
rrrr+�finishedrr+r'r\rs
  `    @@@r/�reactr2ps����X��,���g�.���d�8�3�d�3�4�H��D��H��
�"�"�8�Z��D��V��$��4�� 9��9�D�9�
���X���L�L�N��H�H�T�Nr1)rr�r�r�r�rr2rc)r�N)@r�r/r�r8�typingrrrrrrr	r
rrr
�zope.interfacer�incrementalr�twisted.internet.baser�twisted.internet.deferrrr�twisted.internet.errorr�twisted.internet.interfacesrrr�twisted.pythonrr�twisted.python.deprecater�twisted.python.failurerrr�	Exceptionr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrJrr2�__all__r�r1r/�<module>r?s:��
�
�������'��-�J�J�4�P�P�'�A�*��T�]��M
�M
�`�Y���~���>���|���,��������'�'���E���T�� 2�E�|�E��~�&��YM�YM�xy3�y3�x���
.����
.��(�2�,�)?�
.�.����.��.�$
�\��J!�J!��J!�`-1�$
��$
��$
��x��R��(�)�$
��	$
�
�$
��b�\�
$
�X �'+�
U�
��
�h�r�l�I�n�f�b�&@�A�A�B�	D��U�
�6�
�U��|�$�
U��U�p�r1

Zerion Mini Shell 1.0