U
    )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__ 0/tmp/pip-unpacked-wheel-u8lm3wqg/tqdm/asyncio.pyr      s    



ztqdm_asyncio.__init__c                 C   s   | S Nr   )r   r   r   r   	__aiter__$   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    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$   )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 r   r   )ifr   r   r   wrap_awaitableK   s    z+tqdm_asyncio.gather.<locals>.wrap_awaitablec                    s   g | ]\}} ||qS r   r   ).0r.   r/   r0   r   r   
<listcomp>N   s     z'tqdm_asyncio.gather.<locals>.<listcomp>c                    s   g | ]}|I d H qS r   r   )r1   r/   r   r   r   r3   O   s     r!   Nc                 S   s   g | ]\}}|qS r   r   )r1   _r.   r   r   r   r3   Q   s     )	enumerater*   sorted)r+   r"   r#   r$   r,   r-   Zifsr   r   r2   r   gatherF   s    ztqdm_asyncio.gather)N)__name__
__module____qualname____doc__r   r   r   r    classmethodr*   r7   __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    )r;   r)   sysr   Zstdr   Zstd_tqdm
__author____all__r   r   r   r   r   r   r   <module>   s   	
A