3
d
                 @   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 progressbar 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                   sf   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Z
  ZS )r   z>
    Asynchronous-friendly version of tqdm (Python 3.6+).
    Nc                sl   t t| j|f|| d| _|d k	rht|dr@|j| _d| _n(t|drT|j| _nt|| _	| j	j| _d S )NF	__anext__T__next__)
superr   __init__iterable_awaitablehasattrr   iterable_nextr	   iterZiterable_iterator)selfiterableargskwargs)	__class__ ,/tmp/pip-build-v9q4h5k9/tqdm/tqdm/asyncio.pyr      s    



ztqdm_asyncio.__init__c             C   s   | S )Nr   )r   r   r   r   	__aiter__$   s    ztqdm_asyncio.__aiter__c                sl   y*| j r| j I d H }n| j }| j  |S  tk
rJ   | j  tY n tk
rf   | j   Y nX d S )N)r   r   updateStopIterationcloseStopAsyncIterationBaseException)r   resr   r   r   r   '   s    ztqdm_asyncio.__anext__c             O   s   | j j||S )N)r   send)r   r   r   r   r   r   r   6   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!   )r#   r$   )lenr   asyncioas_completed)clsfsr   r    r!   tqdm_kwargsr   r   r   r   r'   9   s    ztqdm_asyncio.as_completedc               sZ   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                s   | |I d H fS )Nr   )ifr   r   r   wrap_awaitableK   s    z+tqdm_asyncio.gather.<locals>.wrap_awaitablec                s   g | ]\}} ||qS r   r   ).0r+   r,   )r-   r   r   
<listcomp>N   s    z'tqdm_asyncio.gather.<locals>.<listcomp>c                s   g | ]}|I d H qS )Nr   )r.   r,   r   r   r   r/   O   s    )r   r    r!   Nc             S   s   g | ]\}}|qS r   r   )r.   _r+   r   r   r   r/   Q   s    )	enumerater'   sorted)r(   r   r    r!   r)   r*   Zifsr   r   )r-   r   gatherF   s
    ztqdm_asyncio.gather)N)__name__
__module____qualname____doc__r   r   r   r   classmethodr'   r3   __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   T   s    )r7   r&   sysr   Zstdr   Zstd_tqdm
__author____all__r   r   r   r   r   r   r   <module>	   s   
A