U
    ;»{jÅë  ã                   @   s  d dl Z d dlZd dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
mZ d dlmZ d dl mZmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZmZmZ d dlmZ d dlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/ ej0dk�r&d dlm1Z1 nd dl2m1Z1 ej0dk�rLd dlm3Z3 nd dl2m3Z3 ddl4m5Z5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZC ddlDmEZE ddlFmGZG ddlHmIZImJZJ ddlKmLZLmMZM e(deNƒZOe.dƒZPe g eQf ZRe .de+e¡ZSG d d!„ d!eƒZTd†e/e*eP e%eP f eUe)eQ eNeVe)e8 eVe)e g eQf  eQeGeGeGeGeQeVeVe%eP d+œd,d-„ZWG d.d/„ d/eeƒZXG d0d1„ d1e!eS e$eS ƒZYd2d#dd$dd%d&d'd(d)d$d3œeeNeUeVe)e8 eVe)e g eQf  eQeGeGeGeGeVe!e d4œd5d6„ZZej[d‡dd2d#dd$dd%d&d'd(d)d$d8œe/eUd9e\f e/e1d: e1d; f eNe)eU e)eU e)eU e)eN eUeVe)e8 eVe)e g eQf  eQeGeGeGeGeVe!e+ d<œd=d>„ƒZ]ej[dˆdd2d#dd$dd%d&d'd(d)d$d8œe/eUd9e\f e1d? eNe)eU e)eU e)eU e)eN eUeVe)e8 eVe)e g eQf  eQeGeGeGeGeVe!e d<œd@d>„ƒZ]d‰dd2d#dd$dd%d&d'd(d)d$d8œe/eUd9e\f e/e1d? e1d: e1d; f eNe)eU e)eU e)eU e)eN eUeVe)e8 eVe)e g eQf  eQeGeGeGeGeVe/e!e e!e+ f d<œdAd>„Z]G dBdC„ dCeƒZ^G dDdE„ dEe^ƒZ_G dFdG„ dGe^ƒZ`G dHdI„ dIe^ƒZaG dJdK„ dKe^ƒZbG dLdM„ dMe^ƒZcG dNdO„ dOeaƒZdG dPdQ„ dQe^ƒZeG dRdS„ dSe^ƒZfG dTdU„ dUe^ƒZgG dVdW„ dWe^ƒZhG dXdY„ dYe^ƒZiG dZd[„ d[e^ƒZjG d\d]„ d]e'ƒZke
G d^d_„ d_ƒƒZlG d`da„ dae?ƒZmendbk�rd dloZod dlpZpddclqmrZr dddlsmtZt ddelumvZv ddflHmJZJ evdgdhd#di�ZueJdjdkdlƒZHeH wdmdndo¡ dperdqƒdreHdsdtdudvœdweuetdxƒg	Zxd dylymzZz ezexƒZ{e8d#dz�Z7eme`ƒ fem |¡ ecƒ fže7d$d{œŽ�‚Z}e}j~d|d}d~�Ze}j~dd}d~�Z€e}j~d€dd~�Z�e}j‚�se}jƒed�d‚� e}jƒe€dƒd‚� ep „d„¡ eo …d d…¡dk �r¾e} †e‡e{ƒ¡ �q¾W 5 Q R X dS )Šé    N)ÚABCÚabstractmethod©Údeque)Ú	dataclassÚfield)Ú	timedelta)Ú	RawIOBaseÚUnsupportedOperation)Úceil)Úmmap)Úlength_hint)ÚPathLikeÚstat)ÚEventÚRLockÚThread)ÚTracebackType)ÚAnyÚBinaryIOÚCallableÚContextManagerÚDequeÚDictÚGenericÚIterableÚListÚ
NamedTupleÚNewTypeÚOptionalÚSequenceÚTextIOÚTupleÚTypeÚTypeVarÚUnion)é   é   )ÚLiteral)r&   é   )ÚSelfé   )ÚfilesizeÚget_console)ÚConsoleÚGroupÚJustifyMethodÚRenderableType)ÚHighlighter)ÚJupyterMixin)ÚLive)ÚProgressBar)ÚSpinner)Ú	StyleType)ÚColumnÚTable)ÚTextÚTextTypeÚTaskIDÚProgressTypeÚ_Ic                       sj   e Zd ZdZddedœ‡ fdd„Zddœd	d
„Zd dœdd„Zee	e
  ee
 ee ddœdd„Z‡  ZS )Ú_TrackThreadz)A thread to periodically update progress.ÚProgressr<   )ÚprogressÚtask_idÚupdate_periodc                    s2   || _ || _|| _tƒ | _d| _tƒ jdd� d S )Nr   T)Údaemon)rA   rB   rC   r   ÚdoneÚ	completedÚsuperÚ__init__)ÚselfrA   rB   rC   ©Ú	__class__© ú:/tmp/pip-install-zsn1f9xv/pip/pip/_vendor/rich/progress.pyrH   G   s    z_TrackThread.__init__N©Úreturnc                 C   sn   | j }| jj}| j}d}| jj}||ƒsT| jjjrT| j}||kr |||| ƒ |}q | jj	| j | jdd� d S )Nr   T)rF   Úrefresh)
rB   rA   ÚadvancerC   rE   ÚwaitÚliveÚ
is_startedrF   Úupdate)rI   rB   rQ   rC   Zlast_completedrR   rF   rL   rL   rM   ÚrunP   s    z_TrackThread.runc                 C   s   |   ¡  | S ©N©Ústart©rI   rL   rL   rM   Ú	__enter__^   s    z_TrackThread.__enter__©Úexc_typeÚexc_valÚexc_tbrO   c                 C   s   | j  ¡  |  ¡  d S rW   )rE   ÚsetÚjoin©rI   r]   r^   r_   rL   rL   rM   Ú__exit__b   s    
z_TrackThread.__exit__)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚfloatrH   rV   r[   r   r#   ÚBaseExceptionr   rc   Ú__classcell__rL   rL   rJ   rM   r?   D   s   	
ûr?   ú
Working...TFé
   úbar.backúbar.completeúbar.finishedú	bar.pulseçš™™™™™¹?)ÚsequenceÚdescriptionÚtotalrF   Úauto_refreshÚconsoleÚ	transientÚget_timeÚrefresh_per_secondÚstyleÚcomplete_styleÚfinished_styleÚpulse_stylerC   ÚdisableÚ
show_speedrO   c              	   c   s„   |rt dƒgng }| t|	|
||d�t|d�tdd�f¡ t||||||pLd|dœŽ}|�  |j| ||||d�E d	H  W 5 Q R X d	S )
a=  Track progress by iterating over a sequence.

    Args:
        sequence (Iterable[ProgressType]): A sequence (must support "len") you wish to iterate over.
        description (str, optional): Description of task show next to progress bar. Defaults to "Working".
        total: (float, optional): Total number of steps. Default is len(sequence).
        completed (int, optional): Number of steps completed so far. Defaults to 0.
        auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        console (Console, optional): Console to write to. Default creates internal Console instance.
        refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
        update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.
        disable (bool, optional): Disable display of progress.
        show_speed (bool, optional): Show speed if total isn't known. Defaults to True.
    Returns:
        Iterable[ProgressType]: An iterable of the values in the sequence.

    ú([progress.description]{task.description}©rz   r{   r|   r}   )r   T)Úelapsed_when_finishedrl   ©ru   rv   rw   rx   ry   r~   )rt   rF   rs   rC   N)Ú
TextColumnÚextendÚ	BarColumnÚTaskProgressColumnÚTimeRemainingColumnr@   Útrack)rr   rs   rt   rF   ru   rv   rw   rx   ry   rz   r{   r|   r}   rC   r~   r   ÚcolumnsrA   rL   rL   rM   r‰   l   s<    *ÿüøÿù
ûr‰   c                   @   s˜  e Zd ZdZd<edeeddœdd„Zd dœd	d
„Ze	e
e  e	e e	e ddœdd„Zedœdd„Zedœdd„Zeedœdd„ƒZedœdd„Zedœdd„Zeedœdd„ƒZeedœdd„ƒZedœdd„Zedœdd„Zedœd d!„Zd=eed#œd$d%„Zeeee f d&œd'd(„Z!d>eed#œd)d*„Z"d?ee#e d+œd,d-„Z$ddœd.d/„Z%d@eeed1œd2d3„Z&edœd4d5„Z'e(ed6œd7d8„Z)e*e( dd9œd:d;„Z+dS )AÚ_Readerz9A reader that tracks progress while it's being read from.Tr@   N)ÚhandlerA   ÚtaskÚclose_handlerO   c                 C   s"   || _ || _|| _|| _d| _d S ©NF)rŒ   rA   r�   rŽ   Ú_closed)rI   rŒ   rA   r�   rŽ   rL   rL   rM   rH   »   s
    z_Reader.__init__rN   c                 C   s   | j  ¡  | S rW   )rŒ   r[   rZ   rL   rL   rM   r[   È   s    
z_Reader.__enter__r\   c                 C   s   |   ¡  d S rW   )Úcloserb   rL   rL   rM   rc   Ì   s    z_Reader.__exit__c                 C   s   | S rW   rL   rZ   rL   rL   rM   Ú__iter__Ô   s    z_Reader.__iter__c                 C   s$   t | jƒ}| jj| jt|ƒd� |S ©N©rQ   )ÚnextrŒ   rA   rQ   r�   Úlen)rI   ÚlinerL   rL   rM   Ú__next__×   s    
z_Reader.__next__c                 C   s   | j S rW   )r�   rZ   rL   rL   rM   ÚclosedÜ   s    z_Reader.closedc                 C   s
   | j  ¡ S rW   )rŒ   ÚfilenorZ   rL   rL   rM   rš   à   s    z_Reader.filenoc                 C   s
   | j  ¡ S rW   )rŒ   ÚisattyrZ   rL   rL   rM   r›   ã   s    z_Reader.isattyc                 C   s   | j jS rW   )rŒ   ÚmoderZ   rL   rL   rM   rœ   æ   s    z_Reader.modec                 C   s   | j jS rW   )rŒ   ÚnamerZ   rL   rL   rM   r�   ê   s    z_Reader.namec                 C   s
   | j  ¡ S rW   )rŒ   ÚreadablerZ   rL   rL   rM   rž   î   s    z_Reader.readablec                 C   s
   | j  ¡ S rW   )rŒ   ÚseekablerZ   rL   rL   rM   rŸ   ñ   s    z_Reader.seekablec                 C   s   dS r�   rL   rZ   rL   rL   rM   Úwritableô   s    z_Reader.writableéÿÿÿÿ)ÚsizerO   c                 C   s&   | j  |¡}| jj| jt|ƒd� |S r“   )rŒ   ÚreadrA   rQ   r�   r–   )rI   r¢   ÚblockrL   rL   rM   r£   ÷   s    z_Reader.read)Úbc                 C   s"   | j  |¡}| jj| j|d� |S r“   )rŒ   ÚreadintorA   rQ   r�   )rI   r¥   ÚnrL   rL   rM   r¦   ü   s    z_Reader.readintoc                 C   s&   | j  |¡}| jj| jt|ƒd� |S r“   )rŒ   ÚreadlinerA   rQ   r�   r–   )rI   r¢   r—   rL   rL   rM   r¨     s    z_Reader.readline)ÚhintrO   c                 C   s,   | j  |¡}| jj| jttt|ƒƒd� |S r“   )rŒ   Ú	readlinesrA   rQ   r�   ÚsumÚmapr–   )rI   r©   ÚlinesrL   rL   rM   rª     s    z_Reader.readlinesc                 C   s   | j r| j ¡  d| _d S )NT)rŽ   rŒ   r‘   r�   rZ   rL   rL   rM   r‘     s    
z_Reader.closer   )ÚoffsetÚwhencerO   c                 C   s$   | j  ||¡}| jj| j|d� |S )N©rF   )rŒ   ÚseekrA   rU   r�   )rI   r®   r¯   ÚposrL   rL   rM   r±     s    z_Reader.seekc                 C   s
   | j  ¡ S rW   )rŒ   ÚtellrZ   rL   rL   rM   r³     s    z_Reader.tell)ÚsrO   c                 C   s   t dƒ‚d S )NÚwrite©r
   )rI   r´   rL   rL   rM   rµ     s    z_Reader.write)r­   rO   c                 C   s   t dƒ‚d S )NÚ
writelinesr¶   )rI   r­   rL   rL   rM   r·     s    z_Reader.writelines)T)r¡   )r¡   )r¡   )r   ),rd   re   rf   rg   r   r<   ÚboolrH   r[   r   r#   ri   r   rc   r’   Úbytesr˜   Úpropertyr™   Úintrš   r›   Ústrrœ   r�   rž   rŸ   r    r£   r%   Ú	bytearrayÚ
memoryviewr   r¦   r¨   r   rª   r‘   r±   r³   r   rµ   r   r·   rL   rL   rL   rM   r‹   ¸   sJ    ûú
ûr‹   c                   @   sT   e Zd ZdZdeddœdd„Zedœdd	„Zeee	  ee	 ee
 dd
œdd„ZdS )Ú_ReadContextzEA utility class to handle a context for both a reader and a progress.r@   N)rA   ÚreaderrO   c                 C   s   || _ || _d S rW   )rA   rÀ   )rI   rA   rÀ   rL   rL   rM   rH   "  s    z_ReadContext.__init__rN   c                 C   s   | j  ¡  | j ¡ S rW   )rA   rY   rÀ   r[   rZ   rL   rL   rM   r[   &  s    
z_ReadContext.__enter__r\   c                 C   s   | j  ¡  | j |||¡ d S rW   )rA   ÚstoprÀ   rc   rb   rL   rL   rM   rc   *  s    
z_ReadContext.__exit__)rd   re   rf   rg   r>   rH   r[   r   r#   ri   r   rc   rL   rL   rL   rM   r¿     s   
ûr¿   ú
Reading...)rs   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   )Úfilert   rs   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rO   c             	   C   sh   |rt dƒgng }| t||	|
|d�tƒ tƒ f¡ t||||||pDd|dœŽ}|j| ||d�}t||ƒS )a  Read bytes from a file while tracking progress.

    Args:
        file (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode.
        total (int): Total number of bytes to read.
        description (str, optional): Description of task show next to progress bar. Defaults to "Reading".
        auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        console (Console, optional): Console to write to. Default creates internal Console instance.
        refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
        disable (bool, optional): Disable display of progress.
    Returns:
        ContextManager[BinaryIO]: A context manager yielding a progress reader.

    r€   r�   rl   rƒ   )rt   rs   )r„   r…   r†   ÚDownloadColumnrˆ   r@   Ú	wrap_filer¿   )rÃ   rt   rs   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rŠ   rA   rÀ   rL   rL   rM   rÅ   4  s0    %ÿüøÿù
rÅ   r¡   )rt   rs   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   úPathLike[str]ÚrtÚr)rÃ   rœ   Ú	bufferingÚencodingÚerrorsÚnewlinert   rs   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rO   c                C   s   d S rW   rL   ©rÃ   rœ   rÉ   rÊ   rË   rÌ   rt   rs   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rL   rL   rM   Úopenu  s    rÎ   Úrbc                C   s   d S rW   rL   rÍ   rL   rL   rM   rÎ   Ž  s    c             
   C   sr   |rt dƒgng }| t||||d�tƒ tƒ f¡ t|||	|
||pDd|dœŽ}|j| |||||||d�}t||ƒS )a®  Read bytes from a file while tracking progress.

    Args:
        path (Union[str, PathLike[str], BinaryIO]): The path to the file to read, or a file-like object in binary mode.
        mode (str): The mode to use to open the file. Only supports "r", "rb" or "rt".
        buffering (int): The buffering strategy to use, see :func:`io.open`.
        encoding (str, optional): The encoding to use when reading in text mode, see :func:`io.open`.
        errors (str, optional): The error handling strategy for decoding errors, see :func:`io.open`.
        newline (str, optional): The strategy for handling newlines in text mode, see :func:`io.open`
        total: (int, optional): Total number of bytes to read. Must be provided if reading from a file handle. Default for a path is os.stat(file).st_size.
        description (str, optional): Description of task show next to progress bar. Defaults to "Reading".
        auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        console (Console, optional): Console to write to. Default creates internal Console instance.
        refresh_per_second (float): Number of times per second to refresh the progress information. Defaults to 10.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
        disable (bool, optional): Disable display of progress.
        encoding (str, optional): The encoding to use when reading in text mode.

    Returns:
        ContextManager[BinaryIO]: A context manager yielding a progress reader.

    r€   r�   rl   rƒ   )rœ   rÉ   rÊ   rË   rÌ   rt   rs   )r„   r…   r†   rÄ   rˆ   r@   rÎ   r¿   )rÃ   rœ   rÉ   rÊ   rË   rÌ   rt   rs   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   rŠ   rA   rÀ   rL   rL   rM   rÎ   §  sB    1ÿüøÿù
ø
c                   @   sj   e Zd ZU dZdZee ed< dee ddœdd„Z	edœdd	„Z
d
edœdd„Zed
edœdd„ƒZdS )ÚProgressColumnz3Base class for a widget to use in progress display.NÚmax_refresh)Útable_columnrO   c                 C   s   || _ i | _d | _d S rW   )Ú_table_columnÚ_renderable_cacheZ_update_time)rI   rÒ   rL   rL   rM   rH     s    zProgressColumn.__init__rN   c                 C   s   | j p
tƒ S )z.Get a table column, used to build tasks table.)rÓ   r8   rZ   rL   rL   rM   Úget_table_column  s    zProgressColumn.get_table_columnÚTask©r�   rO   c                 C   sr   |  ¡ }| jdk	rT|jsTz| j|j \}}W n tk
r@   Y nX || j |krT|S |  |¡}||f| j|j< |S )a  Called by the Progress object to return a renderable for the given task.

        Args:
            task (Task): An object containing information regarding the task.

        Returns:
            RenderableType: Anything renderable (including str).
        N)rx   rÑ   rF   rÔ   ÚidÚKeyErrorÚrender)rI   r�   Úcurrent_timeÚ	timestampÚ
renderablerL   rL   rM   Ú__call__  s    	
zProgressColumn.__call__c                 C   s   dS )z"Should return a renderable object.NrL   ©rI   r�   rL   rL   rM   rÚ   "  s    zProgressColumn.render)N)rd   re   rf   rg   rÑ   r   rh   Ú__annotations__r8   rH   rÕ   r1   rÞ   r   rÚ   rL   rL   rL   rM   rÐ   ý  s   
rÐ   c                       sD   e Zd ZdZdddœeee dœ‡ fdd„Zded	œd
d„Z‡  Z	S )ÚRenderableColumnz�A column to insert an arbitrary column.

    Args:
        renderable (RenderableType, optional): Any renderable. Defaults to empty string.
    Ú N©rÒ   )rÝ   rÒ   c                   s   || _ tƒ j|d� d S ©Nrã   )rÝ   rG   rH   )rI   rÝ   rÒ   rJ   rL   rM   rH   .  s    zRenderableColumn.__init__rÖ   r×   c                 C   s   | j S rW   )rÝ   rß   rL   rL   rM   rÚ   4  s    zRenderableColumn.render)râ   )
rd   re   rf   rg   r1   r   r8   rH   rÚ   rj   rL   rL   rJ   rM   rá   '  s    ÿÿ ÿrá   c                       sb   e Zd ZdZdeee eeee	 dœ‡ fdd	„Z
deee edd
œdd„Zdedœdd„Z‡  ZS )ÚSpinnerColumna‰  A column with a 'spinner' animation.

    Args:
        spinner_name (str, optional): Name of spinner animation. Defaults to "dots".
        style (StyleType, optional): Style of spinner. Defaults to "progress.spinner".
        speed (float, optional): Speed factor of spinner. Defaults to 1.0.
        finished_text (TextType, optional): Text used when task is finished. Defaults to " ".
    Údotsúprogress.spinnerç      ð?ú N)Úspinner_namerz   ÚspeedÚfinished_textrÒ   c                    s<   t |||d�| _t|tƒr$t |¡n|| _tƒ j|d� d S )N©rz   rë   rã   )	r6   ÚspinnerÚ
isinstancer¼   r:   Úfrom_markuprì   rG   rH   )rI   rê   rz   rë   rì   rÒ   rJ   rL   rM   rH   B  s    ÿýzSpinnerColumn.__init__)rê   Úspinner_stylerë   rO   c                 C   s   t |||d�| _dS )a-  Set a new spinner.

        Args:
            spinner_name (str): Spinner name, see python -m rich.spinner.
            spinner_style (Optional[StyleType], optional): Spinner style. Defaults to "progress.spinner".
            speed (float, optional): Speed factor of spinner. Defaults to 1.0.
        rí   N)r6   rî   )rI   rê   rñ   rë   rL   rL   rM   Úset_spinnerR  s    zSpinnerColumn.set_spinnerrÖ   r×   c                 C   s    |j r| jn| j | ¡ ¡}|S rW   )Úfinishedrì   rî   rÚ   rx   )rI   r�   ÚtextrL   rL   rM   rÚ   a  s
    ÿýzSpinnerColumn.render)ræ   rç   rè   ré   N)rç   rè   )rd   re   rf   rg   r¼   r   r7   rh   r;   r8   rH   rò   r1   rÚ   rj   rL   rL   rJ   rM   rå   8  s,        úú  üûrå   c                	       sL   e Zd ZdZdeeeeee	 ee
 ddœ‡ fdd„Zd	ed
œdd„Z‡  ZS )r„   zA column containing text.ÚnoneÚleftTN)Útext_formatrz   ÚjustifyÚmarkupÚhighlighterrÒ   rO   c                    s:   || _ || _|| _|| _|| _tƒ j|p0tdd�d� d S )NT©Zno_wraprã   )r÷   rø   rz   rù   rú   rG   rH   r8   )rI   r÷   rz   rø   rù   rú   rÒ   rJ   rL   rM   rH   m  s    	zTextColumn.__init__rÖ   r×   c                 C   sR   | j j|d�}| jr*tj|| j| jd�}nt|| j| jd�}| jrN| j |¡ |S ©N©r�   )rz   rø   )	r÷   Úformatrù   r:   rð   rz   rø   rú   Ú	highlight)rI   r�   Ú_textrô   rL   rL   rM   rÚ   }  s    zTextColumn.render)rõ   rö   TNN)rd   re   rf   rg   r¼   r7   r0   r¸   r   r2   r8   rH   r:   rÚ   rj   rL   rL   rJ   rM   r„   j  s         ùør„   c                	       sL   e Zd ZdZdee eeeeee ddœ‡ fd	d
„Zde	dœdd„Z
‡  ZS )r†   a  Renders a visual progress bar.

    Args:
        bar_width (Optional[int], optional): Width of bar or None for full width. Defaults to 40.
        style (StyleType, optional): Style for the bar background. Defaults to "bar.back".
        complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete".
        finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished".
        pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse".
    é(   rm   rn   ro   rp   N)Ú	bar_widthrz   r{   r|   r}   rÒ   rO   c                    s0   || _ || _|| _|| _|| _tƒ j|d� d S rä   )r  rz   r{   r|   r}   rG   rH   )rI   r  rz   r{   r|   r}   rÒ   rJ   rL   rM   rH   “  s    	zBarColumn.__init__rÖ   r×   c                 C   s^   t |jdk	rtd|jƒndtd|jƒ| jdkr2dn
td| jƒ|j | ¡ | j| j| j	| j
d�	S )z&Gets a progress bar widget for a task.Nr   r+   )	rt   rF   ÚwidthZpulseZanimation_timerz   r{   r|   r}   )r5   rt   ÚmaxrF   r  Ústartedrx   rz   r{   r|   r}   rß   rL   rL   rM   rÚ   £  s    
÷zBarColumn.render)r  rm   rn   ro   rp   N)rd   re   rf   rg   r   r»   r7   r8   rH   r5   rÚ   rj   rL   rL   rJ   rM   r†   ˆ  s"         ùør†   c                   @   s    e Zd ZdZdedœdd„ZdS )ÚTimeElapsedColumnzRenders time elapsed.rÖ   r×   c                 C   sJ   |j r|jn|j}|dkr&tddd�S ttdt|ƒƒd�}tt|ƒdd�S )zShow time elapsed.Nú-:--:--úprogress.elapsed©rz   r   )Úseconds)ró   Úfinished_timeÚelapsedr:   r   r  r»   r¼   )rI   r�   r  ÚdeltarL   rL   rM   rÚ   µ  s
    zTimeElapsedColumn.renderN©rd   re   rf   rg   r:   rÚ   rL   rL   rL   rM   r  ²  s   r  c                       sh   e Zd ZdZdeeeeeee	 ee
 edd	œ	‡ fd
d„Zeee edœdd„ƒZdedœdd„Z‡  ZS )r‡   a  Show task progress as a percentage.

    Args:
        text_format (str, optional): Format for percentage display. Defaults to "[progress.percentage]{task.percentage:>3.0f}%".
        text_format_no_percentage (str, optional): Format if percentage is unknown. Defaults to "".
        style (StyleType, optional): Style of output. Defaults to "none".
        justify (JustifyMethod, optional): Text justification. Defaults to "left".
        markup (bool, optional): Enable markup. Defaults to True.
        highlighter (Optional[Highlighter], optional): Highlighter to apply to output. Defaults to None.
        table_column (Optional[Column], optional): Table Column to use. Defaults to None.
        show_speed (bool, optional): Show speed if total is unknown. Defaults to False.
    ú-[progress.percentage]{task.percentage:>3.0f}%râ   rõ   rö   TNF)	r÷   Útext_format_no_percentagerz   rø   rù   rú   rÒ   r   rO   c	           	         s(   || _ || _tƒ j||||||d� d S )N)r÷   rz   rø   rù   rú   rÒ   )r  r   rG   rH   )	rI   r÷   r  rz   rø   rù   rú   rÒ   r   rJ   rL   rM   rH   Ì  s    úzTaskProgressColumn.__init__)rë   rO   c                 C   sT   |dkrt ddd�S t t|ƒdddddgd	¡\}}|| }t |d
›|› d�dd�S )zµRender the speed in iterations per second.

        Args:
            task (Task): A Task object.

        Returns:
            Text: Text object containing the task speed.
        Nrâ   zprogress.percentager	  u   Ã—10Â³u   Ã—10â�¶u   Ã—10â�¹u   Ã—10Â¹Â²éè  z.1fz it/s)r:   r,   Úpick_unit_and_suffixr»   )Úclsrë   ÚunitÚsuffixÚ
data_speedrL   rL   rM   Úrender_speedâ  s    
ýzTaskProgressColumn.render_speedrÖ   r×   c                 C   sˆ   |j d kr"| jr"|  |jp|j¡S |j d kr2| jn| j}|j|d�}| jr`t	j
|| j| jd�}nt	|| j| jd�}| jr„| j |¡ |S rü   )rt   r   r  Úfinished_speedrë   r  r÷   rþ   rù   r:   rð   rz   rø   rú   rÿ   )rI   r�   r÷   r   rô   rL   rL   rM   rÚ   ö  s    ÿzTaskProgressColumn.render)r  râ   rõ   rö   TNNF)rd   re   rf   rg   r¼   r7   r0   r¸   r   r2   r8   rH   Úclassmethodrh   r:   r  rÚ   rj   rL   rL   rJ   rM   r‡   ¾  s.           ÷ör‡   c                       sD   e Zd ZdZdZdeeee dœ‡ fdd„Zde	d	œd
d„Z
‡  ZS )rˆ   a  Renders estimated time remaining.

    Args:
        compact (bool, optional): Render MM:SS when time remaining is less than an hour. Defaults to False.
        elapsed_when_finished (bool, optional): Render time elapsed when the task is finished. Defaults to False.
    ç      à?FN)Úcompactr‚   rÒ   c                    s   || _ || _tƒ j|d� d S rä   )r  r‚   rG   rH   )rI   r  r‚   rÒ   rJ   rL   rM   rH     s    zTimeRemainingColumn.__init__rÖ   r×   c                 C   sº   | j r|jr|j}d}n
|j}d}|jdkr8td|d�S |dkrVt| jrLdnd|d�S tt|ƒdƒ\}}t|dƒ\}}| jr”|s”|d	›d
|d	›�}n|d›d
|d	›d
|d	›�}t||d�S )zShow time remaining.r  zprogress.remainingNrâ   r	  z--:--r  é<   Z02dú:Úd)	r‚   ró   r  Útime_remainingrt   r:   r  Údivmodr»   )rI   r�   Z	task_timerz   Úminutesr
  ÚhoursÚ	formattedrL   rL   rM   rÚ     s    

zTimeRemainingColumn.render)FFN)rd   re   rf   rg   rÑ   r¸   r   r8   rH   r:   rÚ   rj   rL   rL   rJ   rM   rˆ     s      üü
rˆ   c                   @   s    e Zd ZdZdedœdd„ZdS )ÚFileSizeColumnzRenders completed filesize.rÖ   r×   c                 C   s   t  t|jƒ¡}t|dd�S )úShow data completed.zprogress.filesizer	  )r,   Údecimalr»   rF   r:   ©rI   r�   Ú	data_sizerL   rL   rM   rÚ   9  s    zFileSizeColumn.renderNr  rL   rL   rL   rM   r$  6  s   r$  c                   @   s    e Zd ZdZdedœdd„ZdS )ÚTotalFileSizeColumnzRenders total filesize.rÖ   r×   c                 C   s*   |j dk	rt t|j ƒ¡nd}t|dd�S )r%  Nrâ   zprogress.filesize.totalr	  )rt   r,   r&  r»   r:   r'  rL   rL   rM   rÚ   B  s    zTotalFileSizeColumn.renderNr  rL   rL   rL   rM   r)  ?  s   r)  c                       s>   e Zd ZdZdeee dœ‡ fdd„Zdedœd	d
„Z	‡  Z
S )ÚMofNCompleteColumnaH  Renders completed count/total, e.g. '  10/1000'.

    Best for bounded tasks with int quantities.

    Space pads the completed count so that progress length does not change as task progresses
    past powers of 10.

    Args:
        separator (str, optional): Text to separate completed and total values. Defaults to "/".
    ú/N)Ú	separatorrÒ   c                    s   || _ tƒ j|d� d S rä   )r,  rG   rH   )rI   r,  rÒ   rJ   rL   rM   rH   T  s    zMofNCompleteColumn.__init__rÖ   r×   c                 C   sP   t |jƒ}|jdk	rt |jƒnd}tt|ƒƒ}t||› d�›| j› |› �dd�S )zShow completed/total.Nú?r  úprogress.downloadr	  )r»   rF   rt   r–   r¼   r:   r,  )rI   r�   rF   rt   Ztotal_widthrL   rL   rM   rÚ   X  s    
þzMofNCompleteColumn.render)r+  N)rd   re   rf   rg   r¼   r   r8   rH   r:   rÚ   rj   rL   rL   rJ   rM   r*  H  s   r*  c                       s@   e Zd ZdZdeee ddœ‡ fdd„Zdedœd	d
„Z	‡  Z
S )rÄ   z¤Renders file size downloaded and total, e.g. '0.5/2.3 GB'.

    Args:
        binary_units (bool, optional): Use binary units, KiB, MiB etc. Defaults to False.
    FN)Úbinary_unitsrÒ   rO   c                    s   || _ tƒ j|d� d S rä   )r/  rG   rH   )rI   r/  rÒ   rJ   rL   rM   rH   j  s    zDownloadColumn.__init__rÖ   r×   c                 C   sð   t |jƒ}|jdk	rt |jƒn|}| jrNt |dddddddd	d
g	d¡\}}n$t |dddddddddg	d¡\}}|dkr~dnd}|| }|d|› d�›}|jdk	rÈt |jƒ}	|	| }
|
d|› d�›}nd}|› d|› d|› �}t|dd�}|S )z.Calculate common unit for completed and total.Nr¹   ZKiBZMiBZGiBZTiBZPiBZEiBZZiBZYiBi   ZkBZMBZGBZTBZPBZEBZZBZYBr  r+   r   z,.Úfr-  r+  ré   r.  r	  )r»   rF   rt   r/  r,   r  r:   )rI   r�   rF   Z unit_and_suffix_calculation_baser  r  Z	precisionZcompleted_ratioZcompleted_strrt   Ztotal_ratioZ	total_strZdownload_statusZdownload_textrL   rL   rM   rÚ   p  s2    
ÿý
ý

zDownloadColumn.render)FN)rd   re   rf   rg   r¸   r   r8   rH   r:   rÚ   rj   rL   rL   rJ   rM   rÄ   c  s      ÿ þrÄ   c                   @   s    e Zd ZdZdedœdd„ZdS )ÚTransferSpeedColumnz&Renders human readable transfer speed.rÖ   r×   c                 C   s@   |j p
|j}|dkr tddd�S t t|ƒ¡}t|› d�dd�S )zShow data transfer speed.Nr-  zprogress.data.speedr	  z/s)r  rë   r:   r,   r&  r»   )rI   r�   rë   r  rL   rL   rM   rÚ   —  s
    zTransferSpeedColumn.renderNr  rL   rL   rL   rM   r1  ”  s   r1  c                   @   s"   e Zd ZU dZeed< eed< dS )ÚProgressSamplez$Sample of progress for a given time.rÜ   rF   N)rd   re   rf   rg   rh   rà   rL   rL   rL   rM   r2     s   
r2  c                   @   s”  e Zd ZU dZeed< eed< ee ed< eed< e	ed< dZ
ee ed< d	Zeed
< eed�Zeeef ed< edddd�Zee ed< edddd�Zee ed< dZee ed< edd„ ddd�Zee ed< eded�Zeed< edœdd„Zeedœdd„ƒZeee dœdd„ƒZeee dœdd „ƒZeedœd!d"„ƒZeedœd#d$„ƒZ eee dœd%d&„ƒZ!eee dœd'd(„ƒZ"ddœd)d*„Z#dS )+rÖ   z…Information regarding a progress task.

    This object should be considered read-only outside of the :class:`~Progress` class.

    rØ   rs   rt   rF   Ú	_get_timeNr  TÚvisible)Údefault_factoryÚfieldsF)ÚdefaultÚinitÚreprÚ
start_timeÚ	stop_timer  c                   C   s
   t dd�S )Nr  )Úmaxlenr   rL   rL   rL   rM   Ú<lambda>Ó  ó    zTask.<lambda>)r5  r8  r9  Ú	_progress)r9  r5  Ú_lockrN   c                 C   s   |   ¡ S )z(float: Get the current time, in seconds.)r3  rZ   rL   rL   rM   rx   Ù  s    zTask.get_timec                 C   s
   | j dk	S )z#bool: Check if the task as started.N)r:  rZ   rL   rL   rM   r  Ý  s    zTask.startedc                 C   s   | j dkrdS | j | j S )zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N©rt   rF   rZ   rL   rL   rM   Ú	remainingâ  s    
zTask.remainingc                 C   s2   | j dkrdS | jdk	r$| j| j  S |  ¡ | j  S )z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)r:  r;  rx   rZ   rL   rL   rM   r  é  s
    

zTask.elapsedc                 C   s
   | j dk	S )zCheck if the task has finished.N)r  rZ   rL   rL   rM   ró   ò  s    zTask.finishedc                 C   s.   | j s
dS | j| j  d }tdtd|ƒƒ}|S )zOfloat: Get progress of task as a percentage. If a None total was set, returns 0ç        ç      Y@)rt   rF   Úminr  )rI   rF   rL   rL   rM   Ú
percentage÷  s
    zTask.percentagec              
   C   sœ   | j dkrdS | j�~ | j}|s.W 5 Q R £ dS |d j|d j }|dkrXW 5 Q R £ dS t|ƒ}t|ƒ tdd„ |D ƒƒ}|| }|W  5 Q R £ S Q R X dS )z=Optional[float]: Get the estimated speed in steps per second.Nr¡   r   c                 s   s   | ]}|j V  qd S rW   r°   )Ú.0ÚsamplerL   rL   rM   Ú	<genexpr>  s     zTask.speed.<locals>.<genexpr>)r:  r@  r?  rÜ   Úiterr•   r«   )rI   rA   Z
total_timeZiter_progressZtotal_completedrë   rL   rL   rM   rë      s    
z
Task.speedc                 C   s:   | j r
dS | j}|sdS | j}|dkr*dS t|| ƒ}|S )zJOptional[float]: Get estimated time to completion, or ``None`` if no data.rC  N)ró   rë   rB  r   )rI   rë   rB  ZestimaterL   rL   rM   r    s    zTask.time_remainingc                 C   s   | j  ¡  d| _d| _dS )zReset progress.N)r?  Úclearr  r  rZ   rL   rL   rM   Ú_reset   s    
zTask._reset)$rd   re   rf   rg   r<   rà   r¼   r   rh   ÚGetTimeCallabler  r4  r¸   r   Údictr6  r   r   r:  r;  r  r?  r   r2  r   r@  rx   rº   r  rB  r  ró   rF  rë   r  rL  rL   rL   rL   rM   rÖ   ©  sD   
  ÿrÖ   c                   @   s¼  e Zd ZdZdddddddddddœ
eeef ee e	e
e
e	e	e	ee e	e	ddœd	d
„Zeeedf dœdd„ƒZeedœdd„ƒZeee dœdd„ƒZeee dœdd„ƒZee	dœdd„ƒZddœdd„Zddœdd„Zedœdd„Zeee  ee ee ddœdd„ZdXee e! e"e! f ee
 e#ee ee
e e! d#œd$d%„Z$dYdd&d'œe%ee# ee ee%d(œd)d*„Z&e'j(dZddd&d,œeed-e)f e*d. e#ee ee ee ee# ee ee%d/œ
d0d1„ƒZ+e'j(d[ddd&d,œeed-e)f ee*d2 e*d3 f e#ee ee ee ee# ee ee,d/œ
d4d1„ƒZ+d\ddd&d,œeed-e)f ee*d. e*d3 e*d2 f e#ee ee ee ee# ee eee%e,f d/œ
d5d1„Z+edd6œd7d8„Z-edd6œd9d:„Z.ddddddd;œeee
 ee
 ee
 ee ee	 e	e/dd<œ	d=d>„Z0ddd ddd?œee	ee
 e#ee	 ee e/dd@œdAdB„Z1d]ee
ddDœdEdF„Z2ddœdGdH„Z3e4dœdIdJ„Z5e e4 dœdKdL„Z6e e e7dMœdNdO„Z8e4dœdPdQ„Z9d^ee	ee
 e#e	e/edSœdTdU„Z:edd6œdVdW„Z;dS )_r@   aŒ  Renders an auto-updating progress bar(s).

    Args:
        console (Console, optional): Optional Console instance. Defaults to an internal Console instance writing to stdout.
        auto_refresh (bool, optional): Enable auto refresh. If disabled, you will need to call `refresh()`.
        refresh_per_second (Optional[float], optional): Number of times per second to refresh the progress information or None to use default (10). Defaults to None.
        speed_estimate_period: (float, optional): Period (in seconds) used to calculate the speed estimate. Defaults to 30.
        transient: (bool, optional): Clear the progress on exit. Defaults to False.
        redirect_stdout: (bool, optional): Enable redirection of stdout, so ``print`` may be used. Defaults to True.
        redirect_stderr: (bool, optional): Enable redirection of stderr. Defaults to True.
        get_time: (Callable, optional): A callable that gets the current time, or None to use Console.get_time. Defaults to None.
        disable (bool, optional): Disable progress display. Defaults to False
        expand (bool, optional): Expand tasks table to fit width. Defaults to False.
    NTrl   g      >@F)
rv   ru   ry   Úspeed_estimate_periodrw   Úredirect_stdoutÚredirect_stderrrx   r~   Úexpand)rŠ   rv   ru   ry   rO  rw   rP  rQ  rx   r~   rR  rO   c       
      	   G   sŽ   |dkst dƒ‚tƒ | _|p"|  ¡ | _|| _|	| _|
| _i | _t	dƒ| _
t|pRtƒ |||||| jd�| _|pr| jj| _| jj| _| jj| _d S )Nr   zrefresh_per_second must be > 0)rv   ru   ry   rw   rP  rQ  Úget_renderable)ÚAssertionErrorr   r@  Úget_default_columnsrŠ   rO  r~   rR  Ú_tasksr<   Ú_task_indexr4   r-   rS  rS   rv   rx   ÚprintÚlog)rI   rv   ru   ry   rO  rw   rP  rQ  rx   r~   rR  rŠ   rL   rL   rM   rH   7  s(    
ù	
zProgress.__init__.rN   c                 C   s   t dƒtƒ tƒ tƒ fS )a§  Get the default columns used for a new Progress instance:
           - a text column for the description (TextColumn)
           - the bar itself (BarColumn)
           - a text column showing completion percentage (TextColumn)
           - an estimated-time-remaining column (TimeRemainingColumn)
        If the Progress instance is created without passing a columns argument,
        the default columns defined here will be used.

        You can also create a Progress instance using custom columns before
        and/or after the defaults, as in this example:

            progress = Progress(
                SpinnerColumn(),
                *Progress.get_default_columns(),
                "Elapsed:",
                TimeElapsedColumn(),
            )

        This code shows the creation of a Progress display, containing
        a spinner to the left, the default columns, and a labeled elapsed
        time column.
        r€   )r„   r†   r‡   rˆ   )r  rL   rL   rM   rU  [  s
    üzProgress.get_default_columnsc                 C   s   | j jS rW   )rS   rv   rZ   rL   rL   rM   rv   z  s    zProgress.consolec              
   C   s,   | j � t| j ¡ ƒW  5 Q R £ S Q R X dS )zGet a list of Task instances.N)r@  ÚlistrV  ÚvaluesrZ   rL   rL   rM   Útasks~  s    zProgress.tasksc              
   C   s,   | j � t| j ¡ ƒW  5 Q R £ S Q R X dS )zA list of task IDs.N)r@  rZ  rV  ÚkeysrZ   rL   rL   rM   Útask_ids„  s    zProgress.task_idsc              
   C   sJ   | j �: | jsW 5 Q R £ dS tdd„ | j ¡ D ƒƒW  5 Q R £ S Q R X dS )z'Check if all tasks have been completed.Tc                 s   s   | ]}|j V  qd S rW   )ró   )rG  r�   rL   rL   rM   rI  �  s     z$Progress.finished.<locals>.<genexpr>N)r@  rV  Úallr[  rZ   rL   rL   rM   ró   Š  s    zProgress.finishedc                 C   s   | j s| jjdd� dS )zStart the progress display.T)rP   N)r~   rS   rY   rZ   rL   rL   rM   rY   ’  s    zProgress.startc                 C   s(   | j  ¡  | jjs$| jjs$| j ¡  dS )zStop the progress display.N)rS   rÁ   rv   Zis_interactiveZ
is_jupyterrX  rZ   rL   rL   rM   rÁ   —  s    
zProgress.stopc                 C   s   |   ¡  | S rW   rX   rZ   rL   rL   rM   r[   �  s    zProgress.__enter__r\   c                 C   s   |   ¡  d S rW   )rÁ   rb   rL   rL   rM   rc   ¡  s    zProgress.__exit__r   rk   rq   )rr   rt   rF   rB   rs   rC   rO   c              	   c   s²   |dkrt t|ƒƒpd}|dkr2| j|||d�}n| j|||d� | jjr‚t| ||ƒ�$}|D ]}|V  | jd7  _q\W 5 Q R X n,| j}	| j	}
|D ]}|V  |	|dƒ |
ƒ  q’dS )aß  Track progress by iterating over a sequence.

        Args:
            sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress.
            total: (float, optional): Total number of steps. Default is len(sequence).
            completed (int, optional): Number of steps completed so far. Defaults to 0.
            task_id: (TaskID): Task to track. Default is new task.
            description: (str, optional): Description of task, if new task is created.
            update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.

        Returns:
            Iterable[ProgressType]: An iterable of values taken from the provided sequence.
        NrA  r+   )
rh   r   Úadd_taskrU   rS   ru   r?   rF   rQ   rP   )rI   rr   rt   rF   rB   rs   rC   Ztrack_threadÚvaluerQ   rP   rL   rL   rM   r‰   ©  s     
zProgress.trackrÂ   )rB   rs   )rÃ   rt   rB   rs   rO   c             	   C   s~   d}|dk	r|}n&|dk	r8| j � | j| j}W 5 Q R X |dkrHtdƒ‚|dkr`| j||d�}n| j||d� t|| |dd�S )aj  Track progress file reading from a binary file.

        Args:
            file (BinaryIO): A file-like object opened in binary mode.
            total (int, optional): Total number of bytes to read. This must be provided unless a task with a total is also given.
            task_id (TaskID): Task to track. Default is new task.
            description (str, optional): Description of task, if new task is created.

        Returns:
            BinaryIO: A readable file-like object in binary mode.

        Raises:
            ValueError: When no total value can be extracted from the arguments or the task.
        Nz?unable to get the total number of bytes, please specify 'total'©rt   F©rŽ   )r@  rV  rt   Ú
ValueErrorr`  rU   r‹   )rI   rÃ   rt   rB   rs   Útotal_bytesrL   rL   rM   rÅ   Ô  s    ÿzProgress.wrap_filer¡   )rt   rB   rs   rÆ   rÏ   )
rÃ   rœ   rÉ   rÊ   rË   rÌ   rt   rB   rs   rO   c          
      C   s   d S rW   rL   ©
rI   rÃ   rœ   rÉ   rÊ   rË   rÌ   rt   rB   rs   rL   rL   rM   rÎ   þ  s    zProgress.openrÈ   rÇ   c          
      C   s   d S rW   rL   rf  rL   rL   rM   rÎ     s    c                C   sð   d  t|dd�¡}
|
dkr(td|›�ƒ‚|dk}|
dkrR|dkrRt dt¡ d	}n&|
d
krx|dkrltdƒ‚n|dkrxd	}|dkrŠt|ƒj}|dkr¢| j|	|d�}n| j	||d� t
j|d|d�}t|| |dd�}|dkrìt
j|||||d�S |S )a#  Track progress while reading from a binary file.

        Args:
            path (Union[str, PathLike[str]]): The path to the file to read.
            mode (str): The mode to use to open the file. Only supports "r", "rb" or "rt".
            buffering (int): The buffering strategy to use, see :func:`io.open`.
            encoding (str, optional): The encoding to use when reading in text mode, see :func:`io.open`.
            errors (str, optional): The error handling strategy for decoding errors, see :func:`io.open`.
            newline (str, optional): The strategy for handling newlines in text mode, see :func:`io.open`.
            total (int, optional): Total number of bytes to read. If none given, os.stat(path).st_size is used.
            task_id (TaskID): Task to track. Default is new task.
            description (str, optional): Description of task, if new task is created.

        Returns:
            BinaryIO: A readable file-like object in binary mode.

        Raises:
            ValueError: When an invalid mode is given.
        râ   F)Úreverse)ÚbrrÇ   rÈ   zinvalid mode r+   rh  zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr¡   )rÇ   rÈ   r   zcan't have unbuffered text I/ONrb  rÏ   )rÉ   Trc  )rÈ   rÇ   )rÊ   rË   rÌ   Úline_buffering)ra   Úsortedrd  ÚwarningsÚwarnÚRuntimeWarningr   Úst_sizer`  rU   ÚiorÎ   r‹   ÚTextIOWrapper)rI   rÃ   rœ   rÉ   rÊ   rË   rÌ   rt   rB   rs   Ú_moderi  rŒ   rÀ   rL   rL   rM   rÎ     s>    !þ

û)rB   rO   c              	   C   s4   | j �$ | j| }|jdkr&|  ¡ |_W 5 Q R X dS )zéStart a task.

        Starts a task (used when calculating elapsed time). You may need to call this manually,
        if you called ``add_task`` with ``start=False``.

        Args:
            task_id (TaskID): ID of task.
        N)r@  rV  r:  rx   )rI   rB   r�   rL   rL   rM   Ú
start_taskk  s    	

zProgress.start_taskc              	   C   s>   | j �. | j| }|  ¡ }|jdkr*||_||_W 5 Q R X dS )z†Stop a task.

        This will freeze the elapsed time on the task.

        Args:
            task_id (TaskID): ID of task.
        N)r@  rV  rx   r:  r;  )rI   rB   r�   rÛ   rL   rL   rM   Ú	stop_tasky  s    

zProgress.stop_task)rt   rF   rQ   rs   r4  rP   )	rB   rt   rF   rQ   rs   r4  rP   r6  rO   c             	   K   s*  | j ��
 | j| }	|	j}
|dk	r:||	jkr:||	_|	 ¡  |dk	rP|	 j|7  _|dk	r^||	_|dk	rl||	_|dk	rz||	_|	j |¡ |	j|
 }|  	¡ }|| j
 }|	j}|j}|rÈ|d j|k rÈ|ƒ  q®|dkrà| t||ƒ¡ |	jdk	�r|	j|	jk�r|	jdk�r|	j|	_W 5 Q R X |�r&|  ¡  dS )a˜  Update information associated with a task.

        Args:
            task_id (TaskID): Task id (returned by add_task).
            total (float, optional): Updates task.total if not None.
            completed (float, optional): Updates task.completed if not None.
            advance (float, optional): Add a value to task.completed if not None.
            description (str, optional): Change task description if not None.
            visible (bool, optional): Set visible flag if not None.
            refresh (bool): Force a refresh of progress information. Default is False.
            **fields (Any): Additional data fields required for rendering.
        Nr   )r@  rV  rF   rt   rL  rs   r4  r6  rU   rx   rO  r?  ÚpopleftrÜ   Úappendr2  r  r  rP   )rI   rB   rt   rF   rQ   rs   r4  rP   r6  r�   Úcompleted_startÚupdate_completedrÛ   Úold_sample_timer?  rt  rL   rL   rM   rU   ˆ  sB    



ÿ
þýzProgress.update)rY   rt   rF   r4  rs   )rB   rY   rt   rF   r4  rs   r6  rO   c          
   	   K   s†   |   ¡ }| j�f | j| }	|	 ¡  |r*|nd|	_|dk	r>||	_||	_|dk	rR||	_|r\||	_|dk	rj||	_	d|	_
W 5 Q R X |  ¡  dS )aˆ  Reset a task so completed is 0 and the clock is reset.

        Args:
            task_id (TaskID): ID of task.
            start (bool, optional): Start the task after reset. Defaults to True.
            total (float, optional): New total steps in task, or None to use current total. Defaults to None.
            completed (int, optional): Number of steps completed. Defaults to 0.
            visible (bool, optional): Enable display of the task. Defaults to True.
            description (str, optional): Change task description if not None. Defaults to None.
            **fields (str): Additional data fields required for rendering.
        N)rx   r@  rV  rL  r:  rt   rF   r4  r6  rs   r  rP   )
rI   rB   rY   rt   rF   r4  rs   r6  rÛ   r�   rL   rL   rM   ÚresetÅ  s     
zProgress.resetr+   )rB   rQ   rO   c           
   	   C   sÊ   |   ¡ }| j�² | j| }|j}| j|7  _|j| }|| j }|j}|j}	|rh|d j|k rh|	ƒ  qNt|ƒdkr||	ƒ  qh| 	t
||ƒ¡ |jdk	r¼|j|jkr¼|jdkr¼|j|_|j|_W 5 Q R X dS )z«Advance task by a number of steps.

        Args:
            task_id (TaskID): ID of task.
            advance (float): Number of steps to advance. Default is 1.
        r   r  N)rx   r@  rV  rF   rO  r?  rt  rÜ   r–   ru  r2  rt   r  r  rë   r  )
rI   rB   rQ   rÛ   r�   rv  rw  rx  r?  rt  rL   rL   rM   rQ   ì  s,    


ÿ
þýzProgress.advancec                 C   s   | j s| jjr| j ¡  dS )z*Refresh (render) the progress information.N)r~   rS   rT   rP   rZ   rL   rL   rM   rP   
  s    zProgress.refreshc                 C   s   t |  ¡ Ž }|S )z*Get a renderable for the progress display.)r/   Úget_renderables)rI   rÝ   rL   rL   rM   rS    s    zProgress.get_renderablec                 c   s   |   | j¡}|V  dS )z5Get a number of renderables for the progress display.N)Úmake_tasks_tabler\  )rI   ÚtablerL   rL   rM   rz    s    zProgress.get_renderables)r\  rO   c                    sR   dd„ | j D ƒ}tj|d| jdœŽ}|D ]$‰ ˆ jr(|j‡ fdd„| j D ƒŽ  q(|S )z×Get a table to render the Progress display.

        Args:
            tasks (Iterable[Task]): An iterable of Task instances, one per row of the table.

        Returns:
            Table: A table instance.
        c                 s   s.   | ]&}t |tƒrtd d�n
| ¡  ¡ V  qdS )Trû   N)rï   r¼   r8   rÕ   Úcopy)rG  Z_columnrL   rL   rM   rI  "  s   ýÿz,Progress.make_tasks_table.<locals>.<genexpr>)r   r+   )ÚpaddingrR  c                 3   s,   | ]$}t |tƒr|jˆ d �n|ˆ ƒV  qdS )rý   N)rï   r¼   rþ   )rG  Úcolumnrý   rL   rM   rI  /  s   ýÿ)rŠ   r9   ZgridrR  r4  Úadd_row)rI   r\  Ztable_columnsr|  rL   rý   rM   r{    s    	ú
úÿ
zProgress.make_tasks_tablec              
   C   s&   | j � |  ¡ W  5 Q R £ S Q R X dS )z+Makes the Progress class itself renderable.N)r@  rS  rZ   rL   rL   rM   Ú__rich__:  s    zProgress.__rich__rD  )rs   rY   rt   rF   r4  r6  rO   c           	      K   sr   | j �Z t| j|||||| j| j d�}|| j| j< |rB|  | j¡ | j}tt| jƒd ƒ| _W 5 Q R X |  ¡  |S )a  Add a new 'task' to the Progress display.

        Args:
            description (str): A description of the task.
            start (bool, optional): Start the task immediately (to calculate elapsed time). If set to False,
                you will need to call `start` manually. Defaults to True.
            total (float, optional): Number of total steps in the progress if known.
                Set to None to render a pulsing animation. Defaults to 100.
            completed (int, optional): Number of steps completed so far. Defaults to 0.
            visible (bool, optional): Enable display of the task. Defaults to True.
            **fields (str): Additional data fields required for rendering.

        Returns:
            TaskID: An ID you can use when calling `update`.
        )r4  r6  r3  r@  r+   )	r@  rÖ   rW  rx   rV  rr  r<   r»   rP   )	rI   rs   rY   rt   rF   r4  r6  r�   Znew_task_indexrL   rL   rM   r`  ?  s$    ø
zProgress.add_taskc              	   C   s   | j � | j|= W 5 Q R X dS )z]Delete a task if it exists.

        Args:
            task_id (TaskID): A task ID.

        N)r@  rV  )rI   rB   rL   rL   rM   Úremove_taskj  s    zProgress.remove_task)Nr   Nrk   rq   )N)r¡   NNN)r¡   NNN)rÈ   r¡   NNN)r+   )TrD  r   T)<rd   re   rf   rg   r%   r¼   rÐ   r   r.   r¸   rh   rM  rH   r  r"   rU  rº   rv   r   rÖ   r\  r<   r^  ró   rY   rÁ   r*   r[   r#   ri   r   rc   r   r=   r    r»   r‰   r   rÅ   ÚtypingÚoverloadr¹   r(   rÎ   r!   rr  rs  r   rU   ry  rQ   rP   r1   rS  rz  r9   r{  r�  r`  r‚  rL   rL   rL   rM   r@   '  sr  ô
ó$
û     ùø. ýúù*    ù	õô    ù	õô     ù	õ
ôM÷õAøö'!    úø+r@   Ú__main__)ÚPanel)ÚRule)ÚSyntax)r9   a~  def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
    """Iterate and generate a tuple with a flag for last value."""
    iter_values = iter(values)
    try:
        previous_value = next(iter_values)
    except StopIteration:
        return
    for value in iter_values:
        yield False, previous_value
        previous_value = value
    yield True, previous_valueÚpython)Zline_numbersZfooÚbarZbazÚ1Ú2Ú3z:Text may be printed while the progress bars are rendering.z(In fact, [i]any[/i] renderable will workzSuch as [magenta]tables[/]...zPretty printed structures...ÚexamplezPretty printed)Útyperô   z	Syntax...zGive it a try!)Úcycle)Úrecord)rv   rw   z[red]Downloadingr  rb  z[green]Processingz[yellow]Thinkingr  r”   g333333Ó?g{®Gáz„?éd   )rk   Nr   TNFNrl   rm   rn   ro   rp   rq   FT)r¡   NNN)r¡   NNN)rÈ   r¡   NNN)ˆro  Úsysrƒ  rk  Úabcr   r   Úcollectionsr   Zdataclassesr   r   Údatetimer   r	   r
   Úmathr   r   Úoperatorr   Úosr   r   Ú	threadingr   r   r   Útypesr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   Úversion_infor(   Zpip._vendor.typing_extensionsr*   râ   r,   r-   rv   r.   r/   r0   r1   rú   r2   Zjupyterr3   rS   r4   Úprogress_barr5   rî   r6   rz   r7   r|  r8   r9   rô   r:   r;   r»   r<   r=   rh   rM  r>   r?   r¼   r¸   r‰   r‹   r¿   rÅ   r„  r¹   rÎ   rÐ   rá   rå   r„   r†   r  r‡   rˆ   r$  r)  r*  rÄ   r1  r2  rÖ   r@   rd   ÚrandomÚtimeZpanelr†  Zruler‡  Zsyntaxrˆ  r€  Zprogress_renderablesÚ	itertoolsr�  ZexamplesrU  rA   r`  Ztask1Ztask2Ztask3ró   rU   ÚsleepÚrandintrY  r•   rL   rL   rL   rM   Ú<module>   s6  P
*               ðïLgòñA    úíì    úíì     úíìV*2*H0		1	}    R
ó÷
ÿýû
