o
    0×¾gø  ã                   @   sÄ   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„ deƒZdd„ ZG dd„ de
ƒZG d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                   @   s   e Zd ZdZddd„ZdS )ÚFailure©ÚexcÚraise_exceptionNc                 C   s   || _ || _d S ©Nr   )Úselfr   r   © r   úV/var/www/html/backend_erp/backend_erp_env/lib/python3.10/site-packages/gevent/_imap.pyÚ__init__   s   
zFailure.__init__r   )Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r   r   r   r   r   r      s    r   c                 C   s   | j r	|   ¡  d S | j‚r   )r   r   )Úfailurer   r   r   Ú
_raise_exc$   s   r   c                   @   sv   e Zd ZdZddd„Zdd„ Zdd	„ ZeZd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r   z%
    At iterator of map results.
    NFc                 C   sV   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   r   r   r   r   0   s   

zIMapUnordered.__init__c                 C   s   | S r   r   ©r   r   r   r   Ú__iter__c   s   zIMapUnordered.__iter__c                 C   s2   | j d ur
| j  ¡  |  ¡ }t|tƒrt|ƒ |S r   )r!   ÚreleaseÚ_inextÚ
isinstancer   r   )r   Úvaluer   r   r   Ú__next__f   s   


zIMapUnordered.__next__c                 C   s
   | j  ¡ S r   )r   Úgetr&   r   r   r   r)   p   ó   
zIMapUnordered._inextc                 C   s\   | j d ur
| j  ¡  |  jd7  _| js|  ||¡n| j|g|¢R Ž }||_| | j¡ |S ©Né   )r!   Úacquirer"   r   r   Ú_imap_task_indexÚrawlinkÚ
_on_result)r   r   ÚitemÚ
item_indexÚgr   r   r   Ú_ispawns   s   

$zIMapUnordered._ispawnc              
   C   sž   zAz| j }| jD ]}|  jd7  _|  ||| j¡ q|  d ¡ W n ty2 } z|  |¡ ‚ d }~ww W d | _d | _ d | _d | _d S d | _d | _ d | _d | _w r/   )r   r    r#   r8   Ú
_on_finishÚBaseExceptionr   r!   )r   r   r5   Úer   r   r   Ú_run|   s(   

€þÿ
ýzIMapUnordered._runc                 C   sŽ   |  j d8  _ | j }| j}|  ¡ }d}|r"|dkr"|s"d }| _d}| ¡ r0| j |  |¡¡ n	| j |  |¡¡ |rE| j |  ¡ ¡ d S d S )Nr0   Fr   T)	r"   r$   ÚreadyÚ
successfulr   ÚputÚ_iqueue_value_for_successÚ_iqueue_value_for_failureÚ_iqueue_value_for_self_finished)r   ÚgreenletÚcountr$   r=   Úput_finishedr   r   r   r4   Œ   s   
ÿzIMapUnordered._on_resultc                 C   sV   | j rd S |d urd| _ | j |  |¡¡ d S | jdkr)d| _ | j |  ¡ ¡ d S d S )NTr   )r$   r   r?   Ú_iqueue_value_for_self_failurer"   rB   ©r   Ú	exceptionr   r   r   r9       s   
þzIMapUnordered._on_finishc                 C   s   |j S r   )r+   ©r   rC   r   r   r   r@   ®   s   z'IMapUnordered._iqueue_value_for_successc                 C   s   t |jt|dƒƒS )NÚ_raise_exception)r   rH   ÚgetattrrI   r   r   r   rA   ±   ó   z'IMapUnordered._iqueue_value_for_failurec                 C   s
   t tƒ ƒS r   )r   ÚStopIterationr&   r   r   r   rB   ´   r.   z-IMapUnordered._iqueue_value_for_self_finishedc                 C   s   t || jƒS r   )r   rJ   rG   r   r   r   rF   ·   s   z,IMapUnordered._iqueue_value_for_self_failure)NF)r   r   r   Ú__doc__r   r'   r,   Únextr)   r8   r<   r4   r9   r@   rA   rB   rF   r   r   r   r   r   +   s    
3	c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )r   c                 O   s(   i | _ d| _tj| g|¢R i |¤Ž d S )Nr   )Ú_resultsÚindexr   r   )r   ÚargsÚkwargsr   r   r   r   À   s   zIMap.__init__c                 C   s`   z	| j  | j¡}W n ty&   	 | j ¡ \}}|| jkrn|| j |< qY nw |  jd7  _|S r/   )rP   ÚpoprQ   ÚKeyErrorr   r-   )r   r+   rQ   r   r   r   r)   È   s   

üûzIMap._inextc                 C   ó   |j t | |¡fS r   )r2   r   r@   rI   r   r   r   r@   Õ   rL   zIMap._iqueue_value_for_successc                 C   rV   r   )r2   r   rA   rI   r   r   r   rA   Ø   rL   zIMap._iqueue_value_for_failurec                 C   s   | j d t | ¡fS r/   )r#   r   rB   r&   r   r   r   rB   Û   s   z$IMap._iqueue_value_for_self_finishedc                 C   s   | j d t | |¡fS r/   )r#   r   rF   rG   r   r   r   rF   Þ   s   z#IMap._iqueue_value_for_self_failureN)	r   r   r   r   r)   r@   rA   rB   rF   r   r   r   r   r   »   s    )Úimport_c_accelzgevent.__imapN)rN   Ú
__future__r   r   r   r	   r   r   Ú__all__Ú
__import__r
   Úlocalsr   r   Úobjectr   r   r   r   Úgevent._utilrW   Úglobalsr   r   r   r   Ú<module>   s&   þ &