
    ;e1Y              
          d Z ddlZddlZddlZddlZddlZdZdZdZdZ	dZ
dZd	Zd
ZdZe
eeeegZe
dedededediZ ej        d          Z G d de          Z G d de          ZeZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d e          Zd! Zd" Zd.d#Z  ej!        d$d%          Z"defd&Z#d.d'Z$ G d( d)e          Z% G d* d+e          Z& G d, d-e'          Z(dS )/z"Brian Quinlan (brian@sweetapp.com)    NFIRST_COMPLETEDFIRST_EXCEPTIONALL_COMPLETED_AS_COMPLETEDPENDINGRUNNING	CANCELLEDCANCELLED_AND_NOTIFIEDFINISHEDpendingrunning	cancelledfinishedzconcurrent.futuresc                       e Zd Z	 dS )ErrorN__name__
__module____qualname__     //usr/lib/python3.11/concurrent/futures/_base.pyr   r   -   s        7Dr   r   c                       e Zd Z	 dS )CancelledErrorNr   r   r   r   r   r   1   s        #Dr   r   c                       e Zd Z	 dS )InvalidStateErrorNr   r   r   r   r   r   7   s        5Dr   r   c                   (    e Zd Z	 d Zd Zd Zd ZdS )_Waiterc                 D    t          j                    | _        g | _        d S N)	threadingEventeventfinished_futuresselfs    r   __init__z_Waiter.__init__=   s    _&&
 "r   c                 :    | j                             |           d S r    r$   appendr&   futures     r   
add_resultz_Waiter.add_resultA       $$V,,,,,r   c                 :    | j                             |           d S r    r)   r+   s     r   add_exceptionz_Waiter.add_exceptionD   r.   r   c                 :    | j                             |           d S r    r)   r+   s     r   add_cancelledz_Waiter.add_cancelledG   r.   r   N)r   r   r   r'   r-   r0   r2   r   r   r   r   r   ;   sS        E# # #- - -- - -- - - - -r   r   c                   >     e Zd Z	  fdZ fdZ fdZ fdZ xZS )_AsCompletedWaiterc                     t          t          |                                            t          j                    | _        d S r    )superr4   r'   r!   Locklock)r&   	__class__s    r   r'   z_AsCompletedWaiter.__init__M   s3     $''00222N$$			r   c                     | j         5  t          t          |                               |           | j                                         d d d            d S # 1 swxY w Y   d S r    )r8   r6   r4   r-   r#   setr&   r,   r9   s     r   r-   z_AsCompletedWaiter.add_resultQ   s    Y 	 	$d++66v>>>JNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   AAAAc                     | j         5  t          t          |                               |           | j                                         d d d            d S # 1 swxY w Y   d S r    )r8   r6   r4   r0   r#   r;   r<   s     r   r0   z _AsCompletedWaiter.add_exceptionV       Y 	 	$d++99&AAAJNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r=   c                     | j         5  t          t          |                               |           | j                                         d d d            d S # 1 swxY w Y   d S r    )r8   r6   r4   r2   r#   r;   r<   s     r   r2   z _AsCompletedWaiter.add_cancelled[   r?   r=   )r   r   r   r'   r-   r0   r2   __classcell__r9   s   @r   r4   r4   J   s        !% % % % %    
    
        r   r4   c                   4     e Zd Z	  fdZ fdZ fdZ xZS )_FirstCompletedWaiterc                 |    t                                          |           | j                                         d S r    )r6   r-   r#   r;   r<   s     r   r-   z _FirstCompletedWaiter.add_resultc   s3    6"""
r   c                 |    t                                          |           | j                                         d S r    )r6   r0   r#   r;   r<   s     r   r0   z#_FirstCompletedWaiter.add_exceptiong   3    f%%%
r   c                 |    t                                          |           | j                                         d S r    )r6   r2   r#   r;   r<   s     r   r2   z#_FirstCompletedWaiter.add_cancelledk   rG   r   )r   r   r   r-   r0   r2   rA   rB   s   @r   rD   rD   `   sm        4                r   rD   c                   D     e Zd Z	  fdZd Z fdZ fdZ fdZ xZS )_AllCompletedWaiterc                     || _         || _        t          j                    | _        t                                                       d S r    )num_pending_callsstop_on_exceptionr!   r7   r8   r6   r'   )r&   rL   rM   r9   s      r   r'   z_AllCompletedWaiter.__init__r   s>    !2!2N$$	r   c                     | j         5  | xj        dz  c_        | j        s| j                                         d d d            d S # 1 swxY w Y   d S )N   )r8   rL   r#   r;   r%   s    r   _decrement_pending_callsz,_AllCompletedWaiter._decrement_pending_callsx   s    Y 	! 	!""a'"") !
   	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!s   1AA
A
c                 r    t                                          |           |                                  d S r    )r6   r-   rP   r<   s     r   r-   z_AllCompletedWaiter.add_result~   s3    6"""%%'''''r   c                     t                                          |           | j        r| j                                         d S |                                  d S r    )r6   r0   rM   r#   r;   rP   r<   s     r   r0   z!_AllCompletedWaiter.add_exception   sV    f%%%! 	,JNN))+++++r   c                 r    t                                          |           |                                  d S r    )r6   r2   rP   r<   s     r   r2   z!_AllCompletedWaiter.add_cancelled   s3    f%%%%%'''''r   )	r   r   r   r'   rP   r-   r0   r2   rA   rB   s   @r   rJ   rJ   o   s        F    ! ! !( ( ( ( (, , , , ,( ( ( ( ( ( ( ( (r   rJ   c                   "    e Zd Z	 d Zd Zd ZdS )_AcquireFuturesc                 <    t          |t                    | _        d S )N)key)sortedidfutures)r&   rZ   s     r   r'   z_AcquireFutures.__init__   s    g2...r   c                 L    | j         D ]}|j                                         d S r    )rZ   
_conditionacquirer+   s     r   	__enter__z_AcquireFutures.__enter__   5    l 	( 	(F%%''''	( 	(r   c                 L    | j         D ]}|j                                         d S r    )rZ   r\   release)r&   argsr,   s      r   __exit__z_AcquireFutures.__exit__   r_   r   N)r   r   r   r'   r^   rc   r   r   r   rU   rU      sD        N/ / /( ( (( ( ( ( (r   rU   c                 v   |t           k    rt                      }n|t          k    rt                      }net	          d | D                       }|t
          k    rt          |d          }n/|t          k    rt          |d          }nt          d|z            | D ]}|j	        
                    |           |S )Nc              3   @   K   | ]}|j         t          t          fvV  d S r    _stater
   r   .0fs     r   	<genexpr>z._create_and_install_waiters.<locals>.<genexpr>   sH       P PGH!7 BBP P P P P Pr   T)rM   FzInvalid return condition: %r)r   r4   r   rD   sumr   rJ   r   
ValueError_waitersr*   )fsreturn_whenwaiterpending_countrj   s        r   _create_and_install_waitersrs      s    m###%%		'	'&(( P PLNP P P P P /))($OOOFFM))(%PPPFF;kIJJJ " "	
&!!!!Mr   c              #      K   	 | rv| d         }|D ]}|                     |           |j        5  |j                             |           d d d            n# 1 swxY w Y   ~|                                 V  | td S d S )N)remover\   rn   pop)ro   rq   ref_collectrj   futures_sets        r   _yield_finished_futuresrz      s      	  rF& 	" 	"Kq!!!!\ 	& 	&Jf%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&ffhh      s   AAAc           	   #   (  K   	 ||t          j                    z   }t          |           } t          |           }t	          |           5  t          d | D                       }| |z
  }t          | t                    }d d d            n# 1 swxY w Y   t          |          }	 t          ||| f          E d {V  |r|d }n=|t          j                    z
  }|dk     r!t          dt          |          |fz            |j
                            |           |j        5  |j        }g |_        |j
                                         d d d            n# 1 swxY w Y   |                                 t          ||| |f          E d {V  || D ];}|j        5  |j                            |           d d d            n# 1 swxY w Y   <d S # | D ];}|j        5  |j                            |           d d d            n# 1 swxY w Y   <w xY w)Nc              3   D   K   | ]}|j         t          t          fv |V  d S r    rf   rh   s     r   rk   zas_completed.<locals>.<genexpr>   sE       C C8 6AAA AAAAC Cr   )rx   r   z%d (of %d) futures unfinished)time	monotonicr;   lenrU   rs   r   listrz   TimeoutErrorr#   waitr8   r$   clearreverser\   rn   rv   )	ro   timeoutend_timetotal_futuresr   r   rq   wait_timeoutrj   s	            r   as_completedr      s     " T^---	RBGGM			 @ @ C CC C C C C x-,R??@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ H~~H**8V8:u> > > 	> 	> 	> 	> 	> 	> 	>  	J#'$.*:*::!##&;LL-?9 9: : : Ll+++ % %!2*,'""$$$% % % % % % % % % % % % % % % .x<>=J J J J J J J J J J'  	J0  	* 	*A * *
!!&)))* * * * * * * * * * * * * * *	* 	* 	* 	*A * *
!!&)))* * * * * * * * * * * * * * *	*sy   	4B		BB$A>G "(E
G EG E3G GG	
G	HH	8HHHHHDoneAndNotDoneFutureszdone not_donec                 
   	 t          |           } t          |           5  d | D             }| |z
  }|t          k    r|rt          ||          cd d d            S |t          k    r7|r5t          d |D                       rt          ||          cd d d            S t          |          t          |           k    rt          ||          cd d d            S t          | |          }d d d            n# 1 swxY w Y   |j        	                    |           | D ];}|j
        5  |j                            |           d d d            n# 1 swxY w Y   <|                    |j                   t          || |z
            S )Nc                 <    h | ]}|j         t          t          fv |S r   rf   rh   s     r   	<setcomp>zwait.<locals>.<setcomp>"  s7     F F Fah#98"DDD DDDr   c              3   j   K   | ].}|                                 s|                                *|V  /d S r    )r   	exceptionrh   s     r   rk   zwait.<locals>.<genexpr>(  sP       G G++--G,-KKMM,E ,E,E,E,EG Gr   )r;   rU   r   r   r   anyr   rs   r#   r   r\   rn   rv   updater$   )ro   r   rp   donenot_donerq   rj   s          r   r   r     s   0 
RB			 > >F F2 F F F9?***(x88> > > > > > > > _,,$, G Gd G G G G G =,T8<<> > > > > > > > t99B(x88> > > > > > > > -R==> > > > > > > > > > > > > > >  Lg & &\ 	& 	&Jf%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	KK'((( rDy111s5   .C55C5/C5C55C9<C9%EE	E	c                     	 	 |                      |          |                                  ~ S # |                                  w xY w# ~ w xY wr    )resultcancel)futr   s     r   _result_or_cancelr   :  sR    	::g&&JJLLL C JJLLLL s   - A AA A	c                       e Zd Z	 d Zd Zd Zd Zd Zd Zd Z	d Z
d	 ZddZddZd Zd Zd Z eej                  Zd
S )Futurec                     	 t          j                    | _        t          | _        d | _        d | _        g | _        g | _        d S r    )	r!   	Conditionr\   r   rg   _result
_exceptionrn   _done_callbacksr%   s    r   r'   zFuture.__init__H  s?    F#-//!r   c                     | j         D ]9}	  ||            # t          $ r t                              d|            Y 6w xY wd S Nz!exception calling callback for %r)r   	ExceptionLOGGERr   )r&   callbacks     r   _invoke_callbackszFuture._invoke_callbacksQ  ss    , 	L 	LHL L L L  !DdKKKKKL	L 	Ls   %??c                    | j         5  | j        t          k    r| j        rKd| j        j        t          |           t          | j                 | j        j        j        fz  cd d d            S d| j        j        t          |           t          | j                 | j        j        j        fz  cd d d            S d| j        j        t          |           t          | j                 fz  cd d d            S # 1 swxY w Y   d S )Nz<%s at %#x state=%s raised %s>z <%s at %#x state=%s returned %s>z<%s at %#x state=%s>)	r\   rg   r   r   r9   r   rY   _STATE_TO_DESCRIPTION_MAPr   r%   s    r   __repr__zFuture.__repr__X  sh   _ 	; 	;{h&&? 9;/41$+>1:	?< <	; 	; 	; 	; 	; 	; 	; 	; >/41$+>.7	A9 9	; 	; 	; 	; 	; 	; 	; 	; *N+tHH,T[9-; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;s   AC1+>C16.C11C58C5c                 D   	 | j         5  | j        t          t          fv r	 d d d            dS | j        t          t
          fv r	 d d d            dS t          | _        | j                                          d d d            n# 1 swxY w Y   |                                  dS )NFT)r\   rg   r   r   r	   r
   
notify_allr   r%   s    r   r   zFuture.cancell  s   	
 _ 	) 	){w111	) 	) 	) 	) 	) 	) 	) 	) {y*@AAA	) 	) 	) 	) 	) 	) 	) 	) $DKO&&(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	   ts   BB%BBBc                 p    	 | j         5  | j        t          t          fv cd d d            S # 1 swxY w Y   d S r    )r\   rg   r	   r
   r%   s    r   r   zFuture.cancelled  s    6_ 	F 	F;9.D"EE	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   +//c                 f    	 | j         5  | j        t          k    cd d d            S # 1 swxY w Y   d S r    )r\   rg   r   r%   s    r   r   zFuture.running  s{    ?_ 	* 	*;')	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   &**c                 |    	 | j         5  | j        t          t          t          fv cd d d            S # 1 swxY w Y   d S r    )r\   rg   r	   r
   r   r%   s    r   r   zFuture.done  s    L_ 	P 	P;9.Dh"OO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps   155c                 <    | j         r	 | j         # d } w xY w| j        S r    )r   r   r%   s    r   __get_resultzFuture.__get_result  s1    ? 	 o% <s    c                 >   	 | j         5  | j        t          t          t          fvr(| j                            |           	 d d d            d S 	 d d d            n# 1 swxY w Y   	  ||            d S # t          $ r t          	                    d|            Y d S w xY wr   )
r\   rg   r	   r
   r   r   r*   r   r   r   )r&   fns     r   add_done_callbackzFuture.add_done_callback  s   		 _ 	 	{9.Dh"OOO$++B///	 	 	 	 	 	 	 	O	 	 	 	 	 	 	 	 	 	 	 	 	 	 		HBtHHHHH 	H 	H 	H@$GGGGGG	Hs#   7AA!A&A3 3%BBNc                    	 	 | j         5  | j        t          t          fv rt	                      | j        t
          k    r"|                                 cd d d            d } S | j                             |           | j        t          t          fv rt	                      | j        t
          k    r"|                                 cd d d            d } S t                      # 1 swxY w Y   	 d } d S # d } w xY wr    )	r\   rg   r	   r
   r   r   _Future__get_resultr   r   r&   r   s     r   r   zFuture.result  sU   		 ) );9.D"EEE(***[H,,,,..	) ) ) ) ) ) )  DD $$W---;9.D"EEE(***[H,,,,..) ) ) ) ) ) )  DD '..() ) ) ) ) ) ) ) )  DDD4DKKKKsB   C- ACC-  A C C- CC!!C- $C!%C- -C1c                    	 | j         5  | j        t          t          fv rt	                      | j        t
          k    r| j        cd d d            S | j                             |           | j        t          t          fv rt	                      | j        t
          k    r| j        cd d d            S t                      # 1 swxY w Y   d S r    )	r\   rg   r	   r
   r   r   r   r   r   r   s     r   r   zFuture.exception  s#   	" _ 	% 	%{y*@AAA$&&&((		% 	% 	% 	% 	% 	% 	% 	% O  ))){y*@AAA$&&&((	% 	% 	% 	% 	% 	% 	% 	% #nn$	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s   :B>AB>0B>>CCc                    	 | j         5  | j        t          k    r9t          | _        | j        D ]}|                    |            	 d d d            dS | j        t          k    rt          | _        	 d d d            dS t          	                    dt          |           | j                   t          d          # 1 swxY w Y   d S )NFTz!Future %s in unexpected state: %szFuture in unexpected state)r\   rg   r	   r
   rn   r2   r   r   r   criticalrY   RuntimeError)r&   rq   s     r   set_running_or_notify_cancelz#Future.set_running_or_notify_cancel  sM   	, _ 	A 	A{i''4"m / /F((.... 	A 	A 	A 	A 	A 	A 	A 	A ''%	A 	A 	A 	A 	A 	A 	A 	A  C "4 $- - - ##?@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	As   =B:B:==B::B>B>c                    	 | j         5  | j        t          t          t          hv r(t          d                    | j        |                     || _        t          | _        | j        D ]}|	                    |            | j         
                                 d d d            n# 1 swxY w Y   |                                  d S Nz{}: {!r})r\   rg   r	   r
   r   r   formatr   rn   r-   r   r   )r&   r   rq   s      r   
set_resultzFuture.set_result  s    	 _ 	) 	){y*@(KKK'
(9(9$+t(L(LMMM!DL"DK- ( (!!$''''O&&(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	        BB$$B(+B(c                    	 | j         5  | j        t          t          t          hv r(t          d                    | j        |                     || _        t          | _        | j        D ]}|	                    |            | j         
                                 d d d            n# 1 swxY w Y   |                                  d S r   )r\   rg   r	   r
   r   r   r   r   rn   r0   r   r   )r&   r   rq   s      r   set_exceptionzFuture.set_exception(  s    	 _ 	) 	){y*@(KKK'
(9(9$+t(L(LMMM'DO"DK- + +$$T****O&&(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	     r   r    )r   r   r   r'   r   r   r   r   r   r   r   r   r   r   r   r   r   classmethodtypesGenericAlias__class_getitem__r   r   r   r   r   E  s       ?" " "L L L; ; ;(  &F F F
* * *
P P P
     H H H(! ! ! !F% % % %D&A &A &AP! ! !! ! ! $E$677r   r   c                   >    e Zd Z	 d ZddddZdddd	Zd
 Zd ZdS )Executorc                     	 t                      r    )NotImplementedError)r&   r   rb   kwargss       r   submitzExecutor.submit<  s    	 "###r   NrO   )r   	chunksizec                     	 t          j                    z    fdt          | D             fd} |            S )Nc                 ,    g | ]} j         g|R  S r   )r   )ri   rb   r   r&   s     r   
<listcomp>z Executor.map.<locals>.<listcomp>`  s-    AAAkdk"$t$$$AAAr   c               3   h  K   	                                   r`$t                                                    V  n8t                                          t          j                    z
            V  `D ]} |                                  d S # D ]} |                                  w xY wr    )r   r   rw   r}   r~   r   )r,   r   ro   r   s    r   result_iteratorz%Executor.map.<locals>.result_iteratord  s      $

 W/999999/(T^EUEU:UVVVVV  W ! $ $FMMOOOO$ $b $ $FMMOOOO$s   A6B B1)r}   r~   zip)r&   r   r   r   	iterablesr   r   ro   s   ```   @@r   mapzExecutor.mapG  sy    	* !1!11HAAAAAiAAA	$ 	$ 	$ 	$ 	$ 	$ 	$    r   TF)cancel_futuresc                    	 d S r    r   )r&   r   r   s      r   shutdownzExecutor.shutdowns  s    	 	r   c                     | S r    r   r%   s    r   r^   zExecutor.__enter__  s    r   c                 2    |                      d           dS )NT)r   F)r   )r&   exc_typeexc_valexc_tbs       r   rc   zExecutor.__exit__  s    4   ur   )T)r   r   r   r   r   r   r^   rc   r   r   r   r   r   9  s        M	$ 	$ 	$ +/! *! *! *! *! *!XE            r   r   c                       e Zd ZdS )BrokenExecutorNr   r   r   r   r   r     s         r   r   r    ))
__author__collectionsloggingr!   r}   r   r   r   r   r   r   r   r	   r
   r   _FUTURE_STATESr   	getLoggerr   r   r   r   r   r   objectr   r4   rD   rJ   rU   rs   rz   r   
namedtupler   r   r   r   r   r   r   r   r   r   <module>r      s-   2
           ## 
	1   YY{Kj  
	/	0	0	 	 	 	 	I 	 	 		 	 	 	 	U 	 	 	 	 	 	 	 	 	 	 	- - - - -f - - -       ,    G   ( ( ( ( (' ( ( (<( ( ( ( (f ( ( (  ,  ,<* <* <* <*| /.2 2 } 02 02 02 02f   r8 r8 r8 r8 r8V r8 r8 r8hO O O O Ov O O Od    \     r   