
    ?f               
       x   d Z ddlZddlZddlmZmZmZmZmZm	Z	m
Z
mZmZmZmZ ddlmZmZ ddlmZmZmZmZ ddde
ee                  d	ee         d
ee         fdZddde
ee                  ded
ee         fdZddddee         deded
ee         fdZ	 	 ddeee                  deded
ee         fdZdS )zt
Friendlier version of asyncio standard library.

Provisional library.  Must be imported as `aioitertools.asyncio`.
    N)AnyAsyncGeneratorAsyncIterable	AwaitablecastDictIterableListOptionalSetTuple   )itermaybe_await)AnyIterableAsyncIteratorMaybeAwaitableT)timeoutawsr   returnc               p  K   t                      }d | D             }d}|r|dk    rt          j                    |z   }nd}|r|rc|t          j                    z
  }|dk    rG|D ]1}t          |t          j                  r|                                 12t          j                    t          t          t          t          t                            t          t          t                            f         t          j        ||t          j                   d{V           \  }}|D ]}| d{V W V  |dS dS )a  
    Run awaitables in `aws` concurrently, and yield results as they complete.

    Unlike `asyncio.as_completed`, this yields actual results, and does not require
    awaiting each item in the iterable.

    Cancels all remaining awaitables if a timeout is given and the timeout threshold
    is reached.

    Example::

        async for value in as_completed(futures):
            ...  # use value immediately

    c                 6    h | ]}t          j        |          S  asyncioensure_future).0as     c/home/panchajanya/Development/work/volatility3/lib/python3.11/site-packages/aioitertools/asyncio.py	<setcomp>zas_completed.<locals>.<setcomp>3   s#    !H!H!Hq'"7":":!H!H!H    Nr   )r   return_when)settime
isinstancer   FuturecancelTimeoutErrorr   r   r   r   r   waitFIRST_COMPLETED)r   r   donepending	remaining	thresholdfutitems           r    as_completedr2      s|     ( "eeD!H!HC!H!H!HG!%I 7Q;;IKK')		
  	-!DIKK/IA~~"  C!#w~66 

*,,, #il#S1%667,!#3        
 
g  	 	D******9      r"   F)return_exceptions	iterablesr3   c                 	K   t          j                    t          j                    dt          t                   ddffd		fd| D             }t	          |          }	 |r	                                 }|r|W V  n|n# t           j        $ r Y nw xY w	                                 }|W V  nj# t           j        $ rX t          |          D ]+}|                                r|	                    |           ,t          j
        d           d{V  Y nw xY w|n# t           j        t          f$ r Y nw xY w|D ]*}|                                s|                                 +|D ] }	 | d{V  # t           j        $ r Y w xY wdS # |D ]*}|                                s|                                 +|D ] }	 | d{V  # t           j        $ r Y w xY ww xY w)ao  
    Yield results from one or more async iterables, in the order they are produced.

    Like :func:`as_completed`, but for async iterators or generators instead of futures.
    Creates a separate task to drain each iterable, and a single queue for results.

    If ``return_exceptions`` is ``False``, then any exception will be raised, and
    pending iterables and tasks will be cancelled, and async generators will be closed.
    If ``return_exceptions`` is ``True``, any exceptions will be yielded as results,
    and execution will continue until all iterables have been fully consumed.

    Example::

        async def generator(x):
            for i in range(x):
                yield i

        gen1 = generator(10)
        gen2 = generator(12)

        async for value in as_generated([gen1, gen2]):
            ...  # intermixed values yielded from gen1 and gen2
    r   r   Nc                 <  K   	 | 2 3 d {V }                     |           d {V  #6 d S # t          j        $ r1 t          | t                    r|                                  d {V   t          $ r&}                     |           d {V  Y d }~d S d }~ww xY wN)putr   CancelledErrorr&   r   aclose	Exception)r   r1   e	exc_queuequeues      r    tailerzas_generated.<locals>.tailerz   s     	#" & & & & & & &diioo%%%%%%%% #dd% 	 	 	$// $kkmm####### 	# 	# 	#--"""""""""""""""	#s   - *- AB5BBc                 J    g | ]}t          j         |                     S r   r   )r   r   r?   s     r    
<listcomp>z as_generated.<locals>.<listcomp>   s,    GGGTW"66$<<00GGGr"   gMbP?)r   Queuer   r   r$   
get_nowait
QueueEmptylistr,   removesleepr9   GeneratorExitr(   )
r4   r3   tasksr-   excvaluetaskr=   r>   r?   s
          @@@r    as_generatedrM   Z   s     : +2-//I%mooE	#=+ 	# 	# 	# 	# 	# 	# 	# 	# HGGGYGGGE%jjG  	+**,,$ IIIIII  %   +((**% + + + MM - -Dyy{{ -t,,,mE***********	+  	+& "M2     	 	D99;;  	 	D







)   	 		  	 	D99;;  	 	D







)   	s   %D$ (B D$ BD$ BD$ B7 6D$ 7A$DD$ DD$ #F $D=:F <D==F 2E;;FF2G$GG$G 	G$G 	 G$r3   limitargsrP   c                 b  K   i }i }dgt          |          z  }t                      }t                      }d}	 |t          |          k     r|dk    st          |          |k     r||         |v r"|||                                      |           n@t          j        ||                   }	|                    |	           |||	<   |g|||         <   |dz  }|t          |          k     r|dk    t          |          |k     |r	 t          j        |t          j                   d{V \  }}|D ]S}
| r2|
                                r|
                                |||
         <   6|
	                                |||
         <   TnD# t          j
        $ r2 |D ]}
|
                                 t          j        |ddi d{V   w xY w|s|t          |          k    rn|                                D ]9}t          dt          |                    D ]}||d                  |||         <   :|S )aR  
    Like asyncio.gather but with a limit on concurrency.

    Note that all results are buffered.

    If gather is cancelled all tasks that were internally created and still pending
    will be cancelled as well.

    Example::

        futures = [some_coro(i) for i in range(10)]

        results = await gather(*futures, limit=2)
    Nr   TrN   r   )r#   r3   )lenr$   appendr   r   addr*   r+   	exceptionresultr9   r(   gathervaluesrange)r3   rP   rQ   	input_mapposretr-   r,   next_argrL   xlstis                r    rX   rX      s     * 02I(*CVc$ii'C&)eeG#&55DH'T""s7||e7K7K H~**$x.)00:::: +2*?X*O*OD!!!$D	-5J	$x.)MH T""s7||e7K7K&  	&-l)@' ' ' ! ! ! ! ! !g  1 1A( 1Q[[]] 1&'kkmmCF&'hhjjCF	1
 )      AHHJJJJngFFFFFFFFFF  	8s4yy00O'R !! & &q#c((## 	& 	&Ac!f+CAKK	& Js   A?F AGitrc                 f   K   t          d t          |           2              d{V ||d d{V S )z
    Wrapper around gather to handle gathering an iterable instead of *args.

    Note that the iterable values don't have to be awaitable.
    c                 <   K   g | 3 d {V }t          |          6 S r7   )r   )r   ra   s     r    rA   zgather_iter.<locals>.<listcomp>  s4      	3	3	3	3	3	3	3	31+a..	3	3	3	3s   NrO   )rX   aiter)rb   r3   rP   s      r    gather_iterrf      sl       	3	3c

	3	3	3	3	3	3	3	3	3+         r"   )FrN   )__doc__r   r%   typingr   r   r   r   r   r   r	   r
   r   r   r   builtinsr   re   r   typesr   r   r   r   floatr2   boolrM   intrX   rf   r   r"   r    <module>rn      sG                               1 0 0 0 0 0 0 0 @ @ @ @ @ @ @ @ @ @ @ @  $9 9 9	)A,	9 e_9 1	9 9 9 9~ $N N Na()N N 1	N N N Nf $L L LQ<LL L 
#Y	L L L Lb $ 	^A&	'  
!W	     r"   