U
    EZh                     @   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ZTde/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[dd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[dd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]dd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ZHeHwdmdndo 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~Ze}j~ddd~Ze}jse}jedd e}jedd epd eod ddk re}ee{ qW 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-unpacked-wheel-36xvkur8/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 )RenderableColumnzA 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 )zRender 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   zRenders 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	rt |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   zInformation 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rt| ||$}|D ]}|V  | jd7  _q\W 5 Q R X n,| j}	| j	}
|D ]}|V  |	|d |
  qd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rt|j}|dkr| j|	|d}n| j	||d t
j|d|d}t|| |dd}|dkrt
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 )zStart 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 )zStop 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 )zAdvance 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 )zGet 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...Z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{Gz?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


