AlkantarClanX12

Your IP : 18.119.124.52


Current Path : /opt/alt/python38/lib64/python3.8/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/asyncio/__pycache__/tasks.cpython-38.opt-1.pyc

U

i�f���@svdZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
ddlmZddlmZdd	lmZdd
l
mZe�d�jZdBdd�ZdCd
d�ZdDdd�Zdd�ZGdd�dej�ZeZzddlZWnek
r�YnXejZZdd�dd�Zejj 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*dEdd�d)d*�Z+dd�d+d,�Z,ej)d-d.��Z-ee-_Gd/d0�d0ej.�Z/dd1d2�d3d4�Z0dd�d5d6�Z1d7d8�Z2e
�3�Z4iZ5d9d:�Z6d;d<�Z7d=d>�Z8d?d@�Z9e6Z:e9Z;e7Z<e8Z=z$ddAlm6Z6m9Z9m7Z7m8Z8m4Z4m5Z5Wnek
�r`YnXe6Z>e9Z?e7Z@e8ZAdS)Fz0Support 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�)�
base_tasks)�
coroutines)�events)�
exceptions)�futures)�
_is_coroutinecCs|dkrt��}t�|�S)z!Return a currently executed task.N)r�get_running_loop�_current_tasks�get��loop�r!�2/opt/alt/python38/lib64/python3.8/asyncio/tasks.pyr"srcs^�dkrt���d}ztt�}WqLtk
rF|d7}|dkrB�YqXqLq�fdd�|D�S)z'Return a set of all tasks for the loop.Nrr��cs&h|]}t�|��kr|��s|�qSr!)r�	_get_loop�done��.0�trr!r"�	<setcomp><s�zall_tasks.<locals>.<setcomp>)rr�list�
_all_tasks�RuntimeError�r �iZtasksr!rr"r)srcs^�dkrt���d}ztt�}WqLtk
rF|d7}|dkrB�YqXqLq�fdd�|D�S)Nrrr#csh|]}t�|��kr|�qSr!)rr$r&rr!r"r)Usz$_all_tasks_compat.<locals>.<setcomp>)r�get_event_loopr*r+r,r-r!rr"�_all_tasks_compat@sr0cCs4|dk	r0z
|j}Wntk
r&Yn
X||�dS�N)�set_name�AttributeError)�task�namer2r!r!r"�_set_task_nameXs
r6cs�eZdZdZdZed%dd��Zed&dd��Zddd��fd	d
�
Z�fdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�dd�Zddd�dd�Zdd �Zd'�fd!d"�	Zd#d$�Z�ZS)(rz A coroutine wrapped in a Future.TNcCs(tjdtdd�|dkr t��}t|�S)z�Return the currently running task in an event loop or None.

        By default the current task for the current event loop is returned.

        None is returned when called not in the context of a Task.
        zVTask.current_task() is deprecated since Python 3.7, use asyncio.current_task() instead���
stacklevelN)�warnings�warn�DeprecationWarningrr/r��clsr r!r!r"rts�zTask.current_taskcCstjdtdd�t|�S)z|Return a set of all tasks for an event loop.

        By default all tasks for the current event loop are returned.
        zPTask.all_tasks() is deprecated since Python 3.7, use asyncio.all_tasks() insteadr7r8)r:r;r<r0r=r!r!r"r�s
�zTask.all_tasks)r r5cs�t�j|d�|jr|jd=t�|�s:d|_td|����|dkrRdt���|_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 r5��	__class__r!r"rC�s


z
Task.__init__csF|jtjkr8|jr8|dd�}|jr,|j|d<|j�|�t���dS)Nz%Task was destroyed but it is pending!)r4�messageZsource_traceback)	Z_staterZ_PENDINGrFrDrPZcall_exception_handlerrB�__del__)rSrArUr!r"rX�s�
zTask.__del__cCs
t�|�Sr1)rZ_task_repr_info�rSr!r!r"�
_repr_info�szTask._repr_infocCs|jSr1)rMrYr!r!r"�get_coro�sz
Task.get_corocCs|jSr1)rIrYr!r!r"�get_name�sz
Task.get_namecCst|�|_dSr1)rJrI)rS�valuer!r!r"r2�sz
Task.set_namecCstd��dS)Nz*Task does not support set_result operation�r,)rS�resultr!r!r"�
set_result�szTask.set_resultcCstd��dS)Nz-Task does not support set_exception operationr^)rS�	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)rSrcr!r!r"�	get_stack�szTask.get_stack)rc�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)rSrcrer!r!r"�print_stack�s	zTask.print_stackcCs4d|_|��rdS|jdk	r*|j��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).
        FNT)Z_log_tracebackr%rL�cancelrKrYr!r!r"rg�s

zTask.cancelc
s�|��rt�d|�d|����|jr>t|tj�s8t��}d|_|j}d|_t|j	|��zfz"|dkrp|�d�}n
|�|�}Wn�t
k
r�}z*|jr�d|_t���nt��|j�W5d}~XY�n�tjk
r�t���Y�n�ttfk
�r}zt��|��W5d}~XY�n�tk
�rL}zt��|�W5d}~XY�npXt|dd�}|dk	�r@t�|�|j	k	�r�td|�d|�d��}|j	j|j||jd�n�|�r||k�r�td	|���}|j	j|j||jd�n8d|_|j|j|jd�||_|j�r>|j���r>d|_n*td
|�d|���}|j	j|j||jd�n||dk�r`|j	j|j|jd�n\t �!|��r�td|�d|���}|j	j|j||jd�n$td
|���}|j	j|j||jd�W5t
|j	|�d}XdS)Nz_step(): already done: z, F�_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%rZInvalidStateErrorrK�
isinstance�CancelledErrorrMrLrrPr�send�throw�
StopIterationrBrgr`r]�KeyboardInterrupt�
SystemExitrb�
BaseException�getattrrr$r,rQrRrOrh�add_done_callback�
_Task__wakeup�inspectZisgenerator)rS�excrTr_Zblocking�new_excrUr!r"Z__steps��  
��
�����
���
zTask.__stepc
CsJz|��Wn,tk
r8}z|�|�W5d}~XYn
X|��d}dSr1)r_rprR)rS�futurerur!r!r"Z__wakeup[sz
Task.__wakeup)N)N)N)�__name__�
__module__�__qualname__�__doc__rF�classmethodrrrCrXrZr[r\r2r`rbrdrfrgrRrs�
__classcell__r!r!rUr"rbs&
!Tr)r5cCs t��}|�|�}t||�|S)z]Schedule the execution of a coroutine object in a spawn task.

    Return a Task object.
    )rrrr6)rTr5r r4r!r!r"rxs

r)r �timeout�return_whenc�s�t�|�st�|�r(tdt|�j����|s4td��|tt	t
fkrPtd|�����dkrbt���nt
jdtdd��fdd	�t|�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.r7r8csh|]}t|�d��qS�r�r�r'�frr!r"r)�szwait.<locals>.<setcomp>)r�isfuturerrErG�typerx�
ValueErrorrrrrrr:r;r<�set�_wait)�fsr r~rr!rr"r�s
�rcGs|��s|�d�dSr1)r%r`)�waiter�argsr!r!r"�_release_waiter�sr�rc
�s�|dkrt��}ntjdtdd�|dkr4|IdHS|dkr�t||d�}|��rX|��St||d�IdHz|��Wn.t	j
k
r�}zt	��|�W5d}~XYn
Xt	���|��}|�
|t|�}t�t|�}t||d�}|�|�z�z|IdHWnPt	j
k
�rF|���r$|��YW�dS|�|�t||d�IdH�YnX|���r^|��W�*S|�|�t||d�IdHt	���W5|��XdS)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.
    Nr�r7r8rr)rrr:r;r<rr%r_�_cancel_and_waitrrj�TimeoutError�
create_future�
call_laterr��	functools�partialrrrg�remove_done_callback)�futr~r rur��timeout_handle�cbr!r!r"r�sL

�





rc
�s�|���d�|dk	r"|�|t���t|������fdd�}|D]}|�|�q@z�IdHW5�dk	rp���|D]}|�|�qtXt�t�}}|D]"}|��r�|�	|�q�|�	|�q�||fS)zVInternal helper for wait().

    The fs argument must be a collection of Futures.
    NcsZ�d8��dks4�tks4�tkrV|��sV|��dk	rV�dk	rD������sV��d�dS)Nrr)rr�	cancelledrargr%r`�r��Zcounterrr�r�r!r"�_on_completions���
�z_wait.<locals>._on_completion)
r�r�r��lenrrrgr�r�r%�add)r�r~rr r�r�r%Zpendingr!r�r"r��s(r�c	�sF|��}t�t|�}|�|�z|��|IdHW5|�|�XdS)z<Cancel the *fut* future or task and wait until it completes.N)r�r�r�r�rrr�rg)r�r r�r�r!r!r"r�&s
r�)r r~c#s�t�|�st�|�r(tdt|�j����ddlm}|�d���dkrPt	�
��ntjdt
dd��fd	d
�t|�D��d����fdd�}���fd
d���fdd�}�D]}|���q��r�|dk	r҈�||��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 r)�QueuerNr�r7r8csh|]}t|�d��qSr�r�r�rr!r"r)Uszas_completed.<locals>.<setcomp>cs*�D]}|�����d�q���dSr1)r��
put_nowait�clearr�)r�r%�todor!r"�_on_timeoutXs
z!as_completed.<locals>._on_timeoutcs4�sdS��|���|��s0�dk	r0���dSr1)�remover�rgr�)r%r�r�r!r"r�^s

z$as_completed.<locals>._on_completionc�s$���IdH}|dkrtj�|��Sr1)rrr�r_r�)r%r!r"�
_wait_for_onefsz#as_completed.<locals>._wait_for_one)rr�rrErGr�rxZqueuesr�rr/r:r;r<r�rrr��ranger�)r�r r~r�r�r�r��_r!)r�r%r r�r�r"r7s*

�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"�__sleep0us	r�c�sr|dkrt�IdH|S|dkr*t��}ntjdtdd�|��}|�|tj	||�}z|IdHW�S|�
�XdS)z9Coroutine that completes after a given time (in seconds).rNr�r7r8)r�rrr:r;r<r�r�rZ_set_result_unless_cancelledrg)Zdelayr_r rw�hr!r!r"r	�s$
��r	cCs�t�|�r6|dkrt��}|�|�}|jr2|jd=|St�|�rb|dk	r^|t�|�k	r^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.
    Nr?zRThe future belongs to a different loop than the one specified as the loop argumentrz:An asyncio.Future, a coroutine or an awaitable is required)rrErr/rrDrr�r$r�rtZisawaitabler�_wrap_awaitablerG)Zcoro_or_futurer r4r!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�cs.eZdZdZdd��fdd�
Zdd�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.
    Nrcst�j|d�||_d|_dS)NrF)rBrC�	_children�_cancel_requested)rS�childrenr rUr!r"rC�sz_GatheringFuture.__init__cCs6|��rdSd}|jD]}|��rd}q|r2d|_|S)NFT)r%r�rgr�)rSZretZchildr!r!r"rg�s
z_GatheringFuture.cancel)rxryrzr{rCrgr}r!r!rUr"r��sr�F)r �return_exceptionscs�|s<|dkrt��}ntjdtdd�|�����g��S�����fdd�}i}g�d�d�|D]f}||kr�t||d�}|dkr�t�	|�}||k	r�d	|_
�d
7�|||<|�|�n||}��|�qdt
�|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.
    Nr�r7r8cs��d7����r$|��s |��dS�sd|��rFt��}��|�dS|��}|dk	rd��|�dS��kr�g}�D]8}|��r�t��}n|��}|dkr�|��}|�|�qt�jrĈ�t���n
��	|�dS)Nr)
r%r�rarrjrbr_�appendr�r`)r�ruZresults�res�r�Z	nfinishedZnfuts�outerr�r!r"�_done_callbacks4


zgather.<locals>._done_callbackrrFr)rr/r:r;r<r�r`rrr$rFrrr�r�)r r�Zcoros_or_futuresr�Z
arg_to_fut�argr�r!r�r"r
�s:
�
1
r
cst|dk	rtjdtdd�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
    Nr�r7r8rcs\���r|��s|��dS|��r.���n*|��}|dk	rJ��|�n��|���dSr1)r�rargrbr`r_)�innerru�r�r!r"�_inner_done_callbackus
z$shield.<locals>._inner_done_callbackcs���s����dSr1)r%r�r�)r�r�r!r"�_outer_done_callback�sz$shield.<locals>._outer_done_callback)	r:r;r<rr%rr$r�rr)r�r r�r!)r�r�r�r"rPs�


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���WnNttfk
r2�Yn6tk
rf}z���rT��|��W5d}~XYnXdS)Nr)rZ
_chain_futurerrornrpZset_running_or_notify_cancelrb)ru�rTrwr r!r"�callback�s
z*run_coroutine_threadsafe.<locals>.callback)rrErG�
concurrentr�FutureZcall_soon_threadsafe)rTr r�r!r�r"r
�s



r
cCst�|�dS)z3Register a new task in asyncio as executed by loop.N)r+r��r4r!r!r"r�srcCs4t�|�}|dk	r(td|�d|�d���|t|<dS)NzCannot enter into task z while another task z is being executed.�rrr,�r r4rr!r!r"r�s
rcCs2t�|�}||k	r(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)Br{�__all__Zconcurrent.futuresr�rNr�rt�	itertools�typesr:�weakref�rrrrrr�count�__next__rHrrr0r6Z	_PyFuturerZ_PyTaskZ_asyncio�ImportErrorZ_CTaskrrrrrr�rr�r�r�	coroutiner�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�	





#H,>

x?$