U
    ·ÜŸj|  ã                   @   s^   d Z ddlZddlmZ ddlmZ ddgiZdd	d
dgZG dd„ deƒZ	dd	„ Z
e	Ze
ZdS )zË
Asynchronous progress bar decorator for iterators.
Includes a default `range` iterator printing to `stderr`.

Usage:
>>> from tqdm.asyncio import trange, tqdm
>>> async for i in trange(10):
...     ...
é    N)Úversion_infoé   )Útqdmzgithub.com/Z	casperdclÚtqdm_asyncioÚtaranger   Útrangec                       sh   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zeddddœdd„ƒZ	edddddœdd„ƒZ
‡  ZS )r   z0
    Asynchronous-friendly version of tqdm.
    Nc                    sŽ   t ƒ j|f|ž|Ž d| _|d k	rŠt|dƒr<|j| _d| _nNt|dƒrb| ¡ | _| jj| _d| _n(t|dƒrv|j| _nt	|ƒ| _| jj| _d S )NFÚ	__anext__TÚ	__aiter__Ú__next__)
ÚsuperÚ__init__Úiterable_awaitableÚhasattrr   Úiterable_nextr	   Ziterable_iteratorr
   Úiter)ÚselfÚiterableÚargsÚkwargs©Ú	__class__© ú0/tmp/pip-unpacked-wheel-ktn_y856/tqdm/asyncio.pyr      s    






ztqdm_asyncio.__init__c                 C   s   | S ©Nr   )r   r   r   r   r	   (   s    ztqdm_asyncio.__aiter__c                 Ã   sn   z,| j r|  ¡ I d H }n|  ¡ }|  ¡  |W S  tk
rL   |  ¡  t‚Y n tk
rh   |  ¡  ‚ Y nX d S r   )r   r   ÚupdateÚStopIterationÚcloseÚStopAsyncIterationÚBaseException)r   Úresr   r   r   r   +   s    ztqdm_asyncio.__anext__c                 O   s   | j j||ŽS r   )r   Úsend)r   r   r   r   r   r   r    :   s    ztqdm_asyncio.send©ÚloopÚtimeoutÚtotalc                k   s\   |dkrt |ƒ}i }tdd… dk r,||d< | tj|fd|i|—Žfd|i|—ŽE dH  dS )z5
        Wrapper for `asyncio.as_completed`.
        Né   )é   é
   r"   r#   r$   )Úlenr   ÚasyncioÚas_completed)ÚclsÚfsr"   r#   r$   Útqdm_kwargsr   r   r   r   r*   =   s    ÿÿztqdm_asyncio.as_completedF)r"   r#   r$   Úreturn_exceptionsc          	      �   s^   ‡ fdd„‰‡fdd„t |ƒD ƒ}dd„ | j|f|||dœ|—ŽD ƒI dH }dd„ t|ƒD ƒS )	z/
        Wrapper for `asyncio.gather`.
        c              
   “   sN   z| |I d H fW S  t k
rH } zˆ r6| |f W Y ¢S ‚ W 5 d }~X Y nX d S r   )Ú	Exception)ÚiÚfÚe)r.   r   r   Úwrap_awaitableP   s    z+tqdm_asyncio.gather.<locals>.wrap_awaitablec                    s   g | ]\}}ˆ ||ƒ‘qS r   r   )Ú.0r0   r1   )r3   r   r   Ú
<listcomp>X   s     z'tqdm_asyncio.gather.<locals>.<listcomp>c                 Ó   s   g | ]}|I d H ‘qS r   r   )r4   r1   r   r   r   r5   Y   s     r!   Nc                 S   s   g | ]\}}|‘qS r   r   )r4   Ú_r0   r   r   r   r5   [   s     )Ú	enumerater*   Úsorted)	r+   r"   r#   r$   r.   r,   r-   Zifsr   r   )r.   r3   r   ÚgatherJ   s    ÿÿztqdm_asyncio.gather)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r    Úclassmethodr*   r9   Ú__classcell__r   r   r   r   r      s   c                  O   s   t t| Ž f|ŽS )zE
    A shortcut for `tqdm.asyncio.tqdm(range(*args), **kwargs)`.
    )r   Úrange)r   r   r   r   r   r   ^   s    )r=   r)   Úsysr   Zstdr   Zstd_tqdmÚ
__author__Ú__all__r   r   r   r   r   r   r   Ú<module>   s   	
K