
    i                     Z   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddgZ e	d	          j
         e            d
<   ej         e            d<   ej         e            d<    G d de          Zd Z G d de
          Z G d de          ZddlmZ  e e            d           dS )z5
Iterators across greenlets or AsyncResult objects.

    )absolute_import)division)print_function)lock)queueIMapUnorderedIMapgeventGreenlet	SemaphoreUnboundQueuec                       e Zd ZdZddZdS )Failureexcraise_exceptionNc                 "    || _         || _        d S Nr   )selfr   r   s      7/usr/local/lib/python3.11/dist-packages/gevent/_imap.py__init__zFailure.__init__   s    .    r   )__name__
__module____qualname__	__slots__r    r   r   r   r      s-        *I/ / / / / /r   r   c                 J    | j         r|                                   d S | j        r   )r   r   )failures    r   
_raise_excr    $   s-     !!!!!kr   c                   `    e Zd ZdZddZd Zd ZeZd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd ZdS )r   z%
    At iterator of map results.
    NFc                     t                               |            || _        || _        || _        || _        t                      | _        |rt          |          | _	        nd| _	        d| _
        d| _        d| _        dS )a  
        An iterator that.

        :param callable spawn: The function we use to create new greenlets.
        :keyword int maxsize: If given and not-None, specifies the maximum number of
            finished results that will be allowed to accumulated awaiting the reader;
            more than that number of results will cause map function greenlets to begin
            to block. This is most useful is there is a great disparity in the speed of
            the mapping code and the consumer and the results consume a great deal of resources.
            Using a bound is more computationally expensive than not using a bound.

        .. versionchanged:: 1.1b3
            Added the *maxsize* parameter.
        Nr   F)r   r   spawn_zippedfunciterabler   r   r   _result_semaphore_outstanding_tasks
_max_indexfinished)r   r&   r'   r$   maxsizer%   s         r   r   zIMapUnordered.__init__0   s     	$
	 !^^
  	*  &/w%7%7D""%)D""# r   c                     | S r   r   r   s    r   __iter__zIMapUnordered.__iter__c   s    r   c                     | j         | j                                          |                                 }t          |t                    rt          |           |S r   )r(   release_inext
isinstancer   r    )r   values     r   __next__zIMapUnordered.__next__f   sR    !-"**,,,eW%% 	ur   c                 4    | j                                         S r   )r   getr.   s    r   r2   zIMapUnordered._inextp   s    z~~r   c                     | j         | j                                          | xj        dz  c_        | j        s|                     ||          n | j        |g|R  }||_        |                    | j                   |S N   )r(   acquirer)   r%   r$   _imap_task_indexrawlink
_on_result)r   r&   item
item_indexgs        r   _ispawnzIMapUnordered._ispawns   s    !-"**,,,1$*.,SDJJtT"""JDJt<Sd<S<S<S'			$/"""r   c                 z   	 | j         }| j        D ].}| xj        dz  c_        |                     ||| j                   /|                     d            n(# t
          $ r}|                     |            d }~ww xY w	 d | _        d | _         d | _        d | _        d S # d | _        d | _         d | _        d | _        w xY wr9   )r&   r'   r*   rB   
_on_finishBaseExceptionr$   r(   )r   r&   r?   es       r   _runzIMapUnordered._run|   s    	*9D : :1$T49999OOD!!!! 	 	 	OOA	 "
 DJDI DM%)D""" DJDI DM%)D"))))s*   AA B 
A:A55A::B B:c                    | xj         dz  c_         | j         }| j        }|                                 }d}|r|dk    r|sdx}| _        d}|                                r.| j                            |                     |                     n-| j                            |                     |                     |r.| j                            |                                            d S d S )Nr:   Fr   T)	r)   r+   ready
successfulr   put_iqueue_value_for_success_iqueue_value_for_failure_iqueue_value_for_self_finished)r   greenletcountr+   rI   put_finisheds         r   r>   zIMapUnordered._on_result   s    1$'=

 	 UaZZZ'++Ht}L   	EJNN499(CCDDDDJNN499(CCDDD 	CJNN4??AABBBBB	C 	Cr   c                    | j         rd S |6d| _         | j                            |                     |                     d S | j        dk    r5d| _         | j                            |                                            d S d S )NTr   )r+   r   rK   _iqueue_value_for_self_failurer)   rN   r   	exceptions     r   rD   zIMapUnordered._on_finish   s    = 	F  DMJNN4>>yIIJJJF"a'' DMJNN4??AABBBBB ('r   c                     |j         S r   )r4   r   rO   s     r   rL   z'IMapUnordered._iqueue_value_for_success   s
    ~r   c                 H    t          |j        t          |d                    S )N_raise_exception)r   rU   getattrrW   s     r   rM   z'IMapUnordered._iqueue_value_for_failure   s     x)78=O+P+PQQQr   c                 8    t          t                                S r   )r   StopIterationr.   s    r   rN   z-IMapUnordered._iqueue_value_for_self_finished   s    }'''r   c                 ,    t          || j                  S r   )r   rY   rT   s     r   rS   z,IMapUnordered._iqueue_value_for_self_failure   s    y$"7888r   )NF)r   r   r   __doc__r   r/   r5   nextr2   rB   rG   r>   rD   rL   rM   rN   rS   r   r   r   r   r   +   s         / / / /f     D       * * * C C C(C C C  R R R( ( (9 9 9 9 9r   c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )r	   c                 L    i | _         d| _        t          j        | g|R i | d S )Nr   )_resultsindexr   r   )r   argskwargss      r   r   zIMap.__init__   s9     
t5d555f55555r   c                     	 | j                             | j                  }nD# t          $ r7 	 | j                                        \  }}|| j        k    rn|| j         |<   3Y nw xY w| xj        dz  c_        |S r9   )rb   poprc   KeyErrorr   r7   )r   r4   rc   s      r   r2   zIMap._inext   s    	-M%%dj11EE 	- 	- 	--#z~~//uDJ&&',e$	- E	- 	

a

s   " >A#"A#c                 F    |j         t                              | |          fS r   )r<   r   rL   rW   s     r   rL   zIMap._iqueue_value_for_success   "    )=+R+RSWYa+b+bccr   c                 F    |j         t                              | |          fS r   )r<   r   rM   rW   s     r   rM   zIMap._iqueue_value_for_failure   rj   r   c                 J    | j         dz   t                              |           fS r9   )r*   r   rN   r.   s    r   rN   z$IMap._iqueue_value_for_self_finished   s#    !#]%R%RSW%X%XYYr   c                 L    | j         dz   t                              | |          fS r9   )r*   r   rS   rT   s     r   rS   z#IMap._iqueue_value_for_self_failure   s&    !#]%Q%QRVXa%b%bccr   N)	r   r   r   r   r2   rL   rM   rN   rS   r   r   r   r	   r	      s|        
6 6 6  d d dd d dZ Z Zd d d d dr   )import_c_accelzgevent.__imapN)r^   
__future__r   r   r   r
   r   r   __all__
__import__r   localsr   r   objectr   r    r   r	   gevent._utilrn   globalsr   r   r   <module>rv      s  
  ' & & & & &       % % % % % %             

 "z(++4   - / / / / /f / / /  M9 M9 M9 M9 M9H M9 M9 M9`$d $d $d $d $d= $d $d $dL ( ' ' ' ' ' wwyy/ * * * * *r   