a
    sh                     @  s  d dl m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/m0Z0m1Z1 er&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ZOe0dZPe"g eQf ZRe0de-e!ZSG dd deZTdd)d*d+d,d-d.d-d/d0d1d1d1d1d0d-d-d)d2d3d4ZUG d5d6 d6ee!ZVG d7d8 d8e#eS e&eS ZWd9d!dd"dd#d$d%d&d'd"d:d;d,d*d-d.d-d/d0d1d1d1d1d-d<d=d>d?ZXejYddd9d!dd"dd#d$d%d&d'd"dAdBdCd,dDdDdDdEd*d-d.d-d/d0d1d1d1d1d-dFdGdHdIZZejYddd9d!dd"dd#d$d%d&d'd"dAdBdJd,dDdDdDdEd*d-d.d-d/d0d1d1d1d1d-d<dGdKdIZZddd9d!dd"dd#d$d%d&d'd"dAdBdMd,dDdDdDdEd*d-d.d-d/d0d1d1d1d1d-dNdGdOdIZZG dPdQ dQeZ[G dRdS dSe[Z\G dTdU dUe[Z]G dVdW dWe[Z^G dXdY dYe[Z_G dZd[ d[e[Z`G d\d] d]e^ZaG d^d_ d_e[ZbG d`da dae[ZcG dbdc dce[ZdG ddde dee[ZeG dfdg dge[ZfG dhdi die[ZgG djdk dke*ZheG dldm dmZiG dndo doe?Zjekdpkrd dllZld dlmZmddqlnmoZo ddrlpmqZq ddslrmsZs ddtlHmJZJ esdudvd!dwZreJdxdydzZHeHtd{d|d} d~eoddeHdddddereqdg	Zud dlvmwZw eweuZxe8d!dZ7eje] gejy e` R e7d"dZzezj{dddZ|ezj{dddZ}ezj{dddZ~ezjsezje|dd ezje}dd emd eld ddk rezeex qW d   n1 s0    Y  dS )    )annotationsN)ABCabstractmethoddeque)	dataclassfield)	timedelta)	RawIOBaseUnsupportedOperation)ceil)mmap)length_hint)PathLikestat)EventRLockThread)TracebackType)TYPE_CHECKINGAnyBinaryIOCallableContextManagerDequeDictGenericIterableListLiteral
NamedTupleNewTypeOptionalTextIOTupleTypeTypeVarUnion)Self   )filesizeget_console)ConsoleGroupJustifyMethodRenderableType)Highlighter)JupyterMixin)Live)ProgressBar)Spinner)	StyleType)ColumnTable)TextTextTypeTaskIDProgressType_Ic                      sZ   e Zd ZdZdddd fddZdd	d
dZdd	ddZdddddddZ  ZS )_TrackThreadz)A thread to periodically update progress.
'Progress'z'TaskID'float)progresstask_idupdate_periodc                   s2   || _ || _|| _t | _d| _t jdd d S )Nr   T)daemon)r@   rA   rB   r   done	completedsuper__init__)selfr@   rA   rB   	__class__ U/var/www/html/assistant/venv/lib/python3.9/site-packages/pip/_vendor/rich/progress.pyrG   C   s    z_TrackThread.__init__None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)rE   refresh)
rA   r@   advancerB   rD   waitlive
is_startedrE   update)rH   rA   rQ   rB   Zlast_completedrR   rE   rK   rK   rL   runL   s    z_TrackThread.runz'_TrackThread'c                 C  s   |    | S NstartrH   rK   rK   rL   	__enter__Z   s    z_TrackThread.__enter__Optional[Type[BaseException]]Optional[BaseException]Optional[TracebackType]exc_typeexc_valexc_tbrO   c                 C  s   | j   |   d S rW   )rD   setjoinrH   r`   ra   rb   rK   rK   rL   __exit__^   s    
z_TrackThread.__exit__)	__name__
__module____qualname____doc__rG   rV   r[   rf   __classcell__rK   rK   rI   rL   r=   @   s
   	r=   
Working...TF
   bar.backbar.completebar.finished	bar.pulse皙?Iterable[ProgressType]strOptional[float]intboolOptional[Console]zOptional[Callable[[], float]]r?   r5   )sequencedescriptiontotalrE   auto_refreshconsole	transientget_timerefresh_per_secondstylecomplete_stylefinished_stylepulse_stylerB   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 d	   n1 s0    Y  d	S )
a  Track progress by iterating over a sequence.

    You can also track progress of an iterable, which might require that you additionally specify ``total``.

    Args:
        sequence (Iterable[ProgressType]): Values you wish to iterate over and track progress.
        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}r   r   r   r   )r   T)elapsed_when_finishedrm   r|   r}   r~   r   r   r   )r{   rE   rz   rB   N)
TextColumnextend	BarColumnTaskProgressColumnTimeRemainingColumnProgresstrack)ry   rz   r{   rE   r|   r}   r~   r   r   r   r   r   r   rB   r   r   columnsr@   rK   rK   rL   r   h   s<    ,
r   c                   @  sv  e Zd ZdZdKddddddd	d
ZddddZdddddddZddddZddddZe	ddddZ
ddddZdddd Ze	d!dd"d#Ze	d!dd$d%Zddd&d'Zddd(d)Zddd*d+ZdLddd-d.d/Zd0d1d2d3ZdMddd-d4d5ZdNdd6d7d8d9Zddd:d;ZdOdddd=d>d?Zddd@dAZdBddCdDdEZdFddGdHdIZdJS )P_Readerz9A reader that tracks progress while it's being read from.Tr   r>   r:   rw   rM   )handler@   taskclose_handlerO   c                 C  s"   || _ || _|| _|| _d| _d S NF)r   r@   r   r   _closed)rH   r   r@   r   r   rK   rK   rL   rG      s
    z_Reader.__init__z	'_Reader'rN   c                 C  s   | j   | S rW   )r   r[   rZ   rK   rK   rL   r[      s    
z_Reader.__enter__r\   r]   r^   r_   c                 C  s   |    d S rW   )closere   rK   rK   rL   rf      s    z_Reader.__exit__c                 C  s   | S rW   rK   rZ   rK   rK   rL   __iter__   s    z_Reader.__iter__bytesc                 C  s$   t | j}| jj| jt|d |S NrQ   )nextr   r@   rQ   r   len)rH   linerK   rK   rL   __next__   s    
z_Reader.__next__c                 C  s   | j S rW   )r   rZ   rK   rK   rL   closed   s    z_Reader.closedrv   c                 C  s
   | j  S rW   )r   filenorZ   rK   rK   rL   r      s    z_Reader.filenoc                 C  s
   | j  S rW   )r   isattyrZ   rK   rK   rL   r      s    z_Reader.isattyrt   c                 C  s   | j jS rW   )r   moderZ   rK   rK   rL   r      s    z_Reader.modec                 C  s   | j jS rW   )r   namerZ   rK   rK   rL   r      s    z_Reader.namec                 C  s
   | j  S rW   )r   readablerZ   rK   rK   rL   r      s    z_Reader.readablec                 C  s
   | j  S rW   )r   seekablerZ   rK   rK   rL   r      s    z_Reader.seekablec                 C  s   dS r   rK   rZ   rK   rK   rL   writable   s    z_Reader.writable)sizerO   c                 C  s&   | j |}| jj| jt|d |S r   )r   readr@   rQ   r   r   )rH   r   blockrK   rK   rL   r      s    z_Reader.readz"Union[bytearray, memoryview, mmap])bc                 C  s"   | j |}| jj| j|d |S r   )r   readintor@   rQ   r   )rH   r   nrK   rK   rL   r      s    z_Reader.readintoc                 C  s&   | j |}| jj| jt|d |S r   )r   readliner@   rQ   r   r   )rH   r   r   rK   rK   rL   r      s    z_Reader.readlinezList[bytes])hintrO   c                 C  s,   | j |}| jj| jttt|d |S r   )r   	readlinesr@   rQ   r   summapr   )rH   r   linesrK   rK   rL   r     s    z_Reader.readlinesc                 C  s   | j r| j  d| _d S )NT)r   r   r   r   rZ   rK   rK   rL   r   	  s    
z_Reader.closer   )offsetwhencerO   c                 C  s$   | j ||}| jj| j|d |S )NrE   )r   seekr@   rU   r   )rH   r   r   posrK   rK   rL   r     s    z_Reader.seekc                 C  s
   | j  S rW   )r   tellrZ   rK   rK   rL   r     s    z_Reader.tellr   )srO   c                 C  s   t dd S )Nwriter   )rH   r   rK   rK   rL   r     s    z_Reader.writezIterable[Any])r   rO   c                 C  s   t dd S )N
writelinesr   )rH   r   rK   rK   rL   r     s    z_Reader.writelinesN)T)r   )r   )r   )r   )rg   rh   ri   rj   rG   r[   rf   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   rK   rK   rL   r      s6    r   c                   @  sD   e Zd ZdZddddddZddd	d
ZdddddddZdS )_ReadContextzEA utility class to handle a context for both a reader and a progress.r>   r<   rM   )r@   readerrO   c                 C  s   || _ || _d S rW   )r@   r   )rH   r@   r   rK   rK   rL   rG      s    z_ReadContext.__init__rN   c                 C  s   | j   | j S rW   )r@   rY   r   r[   rZ   rK   rK   rL   r[   $  s    
z_ReadContext.__enter__r\   r]   r^   r_   c                 C  s   | j   | j||| d S rW   )r@   stopr   rf   re   rK   rK   rL   rf   (  s    
z_ReadContext.__exit__N)rg   rh   ri   rj   rG   r[   rf   rK   rK   rK   rL   r     s   r   
Reading...)rz   r|   r}   r~   r   r   r   r   r   r   r   r   zContextManager[BinaryIO])filer{   rz   r|   r}   r~   r   r   r   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   rm   r   )r{   rz   )r   r   r   DownloadColumnr   r   	wrap_filer   )r   r{   rz   r|   r}   r~   r   r   r   r   r   r   r   r   r@   r   rK   rK   rL   r   2  s0    %
r   r   )r{   rz   r|   r}   r~   r   r   r   r   r   r   r   "Union[str, 'PathLike[str]', bytes]z"Union[Literal['rt'], Literal['r']]Optional[str]Optional[int]zContextManager[TextIO])r   r   	bufferingencodingerrorsnewliner{   rz   r|   r}   r~   r   r   r   r   r   r   r   rO   c                C  s   d S rW   rK   r   r   r   r   r   r   r{   rz   r|   r}   r~   r   r   r   r   r   r   r   rK   rK   rL   opens  s    r   Literal['rb']c                C  s   d S rW   rK   r   rK   rK   rL   r     s    r1Union[Literal['rb'], Literal['rt'], Literal['r']]z7Union[ContextManager[BinaryIO], ContextManager[TextIO]]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   rm   r   )r   r   r   r   r   r{   rz   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r{   rz   r|   r}   r~   r   r   r   r   r   r   r   r   r@   r   rK   rK   rL   r     sB    1

c                   @  sb   e Zd ZU dZdZded< dddddd	Zd
dddZdddddZe	dddddZ
dS )ProgressColumnz3Base class for a widget to use in progress display.Nru   max_refreshOptional[Column]rM   )table_columnrO   c                 C  s   || _ i | _d | _d S rW   )_table_column_renderable_cacheZ_update_time)rH   r   rK   rK   rL   rG      s    zProgressColumn.__init__r6   rN   c                 C  s   | j p
t S )z.Get a table column, used to build tasks table.)r   r6   rZ   rK   rK   rL   get_table_column  s    zProgressColumn.get_table_column'Task'r/   r   rO   c                 C  sp   |  }| jdurR|jsRz| j|j \}}W n ty>   Y n0 || j |krR|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)r   r   rE   r   idKeyErrorrender)rH   r   current_time	timestamp
renderablerK   rK   rL   __call__	  s    	
zProgressColumn.__call__c                 C  s   dS )z"Should return a renderable object.NrK   rH   r   rK   rK   rL   r      s    zProgressColumn.render)N)rg   rh   ri   rj   r   __annotations__rG   r   r   r   r   rK   rK   rK   rL   r     s   
r   c                      s@   e Zd ZdZdddddd fdd	Zd
d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   )r   r   c                  s   || _ t j|d d S Nr   )r   rF   rG   )rH   r   r   rI   rK   rL   rG   ,  s    zRenderableColumn.__init__r   r   c                 C  s   | j S rW   )r   r   rK   rK   rL   r   2  s    zRenderableColumn.render)r   rg   rh   ri   rj   rG   r   rk   rK   rK   rI   rL   r   %  s    r   c                      sV   e Zd ZdZdddd	d
dd fddZdddd	ddddZdd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      ? Nrt   zOptional[StyleType]r?   r9   r   )spinner_namer   speedfinished_textr   c                   s<   t |||d| _t|tr$t|n|| _t j|d d S )Nr   r   r   )	r4   spinner
isinstancert   r8   from_markupr   rF   rG   )rH   r   r   r   r   r   rI   rK   rL   rG   @  s    zSpinnerColumn.__init__rM   )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)r4   r   )rH   r   r   r   rK   rK   rL   set_spinnerP  s    zSpinnerColumn.set_spinnerr   r/   r   c                 C  s    |j r| jn| j| }|S rW   )finishedr   r   r   r   )rH   r   textrK   rK   rL   r   _  s
    zSpinnerColumn.render)r   r   r   r   N)r   r   )rg   rh   ri   rj   rG   r   r   rk   rK   rK   rI   rL   r   6  s          r   c                	      sD   e Zd ZdZddddd	d
ddd fddZdddddZ  ZS )r   zA column containing text.noneleftTNrt   r5   r.   rw   Optional[Highlighter]r   rM   )text_formatr   justifymarkuphighlighterr   rO   c                   s:   || _ || _|| _|| _|| _t j|p0tddd d S )NTZno_wrapr   )r   r   r   r  r  rF   rG   r6   )rH   r   r   r   r  r  r   rI   rK   rL   rG   k  s    	zTextColumn.__init__r   r8   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   )r   r   )	r   formatr  r8   r   r   r   r  	highlight)rH   r   _textr   rK   rK   rL   r   {  s    zTextColumn.render)r   r   TNNr   rK   rK   rI   rL   r   h  s         r   c                	      sD   e Zd ZdZddd	d	d	d	d
dd fddZdd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".
    (   rn   ro   rp   rq   Nr   r5   r   rM   )	bar_widthr   r   r   r   r   rO   c                   s0   || _ || _|| _|| _|| _t j|d d S r   )r
  r   r   r   r   rF   rG   )rH   r
  r   r   r   r   r   rI   rK   rL   rG     s    	zBarColumn.__init__r   r3   r   c                 C  s^   t |jdurtd|jndtd|j| jdu r2dn
td| j|j | | j| j| j	| j
d	S )z&Gets a progress bar widget for a task.Nr   r)   )	r{   rE   widthZpulseZanimation_timer   r   r   r   )r3   r{   maxrE   r
  startedr   r   r   r   r   r   rK   rK   rL   r     s    
zBarColumn.render)r	  rn   ro   rp   rq   Nr   rK   rK   rI   rL   r     s          r   c                   @  s    e Zd ZdZdddddZdS )TimeElapsedColumnzRenders time elapsed.r   r8   r   c                 C  sJ   |j r|jn|j}|du r&tdddS ttdt|d}tt|ddS )zShow time elapsed.N-:--:--progress.elapsedr   r   )seconds)r   finished_timeelapsedr8   r	   r  rv   rt   )rH   r   r  deltarK   rK   rL   r     s
    zTimeElapsedColumn.renderNrg   rh   ri   rj   r   rK   rK   rK   rL   r    s   r  c                      s\   e Zd ZdZdd	d	d
ddddddd	 fddZedddddZdd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   TNFrt   r5   r.   rw   r   r   rM   )	r   text_format_no_percentager   r   r  r  r   r   rO   c	           	        s(   || _ || _t j||||||d d S )N)r   r   r   r  r  r   )r  r   rF   rG   )	rH   r   r  r   r   r  r  r   r   rI   rK   rL   rG     s    zTaskProgressColumn.__init__ru   r8   )r   rO   c                 C  sN   |du rt dddS tt|g d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  )r   u   ×10³u   ×10⁶u   ×10⁹u   ×10¹²  z.1fz it/s)r8   r*   pick_unit_and_suffixrv   )clsr   unitsuffix
data_speedrK   rK   rL   render_speed  s    
zTaskProgressColumn.render_speedr   r   c                 C  s   |j d u r"| jr"| |jp|jS |j d u r2| jn| j}|j|d}| jr`t	j
|| j| jd}nt	|| j| jd}| jr| j| |S r  )r{   r   r  finished_speedr   r  r   r  r  r8   r   r   r   r  r  )rH   r   r   r  r   rK   rK   rL   r     s    zTaskProgressColumn.render)r  r   r   r   TNNF)	rg   rh   ri   rj   rG   classmethodr  r   rk   rK   rK   rI   rL   r     s           $r   c                      s@   e Zd ZdZdZddddd fdd	Zd
d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.
          ?FNrw   r   )compactr   r   c                   s   || _ || _t j|d d S r   )r#  r   rF   rG   )rH   r#  r   r   rI   rK   rL   rG     s    zTimeRemainingColumn.__init__r   r8   r   c                 C  s   | j r|jr|j}d}n
|j}d}|jdu r8td|dS |du 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_remainingr{   r8   r#  divmodrv   )rH   r   Z	task_timer   minutesr  hours	formattedrK   rK   rL   r     s    

zTimeRemainingColumn.render)FFN)rg   rh   ri   rj   r   rG   r   rk   rK   rK   rI   rL   r     s      
r   c                   @  s    e Zd ZdZdddddZdS )FileSizeColumnzRenders completed filesize.r   r8   r   c                 C  s   t t|j}t|ddS )Show data completed.zprogress.filesizer  )r*   decimalrv   rE   r8   rH   r   	data_sizerK   rK   rL   r   7  s    zFileSizeColumn.renderNr  rK   rK   rK   rL   r,  4  s   r,  c                   @  s    e Zd ZdZdddddZdS )TotalFileSizeColumnzRenders total filesize.r   r8   r   c                 C  s*   |j durtt|j nd}t|ddS )r-  Nr   zprogress.filesize.totalr  )r{   r*   r.  rv   r8   r/  rK   rK   rL   r   @  s    zTotalFileSizeColumn.renderNr  rK   rK   rK   rL   r1  =  s   r1  c                      s:   e Zd ZdZdddd fddZd	d
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 "/".
    /Nrt   r   )	separatorr   c                   s   || _ t j|d d S r   )r4  rF   rG   )rH   r4  r   rI   rK   rL   rG   R  s    zMofNCompleteColumn.__init__r   r8   r   c                 C  sP   t |j}|jdurt |jnd}tt|}t|| d| j | ddS )zShow completed/total.N?r&  progress.downloadr  )rv   rE   r{   r   rt   r8   r4  )rH   r   rE   r{   Ztotal_widthrK   rK   rL   r   V  s    
zMofNCompleteColumn.render)r3  Nr   rK   rK   rI   rL   r2  F  s   r2  c                      s<   e Zd ZdZddddd fdd	Zd
d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.
    FNrw   r   rM   )binary_unitsr   rO   c                   s   || _ t j|d d S r   )r7  rF   rG   )rH   r7  r   rI   rK   rL   rG   h  s    zDownloadColumn.__init__r   r8   r   c                 C  s   t |j}|jdurt |jn|}| jr@t|g dd\}}nt|g dd\}}|dkrbdnd}|| }|d| d	}|jdurt |j}	|	| }
|
d| d	}nd
}| d| d| }t|dd}|S )z.Calculate common unit for completed and total.N)	r   ZKiBZMiBZGiBZTiBZPiBZEiBZZiBZYiBi   )	r   ZkBZMBZGBZTBZPBZEBZZBZYBr  r)   r   z,.fr5  r3  r   r6  r  )rv   rE   r{   r7  r*   r  r8   )rH   r   rE   Z unit_and_suffix_calculation_baser  r  Z	precisionZcompleted_ratioZcompleted_strr{   Ztotal_ratioZ	total_strZdownload_statusZdownload_textrK   rK   rL   r   n  s2    



zDownloadColumn.render)FNr   rK   rK   rI   rL   r   a  s    r   c                   @  s    e Zd ZdZdddddZdS )TransferSpeedColumnz&Renders human readable transfer speed.r   r8   r   c                 C  s@   |j p
|j}|du r tdddS tt|}t| dddS )zShow data transfer speed.Nr5  zprogress.data.speedr  z/s)r   r   r8   r*   r.  rv   )rH   r   r   r  rK   rK   rL   r     s
    zTransferSpeedColumn.renderNr  rK   rK   rK   rL   r9    s   r9  c                   @  s"   e Zd ZU dZded< ded< dS )ProgressSamplez$Sample of progress for a given time.r?   r   rE   N)rg   rh   ri   rj   r   rK   rK   rK   rL   r:    s   
r:  c                   @  sd  e Zd ZU dZded< ded< ded< ded	< d
ed< dZded< dZded< eedZ	ded< eddddZ
ded< eddddZded< dZded< edd dddZded< ededZded < dd!d"d#Zedd!d$d%Zedd!d&d'Zedd!d(d)Zedd!d*d+Zedd!d,d-Zedd!d.d/Zedd!d0d1Zd2d!d3d4ZdS )5TaskzInformation regarding a progress task.

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

    r:   r   rt   rz   ru   r{   r?   rE   GetTimeCallable	_get_timeNr  Trw   visible)default_factoryzDict[str, Any]fieldsF)defaultinitrepr
start_time	stop_timer   c                   C  s
   t ddS )Nr  )maxlenr   rK   rK   rK   rL   <lambda>      zTask.<lambda>)r?  rB  rC  zDeque[ProgressSample]	_progress)rC  r?  r   _lockrN   c                 C  s   |   S )z(float: Get the current time, in seconds.)r=  rZ   rK   rK   rL   r     s    zTask.get_timec                 C  s
   | j duS )z#bool: Check if the task as started.N)rD  rZ   rK   rK   rL   r    s    zTask.startedc                 C  s   | j du rdS | j | j S )zPOptional[float]: Get the number of steps remaining, if a non-None total was set.Nr{   rE   rZ   rK   rK   rL   	remaining  s    
zTask.remainingc                 C  s2   | j du rdS | jdur$| j| j  S |  | j  S )z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)rD  rE  r   rZ   rK   rK   rL   r    s
    

zTask.elapsedc                 C  s
   | j duS )zCheck if the task has finished.N)r  rZ   rK   rK   rL   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@)r{   rE   minr  )rH   rE   rK   rK   rL   
percentage  s
    zTask.percentagec                 C  s   | j du rdS | j | j}|s0W d   dS |d j|d j }|dkr\W d   dS t|}t| tdd |D }|| }|W  d   S 1 s0    Y  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samplerK   rK   rL   	<genexpr>  rH  zTask.speed.<locals>.<genexpr>)rD  rJ  rI  r   iterr   r   )rH   r@   Z
total_timeZiter_progressZtotal_completedr   rK   rK   rL   r     s    
z
Task.speedc                 C  s:   | j r
dS | j}|sdS | j}|du r*dS t|| }|S )zJOptional[float]: Get estimated time to completion, or ``None`` if no data.rM  N)r   r   rL  r   )rH   r   rL  ZestimaterK   rK   rL   r'    s    zTask.time_remainingrM   c                 C  s   | j   d| _d| _dS )zReset progress.N)rI  clearr  r   rZ   rK   rK   rL   _reset  s    
zTask._reset)rg   rh   ri   rj   r   r  r>  r   dictr@  rD  rE  r   rI  r   rJ  r   r   r  rL  r  r   rP  r   r'  rV  rK   rK   rK   rL   r;    s@   

r;  c                   @  s  e Zd ZdZddddddddddd
dd	d
ddd
d
d
dd
d
ddddZeddddZeddddZeddddZ	eddddZ
ed
dddZddd d!Zddd"d#Zd$dd%d&Zd'd(d)dd*d+d,Zdwd0d1d2d3d4dd0d5d6d7Zdxdd8d9d:d;d3d4d:d<d=d>Zejdyddd8d@dAdBd2dCdCdCd;d3d4d:dD
dEdFZejdzddd8d@dAdGd2dCdCdCd;d3d4dHdD
dIdFZd{ddd8d@dAdKd2dCdCdCd;d3d4dLdD
dMdFZdNddOdPdQZdNddOdRdSZdddddddTdNd1d1d1dCdUd
dVddW	dXdYZddd-dddZdNd
d1d2dUdCdVdd[d\d]Zd|dNddd_d`daZdddbdcZddddedfZdgddhdiZdjdkdldmdnZddddodpZd}d4d
d1d2d
dVdNdrdsdtZdNddOdudv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.
    NTrm   g      >@F)
r}   r|   r   speed_estimate_periodr~   redirect_stdoutredirect_stderrr   r   expandzUnion[str, ProgressColumn]rx   rw   r?   zOptional[GetTimeCallable]rM   )r   r}   r|   r   rX  r~   rY  rZ  r   r   r[  rO   c       
      	   G  s   |dksJ 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)r}   r|   r   r~   rY  rZ  get_renderable)r   rJ  get_default_columnsr   rX  r   r[  _tasksr:   _task_indexr2   r+   r\  rS   r}   r   printlog)rH   r}   r|   r   rX  r~   rY  rZ  r   r   r[  r   rK   rK   rL   rG   5  s(    
	
zProgress.__init__zTuple[ProgressColumn, ...]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  rK   rK   rL   r]  Y  s
    zProgress.get_default_columnsr,   c                 C  s   | j jS rW   )rS   r}   rZ   rK   rK   rL   r}   x  s    zProgress.consolez
List[Task]c                 C  s8   | j  t| j W  d   S 1 s*0    Y  dS )zGet a list of Task instances.N)rJ  listr^  valuesrZ   rK   rK   rL   tasks|  s    zProgress.taskszList[TaskID]c                 C  s8   | j  t| j W  d   S 1 s*0    Y  dS )zA list of task IDs.N)rJ  rb  r^  keysrZ   rK   rK   rL   task_ids  s    zProgress.task_idsc                 C  sX   | j > | jsW d   dS tdd | j D W  d   S 1 sJ0    Y  dS )z'Check if all tasks have been completed.NTc                 s  s   | ]}|j V  qd S rW   )r   )rQ  r   rK   rK   rL   rS    rH  z$Progress.finished.<locals>.<genexpr>)rJ  r^  allrc  rZ   rK   rK   rL   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   rK   rK   rL   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   r}   Zis_interactiveZ
is_jupyterr`  rZ   rK   rK   rL   r     s    
zProgress.stopr(   c                 C  s   |    | S rW   rX   rZ   rK   rK   rL   r[     s    zProgress.__enter__r\   r]   r^   r_   c                 C  s   |    d S rW   )r   re   rK   rK   rL   rf     s    zProgress.__exit__r   rl   rr   rs   ru   rv   zOptional[TaskID]rt   )ry   r{   rE   rA   rz   rB   rO   c                 c  s   |du rt t|pd}|du r2| j|||d}n| j|||d | jjrt| ||.}|D ]}|V  | jd7  _q\W d   q1 s0    Y  n,| j}	| j	}
|D ]}|V  |	|d |
  qdS )aC  Track progress by iterating over a sequence.

        You can also track progress of an iterable, which might require that you additionally specify ``total``.

        Args:
            sequence (Iterable[ProgressType]): 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.
        NrK  r)   )
r?   r   add_taskrU   rS   r|   r=   rE   rQ   rP   )rH   ry   r{   rE   rA   rz   rB   Ztrack_threadvaluerQ   rP   rK   rK   rL   r     s     0
zProgress.trackr   )rA   rz   r   r   )r   r{   rA   rz   rO   c                C  s   d}|dur|}n:|durL| j  | j| j}W d   n1 sB0    Y  |du r\td|du rt| 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'r{   Fr   )rJ  r^  r{   
ValueErrorrh  rU   r   )rH   r   r{   rA   rz   total_bytesrK   rK   rL   r     s    *zProgress.wrap_filer   )r{   rA   rz   r   r   r   )
r   r   r   r   r   r   r{   rA   rz   rO   c          
      C  s   d S rW   rK   
rH   r   r   r   r   r   r   r{   rA   rz   rK   rK   rL   r     s    zProgress.openz"Union[Literal['r'], Literal['rt']]r#   c          
      C  s   d S rW   rK   rn  rK   rK   rL   r     s    r   r   zUnion[BinaryIO, TextIO]c                C  s   d t|dd}
|
dvr(td||dk}|
dkrR|dkrRtdt d	}n&|
d
v rx|dkrltdn|dkrxd	}|du rt|j}|du r| j|	|d}n| j	||d t
j|d|d}t|| |dd}|dv 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)brrtr   zinvalid mode r)   rp  zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr   )rq  r   r   zcan't have unbuffered text I/ONrj  rb)r   Trk  )r   rq  )r   r   r   line_buffering)rd   sortedrl  warningswarnRuntimeWarningr   st_sizerh  rU   ior   r   TextIOWrapper)rH   r   r   r   r   r   r   r{   rA   rz   _moders  r   r   rK   rK   rL   r     s>    !

r:   )rA   rO   c                 C  sH   | j . | j| }|jdu r&|  |_W d   n1 s:0    Y  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)rJ  r^  rD  r   )rH   rA   r   rK   rK   rL   
start_taskk  s    	

zProgress.start_taskc                 C  sR   | j 8 | j| }|  }|jdu r*||_||_W d   n1 sD0    Y  dS )zStop a task.

        This will freeze the elapsed time on the task.

        Args:
            task_id (TaskID): ID of task.
        N)rJ  r^  r   rD  rE  )rH   rA   r   r   rK   rK   rL   	stop_tasky  s    

zProgress.stop_task)r{   rE   rQ   rz   r>  rP   zOptional[bool]r   )	rA   r{   rE   rQ   rz   r>  rP   r@  rO   c                K  s@  | j  | j| }	|	j}
|dur:||	jkr:||	_|	  |durP|	 j|7  _|dur^||	_|durl||	_|durz||	_|	j| |	j|
 }| 	 }|| j
 }|	j}|j}|r|d j|k r|  q|dkr|t|| |	jdur|	j|	jkr|	jdu r|	j|	_W d   n1 s$0    Y  |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   )rJ  r^  rE   r{   rV  rz   r>  r@  rU   r   rX  rI  popleftr   appendr:  r  r  rP   )rH   rA   r{   rE   rQ   rz   r>  rP   r@  r   completed_startupdate_completedr   old_sample_timerI  r~  rK   rK   rL   rU     sB    




(zProgress.update)rY   r{   rE   r>  rz   )rA   rY   r{   rE   r>  rz   r@  rO   c          
      K  s   |   }| jp | j| }	|	  |r*|nd|	_|dur>||	_||	_|durR||	_|r\||	_|durj||	_	d|	_
W d   n1 s0    Y  |   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)r   rJ  r^  rV  rD  r{   rE   r>  r@  rz   r  rP   )
rH   rA   rY   r{   rE   r>  rz   r@  r   r   rK   rK   rL   reset  s     
$zProgress.resetr)   )rA   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ur|j|jkr|jdu r|j|_|j|_W d   n1 s0    Y  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)r   rJ  r^  rE   rX  rI  r~  r   r   r  r:  r{   r  r  r   r   )
rH   rA   rQ   r   r   r  r  r  rI  r~  rK   rK   rL   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   rK   rK   rL   rP   
  s    zProgress.refreshr/   c                 C  s   t |   }|S )z*Get a renderable for the progress display.)r-   get_renderables)rH   r   rK   rK   rL   r\    s    zProgress.get_renderablezIterable[RenderableType]c                 c  s   |  | j}|V  dS )z5Get a number of renderables for the progress display.N)make_tasks_tablerd  )rH   tablerK   rK   rL   r    s    zProgress.get_renderableszIterable[Task]r7   )rd  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   rt   r6   r   copy)rQ  Z_columnrK   rK   rL   rS  "  s   z,Progress.make_tasks_table.<locals>.<genexpr>)r   r)   )paddingr[  c                 3  s,   | ]$}t |tr|j d n| V  qdS )r  N)r   rt   r  )rQ  columnr  rK   rL   rS  /  s   )r   r7   Zgridr[  r>  add_row)rH   rd  Ztable_columnsr  rK   r  rL   r    s    	

zProgress.make_tasks_tablec                 C  s2   | j  |  W  d   S 1 s$0    Y  dS )z+Makes the Progress class itself renderable.N)rJ  r\  rZ   rK   rK   rL   __rich__:  s    zProgress.__rich__rN  )rz   rY   r{   rE   r>  r@  rO   c           	      K  s   | j d t| j|||||| j| j d}|| j| j< |rB| | j | j}tt| jd | _W d   n1 sp0    Y  |   |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`.
        )r>  r@  r=  rJ  r)   N)	rJ  r;  r_  r   r^  r|  r:   rv   rP   )	rH   rz   rY   r{   rE   r>  r@  r   Znew_task_indexrK   rK   rL   rh  ?  s$    
2zProgress.add_taskc                 C  s2   | j  | j|= W d   n1 s$0    Y  dS )z]Delete a task if it exists.

        Args:
            task_id (TaskID): A task ID.

        N)rJ  r^  )rH   rA   rK   rK   rL   remove_taskj  s    zProgress.remove_task)Nr   Nrl   rr   )N)r   NNN)r   NNN)r   r   NNN)r)   )TrN  r   T)!rg   rh   ri   rj   rG   r!  r]  r   r}   rd  rf  r   rY   r   r[   rf   r   r   typingoverloadr   r|  r}  rU   r  rQ   rP   r\  r  r  r  rh  r  rK   rK   rK   rL   r   %  s   ($     0 *    	&    	&     	$M"A '!    +r   __main__)Panel)Rule)Syntax)r7   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)r}   r~   z[red]Downloadingr  rj  z[green]Processingz[yellow]Thinkingr"  r   g333333?g{Gz?d   )rl   Nr   TNFNrm   rn   ro   rp   rq   rr   FT)r   NNN)r   NNN)r   r   NNN)
__future__r   ry  r  ru  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&   r'   Ztyping_extensionsr(   r   r*   r+   r}   r,   r-   r.   r/   r  r0   Zjupyterr1   rS   r2   progress_barr3   r   r4   r   r5   r  r6   r7   r   r8   r9   rv   r:   r;   r?   r<  r<   r=   r   r   r   r   r  r   r   r   r   r   r   r  r   r   r,  r1  r2  r   r9  r:  r;  r   rg   randomtimeZpanelr  Zruler  Zsyntaxr  r  Zprogress_renderables	itertoolsr  Zexamplesr]  r@   rh  Ztask1Ztask2Ztask3r   rU   sleeprandintra  r   rK   rK   rK   rL   <module>   sv  T
*               0Ng,A    8    8     6V*2*H0		1	}    T


