
    F\hM                        S r SrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSK	Jr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R(                  " S5      R*                  rS1S jrS1S jr " S S\R2                  5      r\r SSKr\R4                  =rrSSS.S jr\R"                  R@                  r \R"                  RB                  r!\R"                  RD                  r"S\"S.S jr#S r$S r%S r&S r' " S S5      r(SS.S jr)\	RT                  S 5       r+S1S jr,SS.S  jr- " S! S"\R\                  5      r/S#S$.S% jr0S& r1S' r2S( r3\3" \5      r4\
Rj                  " 5       r6\7" 5       r80 r9S) r:S* r;S+ r<S, r=S- r>S. r?S/ r@\rA\:rB\;rC\?rD\@rE\<rF\=rG\>rH SS0KJ:r:J;r;J?r?J@r@J<r<J=r=J>r>J6r6J8r8J9r9Jr  \rI\:rJ\;rK\?rL\@rM\<rN\=rO\>rPg! \ a     GN.f = f! \ a     gf = f)2z0Support 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create_eager_task_factoryeager_task_factory_register_task_unregister_task_enter_task_leave_task    N)GenericAlias   )
base_tasks)
coroutines)events)
exceptions)futures)queues)timeoutsc                 ^    U c  [         R                  " 5       n [        R                  " U 5      $ )z!Return a currently executed task.)r   get_running_loop_current_tasksgetloops    $/usr/lib/python3.13/asyncio/tasks.pyr   r   %   s&    |&&(d##    c                 t   U c  [         R                  " 5       n [        [        5      nSnSn  [        [        5      n [        R                  " X!5       Vs1 s H7  n[        R                  " U5      U L d  M  UR                  5       (       a  M5  UiM9     sn$ ! [
         a    US-  nUS:  a  e  Of = fM  s  snf )z'Return a set of all tasks for the loop.Nr   r   i  )r   r"   list_eager_tasks_scheduled_tasksRuntimeError	itertoolschainr   	_get_loopdone)r&   eager_tasksscheduled_tasksits        r'   r   r   ,   s    |&&( |$K O	A
	"#34O  D >D!  #t+ 45FFH D > >  	FADy 	 >s#   B B57B5B5B0/B0c                      ^  \ rS rSrSrSrSSSSS.U 4S jjrU 4S jr\" \	5      r
S	 rS
 rS rS rS rS rS rSS.S jrSSS.S jrSS jrS rS rS rSS jrU 4S jrS rSrU =r$ )r   G   z A coroutine wrapped in a Future.TNFr&   namecontexteager_startc                h  > [         TU ]  US9  U R                  (       a  U R                  S	 [        R                  " U5      (       d  SU l        [        SU< 35      eUc  S[        5        3U l        O[        U5      U l        SU l
        SU l        S U l        Xl        Uc  [        R                  " 5       U l        OX@l        U(       a0  U R"                  R%                  5       (       a  U R'                  5         g U R"                  R)                  U R*                  U R                   S9  [-        U 5        g )Nr%   Fza coroutine was expected, got zTask-r   r:   )super__init___source_tracebackr   iscoroutine_log_destroy_pending	TypeError_task_name_counter_namestr_num_cancels_requested_must_cancel_fut_waiter_corocontextvarscopy_context_context_loop
is_running_Task__eager_start	call_soon_Task__stepr   )selfcoror&   r9   r:   r;   	__class__s         r'   r@   Task.__init__c   s    d#!!&&r*%%d++ ).D%<THEFF< !3!5 67DJTDJ&'#!
?'446DM#M4::0022 JJ  dmm D4 r(   c                    > U R                   [        R                  :X  aQ  U R                  (       a@  U SS.nU R                  (       a  U R                  US'   U R
                  R                  U5        [        TU ]!  5         g )Nz%Task was destroyed but it is pending!)taskmessagesource_traceback)	_stater   _PENDINGrC   rA   rO   call_exception_handlerr?   __del__)rT   r:   rV   s     r'   r_   Task.__del__   sb    ;;'***t/H/HBG %%.2.D.D*+JJ--g6r(   c                 .    [         R                  " U 5      $ N)r   
_task_reprrT   s    r'   __repr__Task.__repr__   s    $$T**r(   c                     U R                   $ rb   )rK   rd   s    r'   get_coroTask.get_coro       zzr(   c                     U R                   $ rb   )rN   rd   s    r'   get_contextTask.get_context   s    }}r(   c                     U R                   $ rb   )rF   rd   s    r'   get_nameTask.get_name   rj   r(   c                 $    [        U5      U l        g rb   )rG   rF   )rT   values     r'   set_nameTask.set_name   s    Z
r(   c                     [        S5      e)Nz*Task does not support set_result operationr-   )rT   results     r'   
set_resultTask.set_result   s    GHHr(   c                     [        S5      e)Nz-Task does not support set_exception operationrv   )rT   	exceptions     r'   set_exceptionTask.set_exception   s    JKKr(   )limitc                .    [         R                  " X5      $ )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.
)r   _task_get_stack)rT   r~   s     r'   	get_stackTask.get_stack   s    * ))$66r(   )r~   filec                0    [         R                  " XU5      $ )a>  Print 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.
)r   _task_print_stack)rT   r~   r   s      r'   print_stackTask.print_stack   s     ++D>>r(   c                     SU l         U R                  5       (       a  gU =R                  S-  sl        U R                  b  U R                  R	                  US9(       a  gSU l        Xl        g)aJ  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).

This also increases the task's count of cancellation requests.
Fr   msgT)_log_tracebackr1   rH   rJ   cancelrI   _cancel_message)rT   r   s     r'   r   Task.cancel   sf    , $99;;##q(# '&&3&/  "r(   c                     U R                   $ )zReturn the count of the task's cancellation requests.

This count is incremented when .cancel() is called
and may be decremented using .uncancel().
)rH   rd   s    r'   
cancellingTask.cancelling   s     ***r(   c                     U R                   S:  a,  U =R                   S-  sl         U R                   S:X  a  SU l        U R                   $ )zDecrement the task's count of cancellation requests.

This should be called by the party that called `cancel()` on the task
beforehand.

Returns the remaining number of cancellation requests.
r   r   F)rH   rI   rd   s    r'   uncancelTask.uncancel   sE     &&*''1,'**a/$)!***r(   c                    [        U R                  U 5      n [        U 5         U R                  R	                  U R
                  S 5        [        U 5          [        U R                  U5      nX L d   e U R                  5       (       a
  S U l        S n g [        U 5        g ! [        U 5        f = f! U R                  5       (       a
  S U l        S n f [        U 5        f = f!  [        U R                  U5      nX L d   e U R                  5       (       a
  S U l        S n f [        U 5        f ! U R                  5       (       a
  S U l        S n f [        U 5        f = f= frb   )
_swap_current_taskrO   _register_eager_taskrN   run!_Task__step_run_and_handle_result_unregister_eager_taskr1   rK   r   )rT   	prev_taskcurtasks      r'   __eager_startTask.__eager_start  s   &tzz48		) &-!!$"C"CTJ&t,),TZZC&99;;!%DJD"4( 't, 99;;!%DJD"4(),TZZC&99;;!%DJD"4(	 99;;!%DJD"4(sF   C &B 
C B/ B,,C /,CE D(=+E(,EEc                    U R                  5       (       a  [        R                  " SU < SU< 35      eU R                  (       a6  [	        U[        R
                  5      (       d  U R                  5       nSU l        S U l        [        U R                  U 5         U R                  U5        [        U R                  U 5        S n g ! [        U R                  U 5        S n f = f)Nz_step(): already done: z, F)r1   r   InvalidStateErrorrI   
isinstanceCancelledError_make_cancelled_errorrJ   r   rO   r   r   )rT   excs     r'   __stepTask.__step  s    99;;..)$C7;= =c:#<#<==002 %DDJJ%	--c2

D)D 

D)Ds   C Cc                   > U R                   n Uc  UR                  S 5      nOUR                  U5      n[        USS 5      nUGbf  [        R
                  " U5      U R                  LaD  [        SU < SU< S35      nU R                  R                  U R                  XPR                  S9  GOU(       a  X0L a?  [        SU < 35      nU R                  R                  U R                  XPR                  S9  GOSUl        UR                  U R                  U R                  S9  X0l        U R                  (       a/  U R                  R!                  U R"                  S9(       a  SU l        GO[        S	U < S
U< 35      nU R                  R                  U R                  XPR                  S9  OUc/  U R                  R                  U R                  U R                  S9  O[$        R&                  " U5      (       aB  [        SU < S
U< 35      nU R                  R                  U R                  XPR                  S9  O>[        SU< 35      nU R                  R                  U R                  XPR                  S9   S n g ! [(         aW  nU R                  (       a#  SU l        [*        TU ]A  U R"                  S9   S nANA[*        TU ]Y  UR.                  5         S nAN_S nAf[0        R2                   a  nXl        [*        TU ]A  5          S nANS nAf[6        [8        4 a  n[*        TU ]u  U5        e S nAf[<         a  n[*        TU ]u  U5         S nANS nAff = f! S n f = f)N_asyncio_future_blockingzTask z got Future z attached to a different loopr>   zTask cannot await on itself: Fr   z-yield was used instead of yield from in task z with z;yield was used instead of yield from for generator in task zTask got bad yield: )rK   sendthrowgetattrr   r0   rO   r-   rR   rS   rN   r   add_done_callback_Task__wakeuprJ   rI   r   r   inspectisgeneratorStopIterationr?   rx   rr   r   r   _cancelled_excKeyboardInterrupt
SystemExitr|   BaseException)rT   r   rU   rw   blockingnew_excrV   s         r'   __step_run_and_handle_result!Task.__step_run_and_handle_result*  s   zzG	{ 4C$ v'A4HH#$$V,DJJ>*x|!*$ACDG JJ((Wmm ) E~".;D8D#F

,, KK-- - I ;@700 MM4== 1 B+1(,,#//66(,(<(<  7  >49 1*##'(&
<=G JJ((Wmm ) E 

$$T[[$--$H$$V,,&))-vjBC 

$$KK-- % A ')=fZ'HI

$$KK-- % A DA  	.  $)!4#7#78"399--(( 	"%GN!:. 	G!#& 	'G!#&&	'd Dsk   &I< IM <
M/K5M :KM M/LM ML++M8MM MM Mc                      UR                  5         U R                  5         S n g ! [         a  nU R                  U5         S nAS n g S nAff = frb   )rw   rS   r   )rT   futurer   s      r'   __wakeupTask.__wakeupu  sH    	MMO KKM  	KK 	s   % 
AAA)
r   r   rN   rK   rJ   rC   r   rI   rF   rH   rb   )__name__
__module____qualname____firstlineno____doc__rC   r@   r_   classmethodr   __class_getitem__re   rh   rl   ro   rs   rx   r|   r   r   r   r   r   rQ   rS   r   r   __static_attributes____classcell__rV   s   @r'   r   r   G   s     +.  %)d"! !>	 $L1+ IL "& 7. $(d 	?(T++)&"IV r(   r   r9   r:   c                x    [         R                  " 5       nUc  UR                  XS9nU$ UR                  XUS9nU$ )zUSchedule the execution of a coroutine object in a spawn task.

Return a Task object.
)r9   r   )r   r"   r   )rU   r9   r:   r&   rY   s        r'   r   r     sM    
 ""$D0 K AKr(   )timeoutreturn_whenc                  #    [         R                  " U 5      (       d  [        R                  " U 5      (       a!  [	        S[        U 5      R                   35      eU (       d  [        S5      eU[        [        [        4;  a  [        SU 35      e[        U 5      n [        S U  5       5      (       a  [	        S5      e[        R                  " 5       n[        XX#5      I Sh  vN $  N7f)a7  Wait for the Futures or Tasks given by fs to complete.

The fs iterable must not be empty.

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.
zexpect a list of futures, not zSet of Tasks/Futures is empty.zInvalid return_when value: c              3   N   #    U  H  n[         R                  " U5      v   M     g 7frb   )r   rB   ).0fs     r'   	<genexpr>wait.<locals>.<genexpr>  s     
1b:!!!$$bs   #%z6Passing coroutines is forbidden, use tasks explicitly.N)r   isfuturer   rB   rD   typer   
ValueErrorr   r   r   setanyr   r"   _wait)fsr   r   r&   s       r'   r   r     s      z55b998b9J9J8KLMM9::?O]KK6{mDEE	RB

1b
111PQQ""$DrK6666s   CC' C%!C'c                 R    U R                  5       (       d  U R                  S 5        g g rb   )r1   rx   )waiterargss     r'   _release_waiterr     s     ;;==$ r(   c                   #    UbZ  US::  aT  [        U 5      n U R                  5       (       a  U R                  5       $ [        U 5      I Sh  vN    U R                  5       $ [        R                  " U5       ISh  vN   U I Sh  vN sSSS5      ISh  vN   $  NO! [        R
                   a  n[        UeSnAff = f ND N< N.! , ISh  vN  (       d  f       g= f7f)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.

If the task suppresses the cancellation and returns a value instead,
that value is returned.

This function is a coroutine.
Nr   )	r   r1   rw   _cancel_and_waitr   r   TimeoutErrorr    r   )futr   r   s      r'   r   r     s     F w!|C 88::::<s###	(::< ((y )(( 	$ (( 	(C'	( ) )(((s   AC
BCB C:B?;C>CCCCCCB<0B77B<<CCCCCCCc                 j  ^^^	^
#    U (       d   S5       eUR                  5       m
Sm	Ub  UR                  U[        T
5      m	[        U 5      mUUU	U
4S jnU  H  nUR	                  U5        M      T
I Sh  vN   T	b  T	R                  5         U  H  nUR                  U5        M     [        5       [        5       pvU  H<  nUR                  5       (       a  UR                  U5        M+  UR                  U5        M>     Xg4$  N! T	b  T	R                  5         U  H  nUR                  U5        M     f = f7f)zNInternal helper for wait().

The fs argument must be a collection of Futures.
zSet of Futures is empty.Nc                 
  > TS-  mTS::  d:  T[         :X  d0  T[        :X  ac  U R                  5       (       dM  U R                  5       b;  Tb  TR	                  5         TR                  5       (       d  TR                  S 5        g g g g g )Nr   r   )r   r   	cancelledr{   r   r1   rx   )r   counterr   timeout_handler   s    r'   _on_completion_wait.<locals>._on_completion	  sx    1qL?*?*AKKMM010I)%%';;==!!$' ! 1J 5B*r(   )
create_future
call_laterr   lenr   r   remove_done_callbackr   r1   add)r   r   r   r&   r   r   r1   pendingr   r   r   s     `     @@@r'   r   r     s    
 )))2!FN/6J"gG
( 
( 	N+ 3%!!#A"">2  E35'6688HHQKKKN	 
 = 	%!!#A"">2 s1   A)D30D 5C?6D :BD3?D /D00D3c                 6  #    [         R                  " 5       nUR                  5       n[        R                  " [
        U5      nU R                  U5         U R                  5         UI Sh  vN   U R                  U5        g N! U R                  U5        f = f7f)z<Cancel the *fut* future or task and wait until it completes.N)	r   r"   r   	functoolspartialr   r   r   r   )r   r&   r   cbs       r'   r   r   )  s|      ""$D!F			?F	3B"%

   $ 	  $s0   ABB *B+B /BB BBc                   L    \ rS rSrSrS rS rS rS rS r	S r
S	 rSS
 jrSrg)_AsCompletedIteratori:  a
  Iterator of awaitables representing tasks of asyncio.as_completed.

As an asynchronous iterator, iteration yields futures as they finish. As a
plain iterator, new coroutines are yielded that will return or raise the
result of the next underlying future to complete.
c                    [         R                  " 5       U l        S U l        [        R
                  " 5       n[        U5       Vs1 s H  n[        XCS9iM     nnU H  nUR                  U R                  5        M      U(       a#  Ub   UR                  X R                  5      U l        XPl        [        U5      U l        g s  snf Nr%   )r   Queue_done_timeout_handler   get_event_loopr   r   r   _handle_completionr   _handle_timeout_todor   
_todo_left)rT   awsr   r&   awtodor   s          r'   r@   _AsCompletedIterator.__init__A  s    \\^
#$$&7:3x@xb,x@A 7 78 G')=)=>   
d) As   B>c                     U $ rb    rd   s    r'   	__aiter___AsCompletedIterator.__aiter__P      r(   c                     U $ rb   r  rd   s    r'   __iter___AsCompletedIterator.__iter__S  r  r(   c                    #    U R                   (       d  [        eU R                   S:  d   eU =R                   S-  sl         U R                  5       I S h  vN $  N7f)Nr   r   )r   StopAsyncIteration_wait_for_onerd   s    r'   	__anext___AsCompletedIterator.__anext__V  sG     $$"""1''))))s   AAAAc                     U R                   (       d  [        eU R                   S:  d   eU =R                   S-  sl         U R                  SS9$ )Nr   r   T)resolve)r   r   r  rd   s    r'   __next___AsCompletedIterator.__next__]  sC    """1!!$!//r(   c                     U R                    H9  nUR                  U R                  5        U R                  R	                  S 5        M;     U R                   R                  5         g rb   )r   r   r   r   
put_nowaitclearrT   r   s     r'   r   $_AsCompletedIterator._handle_timeoutd  sH    A""4#:#:;JJ!!$'  	

r(   c                    U R                   (       d  g U R                   R                  U5        U R                  R                  U5        U R                   (       d)  U R                  b  U R                  R                  5         g g g rb   )r   remover   r  r   r   r  s     r'   r   '_AsCompletedIterator._handle_completionj  s[    zz

!

a zzd22>  '') ?zr(   c                    #    U R                   R                  5       I S h  vN nUc  [        R                  eU(       a  UR	                  5       $ U$  N07frb   )r   r$   r   r   rw   )rT   r  r   s      r'   r  "_AsCompletedIterator._wait_for_oner  sC      **..""9)))$qxxz+!+	 #s   AA1A)r   r   r   r   N)F)r   r   r   r   r   r@   r  r  r  r  r   r   r  r   r  r(   r'   r   r   :  s/    $*0*,r(   r   )r   c                    [         R                  " U 5      (       a!  [        S[        U 5      R                   35      e[        X5      $ )a  Create an iterator of awaitables or their results in completion order.

Run the supplied awaitables concurrently. The returned object can be
iterated to obtain the results of the awaitables as they finish.

The object returned can be iterated as an asynchronous iterator or a plain
iterator. When asynchronous iteration is used, the originally-supplied
awaitables are yielded if they are tasks or futures. This makes it easy to
correlate previously-scheduled tasks with their results:

    ipv4_connect = create_task(open_connection("127.0.0.1", 80))
    ipv6_connect = create_task(open_connection("::1", 80))
    tasks = [ipv4_connect, ipv6_connect]

    async for earliest_connect in as_completed(tasks):
        # earliest_connect is done. The result can be obtained by
        # awaiting it or calling earliest_connect.result()
        reader, writer = await earliest_connect

        if earliest_connect is ipv6_connect:
            print("IPv6 connection established.")
        else:
            print("IPv4 connection established.")

During asynchronous iteration, implicitly-created tasks will be yielded for
supplied awaitables that aren't tasks or futures.

When used as a plain iterator, each iteration yields a new coroutine that
returns the result or raises the exception of the next completed awaitable.
This pattern is compatible with Python versions older than 3.13:

    ipv4_connect = create_task(open_connection("127.0.0.1", 80))
    ipv6_connect = create_task(open_connection("::1", 80))
    tasks = [ipv4_connect, ipv6_connect]

    for next_connect in as_completed(tasks):
        # next_connect is not one of the original task objects. It must be
        # awaited to obtain the result value or raise the exception of the
        # awaitable that finishes next.
        reader, writer = await next_connect

A TimeoutError is raised if the timeout occurs before all awaitables are
done. This is raised by the async for loop during asynchronous iteration or
by the coroutines yielded during plain iteration.
z'expects an iterable of awaitables, not )r   isawaitablerD   r   r   r   )r   r   s     r'   r	   r	   }  sE    \ 25d2h6G6G5HI
 	
  ,,r(   c               #      #    Sv   g7f)zSkip 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'   __sleep0r    s
      
s   c                 ~  #    U S::  a  [        5       I Sh  vN   U$ [        R                  " U 5      (       a  [        S5      e[        R
                  " 5       nUR                  5       nUR                  U [        R                  X15      n UI Sh  vN UR                  5         $  N N! UR                  5         f = f7f)z9Coroutine that completes after a given time (in seconds).r   Nz!Invalid delay: NaN (not a number))r  mathisnanr   r   r"   r   r   r   _set_result_unless_cancelledr   )delayrw   r&   r   hs        r'   r
   r
     s     zjzz%<==""$D!F<<	(A|	
 	 	
s:   B=B$A2B=
B( B&B( B=&B( (B::B=r%   c                   [         R                  " U 5      (       a)  Ub$  U[         R                  " U 5      La  [        S5      eU $ Sn[        R
                  " U 5      (       d4  [        R                  " U 5      (       a  S nU" U 5      n SnO[        S5      eUc  [        R                  " 5       n UR                  U 5      $ ! [         a    U(       a  U R                  5         e f = f)zeWrap a coroutine or an awaitable in a future.

If the argument is a Future, it is returned directly.
zRThe future belongs to a different loop than the one specified as the loop argumentTc                 "   #    U I S h  vN $  N7frb   r  )	awaitables    r'   _wrap_awaitable&ensure_future.<locals>._wrap_awaitable  s     &&s   Fz:An asyncio.Future, a coroutine or an awaitable is required)r   r   r0   r   r   rB   r   r  rD   r   r   r   r-   close)coro_or_futurer&   should_closer)  s       r'   r   r     s    
 ''G,=,=n,M M E F FL!!.11~..' -^<N L * + + |$$&//   "s   /C   #C#c                   6   ^  \ rS rSrSrU 4S jrSS jrSrU =r$ )_GatheringFuturei  zHelper for gather().

This overrides cancel() to cancel all the children and act more
like Task.cancel(), which doesn't immediately mark itself as
cancelled.
c                D   > Uc   e[         TU ]  US9  Xl        SU l        g )Nr%   F)r?   r@   	_children_cancel_requested)rT   childrenr&   rV   s      r'   r@   _GatheringFuture.__init__  s,    d#!!&r(   c                     U R                  5       (       a  gSnU R                   H  nUR                  US9(       d  M  SnM     U(       a  SU l        U$ )NFr   T)r1   r1  r   r2  )rT   r   retchilds       r'   r   _GatheringFuture.cancel  sM    99;;^^E|||$$ $  &*D"
r(   )r2  r1  rb   )	r   r   r   r   r   r@   r   r   r   r   s   @r'   r/  r/    s    ' r(   r/  F)return_exceptionsc                   ^ ^^	^
^ U(       d8  [         R                  " 5       nUR                  5       mTR                  / 5        T$ UU	U
UU 4S jn0 n/ mSm
Sm	/ nSnSmU H  nXd;  ao  [	        XbS9nUc  [
        R                  " U5      nXvLa  SUl        T
S-  m
XtU'   UR                  5       (       a  UR                  U5        OUR                  U5        OXF   nTR                  U5        M     [        TUS9mU H  nU" U5        M     T$ )aM  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.
c                   > TS-  mTb  TR                  5       (       a&  U R                  5       (       d  U R                  5         g T(       d\  U R                  5       (       a"  U R                  5       nTR	                  U5        g U R                  5       nUb  TR	                  U5        g TT:X  a  / nT H|  n U R                  5       (       a0  [
        R                  " U R                  c  SOU R                  5      nO#U R                  5       nUc  U R                  5       nUR                  U5        M~     TR                  (       a"  U R                  5       nTR	                  U5        g TR                  U5        g g )Nr    )r1   r   r{   r   r|   r   r   r   rw   appendr2  rx   )	r   r   resultsresr3  	nfinishednfutsouterr9  s	       r'   _done_callbackgather.<locals>._done_callback4  s4   Q	=EJJLL==?? }} //1##C(mmo?'', G==?? %33!119++-C --/C{!jjls#  " && //1##C(  ); r(   r   Nr%   Fr   )r   r   r   rx   r   r   r0   rC   r1   r=  r   r/  )r9  coros_or_futuresr&   rC  
arg_to_fut	done_futsargr   r3  r@  rA  rB  s   `       @@@@r'   r   r     s   < $$&""$5* 5*n JHEIIDE /C|((-~
 ,1(QJE!sOxxzz  %%%n5 /C/  2 XD1E s Lr(   c                    ^^^ [        U 5      mTR                  5       (       a  T$ [        R                  " T5      nUR	                  5       mU4S jmUU4S jnTR                  T5        TR                  U5        T$ )a-  Wait for a future, shielding it from cancellation.

The statement

    task = asyncio.create_task(something())
    res = await shield(task)

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:

    task = asyncio.create_task(something())
    try:
        res = await shield(task)
    except CancelledError:
        res = None

Save a reference to tasks passed to this function, to avoid
a task disappearing mid-execution. The event loop only keeps
weak references to tasks. A task that isn't referenced elsewhere
may get garbage collected at any time, even before it's done.
c                 P  > TR                  5       (       a&  U R                  5       (       d  U R                  5         g U R                  5       (       a  TR                  5         g U R                  5       nUb  TR                  U5        g TR	                  U R                  5       5        g rb   )r   r{   r   r|   rx   rw   )innerr   rB  s     r'   _inner_done_callback$shield.<locals>._inner_done_callback  ss    ????$$!??LLN//#C##C(  0r(   c                 T   > TR                  5       (       d  TR                  T5        g g rb   )r1   r   )rB  rL  rK  s    r'   _outer_done_callback$shield.<locals>._outer_done_callback  s"    zz||&&';< r(   )r   r1   r   r0   r   r   )rH  r&   rO  rL  rK  rB  s      @@@r'   r   r     sm    B #Ezz||U#D E1"= 
01	01Lr(   c                    ^ ^^ [         R                  " T 5      (       d  [        S5      e[        R                  R                  5       mU UU4S jnTR                  U5        T$ )zkSubmit a coroutine object to a given event loop.

Return a concurrent.futures.Future to access the result.
zA coroutine object is requiredc                     >  [         R                  " [        TTS9T5        g ! [        [        4 a    e [
         a,  n TR                  5       (       a  TR                  U 5        e S n A ff = fr   )r   _chain_futurer   r   r   r   set_running_or_notify_cancelr|   )r   rU   r   r&   s    r'   callback*run_coroutine_threadsafe.<locals>.callback  s`    	!!-4"@&I-. 	 	2244$$S)	s   # A)'A$$A))r   rB   rD   
concurrentr   Futurecall_soon_threadsafe)rU   r&   rU  r   s   `` @r'   r   r     sP    
 !!$''899&&(F 	h'Mr(   c                    ^  SSS.U 4S jjnU$ )a  Create a function suitable for use as a task factory on an event-loop.

Example usage:

    loop.set_task_factory(
        asyncio.create_eager_task_factory(my_task_constructor))

Now, tasks created will be started immediately (rather than being first
scheduled to an event loop). The constructor argument can be any callable
that returns a Task-compatible object and has a signature compatible
with `Task.__init__`; it must have the `eager_start` keyword argument.

Most applications will use `Task` for `custom_task_constructor` and in
this case there's no need to call `create_eager_task_factory()`
directly. Instead the  global `eager_task_factory` instance can be
used. E.g. `loop.set_task_factory(asyncio.eager_task_factory)`.
Nr   c                   > T" XX#SS9$ )NTr8   r  )r&   rU   r9   r:   custom_task_constructors       r'   factory*create_eager_task_factory.<locals>.factory  s    &$TK 	Kr(   r  )r\  r]  s   ` r'   r   r     s    & %)$ K K Nr(   c                 0    [         R                  " U 5        g)z;Register an asyncio Task scheduled to run on an event loop.N)r,   r   rY   s    r'   r   r     s    r(   c                 0    [         R                  " U 5        g)z6Register an asyncio Task about to be eagerly executed.N)r+   r   r`  s    r'   r   r     s    Tr(   c                 p    [         R                  " U 5      nUb  [        SU< SU< S35      eU[         U '   g )NzCannot enter into task z while another task z is being executed.r#   r$   r-   r&   rY   r   s      r'   r   r   !  sL    !%%d+L4TH =##/"22EG H 	HN4r(   c                 n    [         R                  " U 5      nX!La  [        SU< SU< S35      e[         U 	 g )NzLeaving task z! does not match the current task .rc  rd  s      r'   r   r   )  sH    !%%d+L]4( 3//;.>aA B 	Btr(   c                 \    [         R                  " U 5      nUc	  [         U 	 U$ U[         U '   U$ rb   )r#   r$   )r&   rY   r   s      r'   r   r   1  s9    ""4(I|4    $tr(   c                 0    [         R                  " U 5        g)z'Unregister a completed, scheduled Task.N)r,   discardr`  s    r'   r   r   :  s    T"r(   c                 0    [         R                  " U 5        g)z6Unregister a task which finished its first eager step.N)r+   ri  r`  s    r'   r   r   ?  s    r(   )r   r   r   r   r   r   r   r,   r+   r#   r   rb   )Qr   __all__concurrent.futuresrW  rL   r   r   r.   r!  typesweakrefr   r<  r   r   r   r   r   r   r    countr  rE   r   r   	_PyFuturer   _PyTask_asyncio_CTaskImportErrorr   r   r   r   r   r   r   r   r   r   r	   	coroutiner  r
   r   rX  r/  r   r   r   r   r   WeakSetr,   r   r+   r#   r   r   r   r   r   r   r   _py_current_task_py_register_task_py_register_eager_task_py_unregister_task_py_unregister_eager_task_py_enter_task_py_leave_task_py_swap_current_task_c_current_task_c_register_task_c_register_eager_task_c_unregister_task_c_unregister_eager_task_c_enter_task_c_leave_task_c_swap_current_taskr  r(   r'   <module>r     sS   6                
 __Q'00 $>6|7 |~	 "
 MM!D6 #D " $$44$$44""00 # 7< 
0d)X%"@, @,F !% 3-l 
 
( +/ @w~~ : 16 CL?D.4 /t4  ??$ u 

 #

   " . & 2 * .( ( ( ( #O%1)5MM-g  		R  		s$   G
 G 
GGG G 