Hacked By AnonymousFox

Current Path : /opt/alt/python39/lib64/python3.9/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/asyncio/__pycache__/tasks.cpython-39.pyc

a

���es��@s�dZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZe�d�jZdEdd
�ZdFdd�ZdGdd�Zdd�ZGdd�dej�ZeZzddlZWne�yYn0ejZZdd�dd�Z ejj!Z!ejj"Z"ejj#Z#dde#d�dd�Z$dd�Z%dd�dd �Z&d!d"�Z'd#d$�Z(ddd%�d&d'�Z)ej*d(d)��Z+dHdd�d*d+�Z,dd�d,d-�Z-ej*d.d/��Z.ee._Gd0d1�d1ej/�Z0dd2d3�d4d5�Z1dd2d3�d6d7�Z2dd�d8d9�Z3d:d;�Z4e
�5�Z6iZ7d<d=�Z8d>d?�Z9d@dA�Z:dBdC�Z;e8Z<e;Z=e9Z>e:Z?z$ddDlm8Z8m;Z;m9Z9m:Z:m6Z6m7Z7Wne�yzYn0e8Z@e;ZAe9ZBe:ZCdS)Iz0Support for tasks, coroutines and the scheduler.)�Task�create_task�FIRST_COMPLETED�FIRST_EXCEPTION�
ALL_COMPLETED�wait�wait_for�as_completed�sleep�gather�shield�
ensure_future�run_coroutine_threadsafe�current_task�	all_tasks�_register_task�_unregister_task�_enter_task�_leave_task�N)�GenericAlias�)�
base_tasks)�
coroutines)�events)�
exceptions)�futures)�
_is_coroutinecCs|durt��}t�|�S)z!Return a currently executed task.N)r�get_running_loop�_current_tasks�get��loop�r"�2/opt/alt/python39/lib64/python3.9/asyncio/tasks.pyr#srcs\�durt���d}ztt�}WqJtyD|d7}|dkr@�Yq0qJq�fdd�|D�S)z'Return a set of all tasks for the loop.Nrr��cs&h|]}t�|��ur|��s|�qSr")r�	_get_loop�done��.0�tr r"r#�	<setcomp>=s�zall_tasks.<locals>.<setcomp>)rr�list�
_all_tasks�RuntimeError�r!�iZtasksr"r r#r*srcs\�durt���d}ztt�}WqJtyD|d7}|dkr@�Yq0qJq�fdd�|D�S)Nrrr$csh|]}t�|��ur|�qSr")rr%r'r r"r#r*V�z$_all_tasks_compat.<locals>.<setcomp>)r�get_event_loopr+r,r-r.r"r r#�_all_tasks_compatAsr2cCs2|dur.z
|j}Wnty$Yn
0||�dS�N)�set_name�AttributeError)�task�namer4r"r"r#�_set_task_nameYs
r8cs�eZdZdZdZddd��fdd�
Z�fdd�Zee�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�dd�Zddd�dd�Zd!dd�Zd"�fdd�	Zdd �Z�ZS)#rz A coroutine wrapped in a Future.TN)r!r7cs�t�j|d�|jr|jd=t�|�s:d|_td|����|durRdt���|_n
t	|�|_d|_
d|_||_t
��|_|jj|j|jd�t|�dS)Nr ���Fza coroutine was expected, got zTask-��context)�super�__init__�_source_tracebackr�iscoroutine�_log_destroy_pending�	TypeError�_task_name_counter�_name�str�_must_cancel�_fut_waiter�_coro�contextvarsZcopy_context�_context�_loop�	call_soon�_Task__stepr)�self�coror!r7��	__class__r"r#r=us


z
Task.__init__csF|jtjkr8|jr8|dd�}|jr,|j|d<|j�|�t���dS)Nz%Task was destroyed but it is pending!)r6�messageZsource_traceback)	Z_staterZ_PENDINGr@r>rJZcall_exception_handlerr<�__del__)rMr;rOr"r#rR�s�
zTask.__del__cCs
t�|�Sr3)rZ_task_repr_info�rMr"r"r#�
_repr_info�szTask._repr_infocCs|jSr3)rGrSr"r"r#�get_coro�sz
Task.get_corocCs|jSr3)rCrSr"r"r#�get_name�sz
Task.get_namecCst|�|_dSr3)rDrC)rM�valuer"r"r#r4�sz
Task.set_namecCstd��dS)Nz*Task does not support set_result operation�r-)rM�resultr"r"r#�
set_result�szTask.set_resultcCstd��dS)Nz-Task does not support set_exception operationrX)rM�	exceptionr"r"r#�
set_exception�szTask.set_exception)�limitcCst�||�S)a�Return the list of stack frames for this task's coroutine.

        If the coroutine is not done, this returns the stack where it is
        suspended.  If the coroutine has completed successfully or was
        cancelled, this returns an empty list.  If the coroutine was
        terminated by an exception, this returns the list of traceback
        frames.

        The frames are always ordered from oldest to newest.

        The optional limit gives the maximum number of frames to
        return; by default all available frames are returned.  Its
        meaning differs depending on whether a stack or a traceback is
        returned: the newest frames of a stack are returned, but the
        oldest frames of a traceback are returned.  (This matches the
        behavior of the traceback module.)

        For reasons beyond our control, only one stack frame is
        returned for a suspended coroutine.
        )rZ_task_get_stack)rMr]r"r"r#�	get_stack�szTask.get_stack)r]�filecCst�|||�S)anPrint the stack or traceback for this task's coroutine.

        This produces output similar to that of the traceback module,
        for the frames retrieved by get_stack().  The limit argument
        is passed to get_stack().  The file argument is an I/O stream
        to which the output is written; by default output is written
        to sys.stderr.
        )rZ_task_print_stack)rMr]r_r"r"r#�print_stack�s	zTask.print_stackcCs>d|_|��rdS|jdur.|jj|d�r.dSd|_||_dS)a�Request that this task cancel itself.

        This arranges for a CancelledError to be thrown into the
        wrapped coroutine on the next cycle through the event loop.
        The coroutine then has a chance to clean up or even deny
        the request using try/except/finally.

        Unlike Future.cancel, this does not guarantee that the
        task will be cancelled: the exception might be caught and
        acted upon, delaying cancellation of the task or preventing
        cancellation completely.  The task may also return a value or
        raise a different exception.

        Immediately after this method is called, Task.cancelled() will
        not return True (unless the task was already cancelled).  A
        task will be marked as cancelled when the wrapped coroutine
        terminates with a CancelledError exception (even if cancel()
        was not called).
        FN��msgT)Z_log_tracebackr&rF�cancelrE�_cancel_message)rMrbr"r"r#rc�s
zTask.cancelc
s|��rt�d|�d|����|jr>t|tj�s8|��}d|_|j}d|_t	|j
|��z�z"|durp|�d�}n
|�|�}Wn�t
y�}z:|jr�d|_t�j|jd�nt��|j�WYd}~�n d}~0tj�y}z||_t���WYd}~�n�d}~0ttf�y>}zt��|��WYd}~�n�d}~0t�yp}zt��|�WYd}~�n~d}~00t|dd�}|du�rjt�|�|j
u�r�td|�d|�d��}|j
j|j||jd	�n�|�r>||u�r�td
|���}|j
j|j||jd	�n>d|_|j |j!|jd	�||_|j�rh|jj|jd��rhd|_n*td|�d|���}|j
j|j||jd	�n||du�r�|j
j|j|jd	�n\t"�#|��r�td
|�d|���}|j
j|j||jd	�n$td|���}|j
j|j||jd	�Wt$|j
|�d}nt$|j
|�d}0dS)Nz_step(): already done: z, Fra�_asyncio_future_blockingzTask z got Future z attached to a different loopr:zTask cannot await on itself: z-yield was used instead of yield from in task z with z;yield was used instead of yield from for generator in task zTask got bad yield: )%r&rZInvalidStateErrorrE�
isinstance�CancelledError�_make_cancelled_errorrGrFrrJ�send�throw�
StopIterationr<rcrdrZrWZ_cancelled_exc�KeyboardInterrupt�
SystemExitr\�
BaseException�getattrrr%r-rKrLrIre�add_done_callback�
_Task__wakeup�inspectZisgeneratorr)rM�excrNrYZblocking�new_excrOr"r#Z__step�s��$ $
��
�
�
������
�
���
�
��zTask.__stepc
CsLz|��Wn.ty:}z|�|�WYd}~nd}~00|��d}dSr3)rYrnrL)rM�futurersr"r"r#Z__wakeupFs z
Task.__wakeup)N)N)�__name__�
__module__�__qualname__�__doc__r@r=rR�classmethodr�__class_getitem__rTrUrVr4rZr\r^r`rcrLrq�
__classcell__r"r"rOr#rcs 

"Wr)r7cCs t��}|�|�}t||�|S)z]Schedule the execution of a coroutine object in a spawn task.

    Return a Task object.
    )rrrr8)rNr7r!r6r"r"r#rcs

r)r!�timeout�return_whenc�s�t�|�st�|�r(tdt|�j����|s4td��|tt	t
fvrPtd|�����durbt���nt
jdtdd�t|�}tdd	�|D��r�t
jd
tdd��fdd�|D�}t|||��IdHS)
a�Wait for the Futures and coroutines given by fs to complete.

    The fs iterable must not be empty.

    Coroutines will be wrapped in Tasks.

    Returns two sets of Future: (done, pending).

    Usage:

        done, pending = await asyncio.wait(fs)

    Note: This does not raise TimeoutError! Futures that aren't done
    when the timeout occurs are returned in the second set.
    zexpect a list of futures, not z#Set of coroutines/Futures is empty.zInvalid return_when value: N�[The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.���
stacklevelcss|]}t�|�VqdSr3)rr?�r(�fr"r"r#�	<genexpr>�r0zwait.<locals>.<genexpr>z�The explicit passing of coroutine objects to asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in Python 3.11.csh|]}t|�d��qS�r �rr�r r"r#r*�r0zwait.<locals>.<setcomp>)r�isfuturerr?rA�typerv�
ValueErrorrrrrr�warnings�warn�DeprecationWarning�set�any�_wait)�fsr!r}r~r"r r#rus$
��rcGs|��s|�d�dSr3)r&rZ)�waiter�argsr"r"r#�_release_waiter�sr�r c
�s�|durt��}ntjdtdd�|dur4|IdHS|dkr�t||d�}|��rX|��St||d�IdHz
|��WSt	j
y�}zt	��|�WYd}~n
d}~00|��}|�
|t|�}t�t|�}t||d�}|�|�z�z|IdHWnTt	j
�yB|���r |��YW|��S|�|�t||d�IdH�Yn0|���r`|��W|��S|�|�t||d�IdHz|��WW|��St	j
�y�}zt	��|�WYd}~n
d}~00W|��n
|��0dS)a�Wait for the single Future or coroutine to complete, with timeout.

    Coroutine will be wrapped in Task.

    Returns result of the Future or coroutine.  When a timeout occurs,
    it cancels the task and raises TimeoutError.  To avoid the task
    cancellation, wrap it in shield().

    If the wait is cancelled, the task is also cancelled.

    This function is a coroutine.
    Nrr�r�rr )rrr�r�r�rr&rY�_cancel_and_waitrrg�TimeoutError�
create_future�
call_laterr��	functools�partialrprc�remove_done_callback)�futr}r!rsr��timeout_handle�cbr"r"r#r�sZ

�

 

�

�

�"rc
�s�|sJd��|���d�|dur.|�|t���t|������fdd�}|D]}|�|�qLz2�IdHW�durz���|D]}|�|�q~n&�dur����|D]}|�|�q�0t�t�}}|D]"}|��r�|�	|�q�|�	|�q�||fS)zVInternal helper for wait().

    The fs argument must be a collection of Futures.
    zSet of Futures is empty.NcsZ�d8��dks4�tks4�tkrV|��sV|��durV�durD������sV��d�dS)Nrr)rr�	cancelledr[rcr&rZ�r��Zcounterr~r�r�r"r#�_on_completion�s���
�z_wait.<locals>._on_completion)
r�r�r��lenrprcr�r�r&�add)r�r}r~r!r�r�r&Zpendingr"r�r#r��s2�r�c	�sP|��}t�t|�}|�|�z |��|IdHW|�|�n|�|�0dS)z<Cancel the *fut* future or task and wait until it completes.N)r�r�r�r�rprcr�)r�r!r�r�r"r"r#r�s
r�)r!r}c#s�t�|�st�|�r(tdt|�j�����dur@tjdt	dd�ddl
m}|�d���durft�
���fd	d
�t|�D��d����fdd�}���fd
d���fdd�}�D]}|���q��r�|dur؈�||��tt���D]}|�Vq�dS)a^Return an iterator whose values are coroutines.

    When waiting for the yielded coroutines you'll get the results (or
    exceptions!) of the original Futures (or coroutines), in the order
    in which and as soon as they complete.

    This differs from PEP 3148; the proper way to use this is:

        for f in as_completed(fs):
            result = await f  # The 'await' may raise.
            # Use result.

    If a timeout is specified, the 'await' will raise
    TimeoutError when the timeout occurs before all Futures are done.

    Note: The futures 'f' are not necessarily members of fs.
    z#expect an iterable of futures, not Nrr�r�r)�Queuer csh|]}t|�d��qSr�r�r�r r"r#r*Mr0zas_completed.<locals>.<setcomp>cs*�D]}|�����d�q���dSr3)r��
put_nowait�clearr�)r�r&�todor"r#�_on_timeoutPs
z!as_completed.<locals>._on_timeoutcs4�sdS��|���|��s0�dur0���dSr3)�remover�rcr�)r&r�r�r"r#r�Vs

z$as_completed.<locals>._on_completionc�s$���IdH}|durtj�|��Sr3)rrr�rYr�)r&r"r#�
_wait_for_one^sz#as_completed.<locals>._wait_for_one)rr�rr?rAr�rvr�r�r�Zqueuesr�rr1r�rpr��ranger�)r�r!r}r�r�r�r��_r")r�r&r!r�r�r#r.s*�
rccs
dVdS)z�Skip one event loop run cycle.

    This is a private helper for 'asyncio.sleep()', used
    when the 'delay' is set to 0.  It uses a bare 'yield'
    expression (which Task.__step knows how to handle)
    instead of creating a Future object.
    Nr"r"r"r"r#�__sleep0ms	r�c�s~|durtjdtdd�|dkr0t�IdH|S|dur@t��}|��}|�|tj	||�}z|IdHW|�
�S|�
�0dS)z9Coroutine that completes after a given time (in seconds).Nrr�r�r)r�r�r�r�rrr�r�rZ_set_result_unless_cancelledrc)ZdelayrYr!ru�hr"r"r#r	ys&��
�r	cCs�t�|�r6|durt��}|�|�}|jr2|jd=|St�|�rb|dur^|t�|�ur^t	d��|St
�|�r|tt
|�|d�Std��dS)zmWrap a coroutine or an awaitable in a future.

    If the argument is a Future, it is returned directly.
    Nr9zRThe future belongs to a different loop than the one specified as the loop argumentr z:An asyncio.Future, a coroutine or an awaitable is required)rr?rr1rr>rr�r%r�rrZisawaitabler�_wrap_awaitablerA)Zcoro_or_futurer!r6r"r"r#r�s



rccs|��EdHS)z�Helper for asyncio.ensure_future().

    Wraps awaitable (an object with __await__) into a coroutine
    that will later be wrapped in a Task by ensure_future().
    N)�	__await__)Z	awaitabler"r"r#r��sr�cs0eZdZdZdd��fdd�
Zddd�Z�ZS)	�_GatheringFuturez�Helper for gather().

    This overrides cancel() to cancel all the children and act more
    like Task.cancel(), which doesn't immediately mark itself as
    cancelled.
    Nr cst�j|d�||_d|_dS)Nr F)r<r=�	_children�_cancel_requested)rM�childrenr!rOr"r#r=�sz_GatheringFuture.__init__cCs:|��rdSd}|jD]}|j|d�rd}q|r6d|_|S)NFraT)r&r�rcr�)rMrbZret�childr"r"r#rc�s
z_GatheringFuture.cancel)N)rvrwrxryr=rcr|r"r"rOr#r��sr�F�r!�return_exceptionscGs(|durtjdtdd�t|||d��S)a�Return a future aggregating results from the given coroutines/futures.

    Coroutines will be wrapped in a future and scheduled in the event
    loop. They will not necessarily be scheduled in the same order as
    passed in.

    All futures must share the same event loop.  If all the tasks are
    done successfully, the returned future's result is the list of
    results (in the order of the original sequence, not necessarily
    the order of results arrival).  If *return_exceptions* is True,
    exceptions in the tasks are treated the same as successful
    results, and gathered in the result list; otherwise, the first
    raised exception will be immediately propagated to the returned
    future.

    Cancellation: if the outer Future is cancelled, all children (that
    have not completed yet) are also cancelled.  If any child is
    cancelled, this is treated as if it raised CancelledError --
    the outer Future is *not* cancelled in this case.  (This is to
    prevent the cancellation of one child to cause other children to
    be cancelled.)

    If *return_exceptions* is False, cancelling gather() after it
    has been marked done won't cancel any submitted awaitables.
    For instance, gather can be marked done after propagating an
    exception to the caller, therefore, calling ``gather.cancel()``
    after catching an exception (raised by one of the awaitables) from
    gather won't cancel any other awaitables.
    Nrr�r�r�)r�r�r��_gather)r!r��coros_or_futuresr"r"r#r
�s
�r
cs�|s*|durt��}|�����g��S�����fdd�}i}g�d�d�d�|D]f}||vr�t||d�}|dur�t�|�}||ur�d|_�d7�|||<|�|�n||}��	|�qVt
�|d���S)Ncs��d7��dus���r,|��s(|��dS�sl|��rN|��}��|�dS|��}|durl��|�dS��kr�g}�D]J}|��r�t�|jdur�dn|j�}n|��}|dur�|��}|�	|�q|�j
r�|��}��|�n
��|�dS)Nr�)r&r�r[rhr\rrgrdrY�appendr�rZ)r�rsZresults�res�r�Z	nfinishedZnfuts�outerr�r"r#�_done_callback�s<

�z_gather.<locals>._done_callbackrr Fr)rr1r�rZrrr%r@rpr�r�)r!r�r�r�Z
arg_to_fut�argr�r"r�r#r��s4
7
r�cst|durtjdtdd�t||d�����r0�St���}|����fdd����fdd	�}������|��S)
a.Wait for a future, shielding it from cancellation.

    The statement

        res = await shield(something())

    is exactly equivalent to the statement

        res = await something()

    *except* that if the coroutine containing it is cancelled, the
    task running in something() is not cancelled.  From the POV of
    something(), the cancellation did not happen.  But its caller is
    still cancelled, so the yield-from expression still raises
    CancelledError.  Note: If something() is cancelled by other means
    this will still cancel shield().

    If you want to completely ignore cancellation (not recommended)
    you can combine shield() with a try/except clause, as follows:

        try:
            res = await shield(something())
        except CancelledError:
            res = None
    Nrr�r�r cs\���r|��s|��dS|��r.���n*|��}|durJ��|�n��|���dSr3)r�r[rcr\rZrY)�innerrs�r�r"r#�_inner_done_callbackzs
z$shield.<locals>._inner_done_callbackcs���s����dSr3)r&r�r�)r�r�r"r#�_outer_done_callback�sz$shield.<locals>._outer_done_callback)	r�r�r�rr&rr%r�rp)r�r!r�r")r�r�r�r#rUs�


rcs:t���std��tj������fdd�}��|��S)zsSubmit a coroutine object to a given event loop.

    Return a concurrent.futures.Future to access the result.
    zA coroutine object is requiredc
slzt�t��d���WnNttfy0�Yn8tyf}z ���rP��|��WYd}~n
d}~00dS)Nr )rZ
_chain_futurerrmrlrnZset_running_or_notify_cancelr\)rs�rNrur!r"r#�callback�s
z*run_coroutine_threadsafe.<locals>.callback)rr?rA�
concurrentr�FutureZcall_soon_threadsafe)rNr!r�r"r�r#r
�s



r
cCst�|�dS)z3Register a new task in asyncio as executed by loop.N)r,r��r6r"r"r#r�srcCs4t�|�}|dur(td|�d|�d���|t|<dS)NzCannot enter into task z while another task z is being executed.�rrr-�r!r6rr"r"r#r�s

�
rcCs2t�|�}||ur(td|�d|�d���t|=dS)Nz
Leaving task z! does not match the current task �.r�r�r"r"r#r�s

�
rcCst�|�dS)zUnregister a task.N)r,�discardr�r"r"r#r�sr)rrrrr,r)N)N)N)N)Dry�__all__Zconcurrent.futuresr�rHr�rr�	itertools�typesr��weakrefrr�rrrrrr�count�__next__rBrrr2r8Z	_PyFuturerZ_PyTaskZ_asyncio�ImportErrorZ_CTaskrrrrrr�rr�r�r�	coroutiner�r	rr�r�r�r
r�rr
ZWeakSetr,rrrrrZ_py_register_taskZ_py_unregister_taskZ_py_enter_taskZ_py_leave_taskZ_c_register_taskZ_c_unregister_taskZ
_c_enter_taskZ
_c_leave_taskr"r"r"r#�<module>s�	



u

+L,?

&^?$

Hacked By AnonymousFox1.0, Coded By AnonymousFox