HEX
Server: Apache
System: Linux p3plzcpnl506847.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: slfopp7cb1df (5698090)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/python38/lib/python3.8/site-packages/pip/_vendor/rich/__pycache__/progress.cpython-38.pyc
U

�{�e:��@s�ddlZddlZddlZddlZddlmZmZddlmZddl	m
Z
mZddlm
Z
ddlmZmZddlmZddlmZdd	lmZdd
lmZmZddlmZmZmZddlmZdd
lmZmZm 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/ej0dk�r&ddlm1Z1nddl2m1Z1ddl3m4Z4m5Z5ddl6m7Z7m8Z8m9Z9m:Z:ddl;m<Z<ddl=m>Z>ddl?m@Z@ddlAmBZBddlCmDZDddlEmFZFddlGmHZHmIZIddlJmKZKmLZLe(deM�ZNe.d�ZOe gePfZQe�.de+e�ZRGdd�de�ZSd�e/e*eOe%eOfeTe)ePeUe)e7eUe)e gePfePeFeFeFeFePeUeUe%eOd)�d*d+�ZVGd,d-�d-ee�ZWGd.d/�d/e!eRe$eR�ZXd0d!dd"dd#d$d%d&d'd"d1�eeMeTeUe)e7eUe)e gePfePeFeFeFeFeUe!ed2�d3d4�ZYejZd�dd0d!dd"dd#d$d%d&d'd"d6�e/eTd7e[fe/e1d8e1d9feMe)eTe)eTe)eTe)eMeTeUe)e7eUe)e gePfePeFeFeFeFeUe!e+d:�d;d<��Z\ejZd�dd0d!dd"dd#d$d%d&d'd"d6�e/eTd7e[fe1d=eMe)eTe)eTe)eTe)eMeTeUe)e7eUe)e gePfePeFeFeFeFeUe!ed:�d>d<��Z\d�dd0d!dd"dd#d$d%d&d'd"d6�e/eTd7e[fe/e1d=e1d8e1d9feMe)eTe)eTe)eTe)eMeTeUe)e7eUe)e gePfePeFeFeFeFeUe/e!ee!e+fd:�d?d<�Z\Gd@dA�dAe�Z]GdBdC�dCe]�Z^GdDdE�dEe]�Z_GdFdG�dGe]�Z`GdHdI�dIe]�ZaGdJdK�dKe]�ZbGdLdM�dMe`�ZcGdNdO�dOe]�ZdGdPdQ�dQe]�ZeGdRdS�dSe]�ZfGdTdU�dUe]�ZgGdVdW�dWe]�ZhGdXdY�dYe]�ZiGdZd[�d[e'�Zje
Gd\d]�d]��ZkGd^d_�d_e>�Zlemd`k�r�ddlnZnddloZoddalpmqZqddblrmsZsddcltmuZudddlGmIZIeudedfd!dg�ZteIdhdidj�ZGeG�vdkdldm�dneqdo�dpeGdqdrdsdt�duetesdv�g	ZwddwlxmyZyeyew�Zze7d!dx�Z6ele_�fel�{�eb�f�e6d"dy����Z|e|j}dzd{d|�Z~e|j}d}d{d|�Ze|j}d~dd|�Z�e|j��s�e|j�e~dd��e|j�ed�d��eo��d��en��dd��dk�r�e|��e�ez���q�W5QRXdS)��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�)�filesize�get_console)�Console�Group�
JustifyMethod�RenderableType)�Highlighter)�JupyterMixin)�Live)�ProgressBar)�Spinner)�	StyleType)�Column�Table)�Text�TextType�TaskID�ProgressType�_IcsjeZdZdZdded��fdd�Zdd�d	d
�Zdd�dd�Zee	e
ee
eedd
�dd�Z�Z
S)�_TrackThreadz)A thread to periodically update progress.�Progressr:)�progress�task_id�
update_periodcs.||_||_||_t�|_d|_t���dS)Nr)r?r@rAr�done�	completed�super�__init__)�selfr?r@rA��	__class__��=/tmp/pip-unpacked-wheel-_0scjqea/pip/_vendor/rich/progress.pyrEBsz_TrackThread.__init__N��returncCsd|j}|jj}|j}d}|jj}||�sJ|j}||kr ||||�|}q |jj|j|jdd�dS)NrT)rC�refresh)r@r?�advancerArB�waitrC�update)rFr@rNrAZlast_completedrOrCrIrIrJ�runKsz_TrackThread.runcCs|��|S�N��start�rFrIrIrJ�	__enter__Ysz_TrackThread.__enter__��exc_type�exc_val�exc_tbrLcCs|j��|��dSrR)rB�set�join�rFrXrYrZrIrIrJ�__exit__]s
z_TrackThread.__exit__)�__name__�
__module__�__qualname__�__doc__�floatrErQrVrr#�
BaseExceptionrr^�
__classcell__rIrIrGrJr=?s	
�r=�
Working...TF�
�bar.back�bar.complete�bar.finished�	bar.pulse皙�����?)�sequence�description�total�auto_refresh�console�	transient�get_time�refresh_per_second�style�complete_style�finished_style�pulse_stylerA�disable�
show_speedrLc	cs�|rtd�gng}|�t||	|
|d�t|d�tdd�f�t||||||pLd|
d��}|�|j||||d�Ed	HW5QRXd	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).
        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}�rurvrwrx)rzT)�elapsed_when_finishedrg�rprqrrrsrtry)rornrAN)�
TextColumn�extend�	BarColumn�TaskProgressColumn�TimeRemainingColumnr>�track)rmrnrorprqrrrsrtrurvrwrxrAryrz�columnsr?rIrIrJr�gs:(�����
�r�c@s�eZdZdZd9edeedd�dd�Zdd�d	d
�Ze	e
ee	ee	edd�dd
�Z
ed�dd�Zed�dd�Zeed�dd��Zed�dd�Zed�dd�Zeed�dd��Zeed�dd��Zed�dd�Zed�dd�Zed�d d!�Zd:eed#�d$d%�Zeeee fd&�d'd(�Z!d;eed#�d)d*�Z"d<ee#ed+�d,d-�Z$dd�d.d/�Z%d=eeed1�d2d3�Z&ed�d4d5�Z'e(ed6�d7d8�Z)dS)>�_Readerz9A reader that tracks progress while it's being read from.Tr>N)�handler?�task�close_handlerLcCs"||_||_||_||_d|_dS�NF)r�r?r�r��_closed)rFr�r?r�r�rIrIrJrE�s
z_Reader.__init__rKcCs|j��|SrR)r�rVrUrIrIrJrV�s
z_Reader.__enter__rWcCs|��dSrR)�closer]rIrIrJr^�sz_Reader.__exit__cCs|SrRrIrUrIrIrJ�__iter__�sz_Reader.__iter__cCs$t|j�}|jj|jt|�d�|S�N�rN)�nextr�r?rNr��len)rF�linerIrIrJ�__next__�s
z_Reader.__next__cCs|jSrR)r�rUrIrIrJ�closed�sz_Reader.closedcCs
|j��SrR)r��filenorUrIrIrJr��sz_Reader.filenocCs
|j��SrR)r��isattyrUrIrIrJr��sz_Reader.isattycCs|jjSrR)r��moderUrIrIrJr��sz_Reader.modecCs|jjSrR)r��namerUrIrIrJr��sz_Reader.namecCs
|j��SrR)r��readablerUrIrIrJr��sz_Reader.readablecCs
|j��SrR)r��seekablerUrIrIrJr��sz_Reader.seekablecCsdSr�rIrUrIrIrJ�writable�sz_Reader.writable���)�sizerLcCs&|j�|�}|jj|jt|�d�|Sr�)r��readr?rNr�r�)rFr��blockrIrIrJr��sz_Reader.read)�bcCs"|j�|�}|jj|j|d�|Sr�)r��readintor?rNr�)rFr��nrIrIrJr��sz_Reader.readintocCs&|j�|�}|jj|jt|�d�|Sr�)r��readliner?rNr�r�)rFr�r�rIrIrJr��sz_Reader.readline)�hintrLcCs,|j�|�}|jj|jttt|��d�|Sr�)r��	readlinesr?rNr��sum�mapr�)rFr��linesrIrIrJr��sz_Reader.readlinescCs|jr|j��d|_dS)NT)r�r�r�r�rUrIrIrJr�s
z
_Reader.closer)�offset�whencerLcCs$|j�||�}|jj|j|d�|S)N�rC)r��seekr?rPr�)rFr�r��posrIrIrJr�sz_Reader.seekcCs
|j��SrR)r��tellrUrIrIrJr�
sz_Reader.tell)�srLcCstd��dS)N�write)r
)rFr�rIrIrJr�
sz
_Reader.write)T)r�)r�)r�)r)*r_r`rarbrr:�boolrErVrr#rdrr^r��bytesr��propertyr��intr�r��strr�r�r�r�r�r�r%�	bytearray�
memoryviewrr�r�rr�r�r�r�rr�rIrIrIrJr��sH��

�r�c@sTeZdZdZdedd�dd�Zed�dd	�Zeee	ee	ee
dd
�dd�ZdS)
�_ReadContextzEA utility class to handle a context for both a reader and a progress.r>N)r?�readerrLcCs||_||_dSrR)r?r�)rFr?r�rIrIrJrEsz_ReadContext.__init__rKcCs|j��|j��SrR)r?rTr�rVrUrIrIrJrVs
z_ReadContext.__enter__rWcCs|j��|j�|||�dSrR)r?�stopr�r^r]rIrIrJr^s
z_ReadContext.__exit__)r_r`rarbr<rErVrr#rdrr^rIrIrIrJr�s
�r��
Reading...)rnrprqrrrsrtrurvrwrxry)�filerornrprqrrrsrtrurvrwrxryrLc	Csh|rtd�gng}
|
�t||	|
|d�t�t�f�t|
|||||pDd|d��}|j|||d�}t||�S)aRead 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|rgr~)rorn)rr�r��DownloadColumnr�r>�	wrap_filer�)r�rornrprqrrrsrtrurvrwrxryr�r?r�rIrIrJr�&s0%�����
r�r�)rornrprqrrrsrtrurvrwrxry�
PathLike[str]�rt�r)r�r��	buffering�encoding�errors�newlinerornrprqrrrsrtrurvrwrxryrLcCsdSrRrI�r�r�r�r�r�r�rornrprqrrrsrtrurvrwrxryrIrIrJ�opengsr��rbcCsdSrRrIr�rIrIrJr��sc
Csr|rtd�gng}|�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|rgr~)r�r�r�r�r�rorn)rr�r�r�r�r>r�r�)r�r�r�r�r�r�rornrprqrrrsrtrurvrwrxryr�r?r�rIrIrJr��sB1�����
�
c@sjeZdZUdZdZeeed<deedd�dd�Z	ed�dd	�Z
d
ed�dd
�Ze
d
ed�dd��ZdS)�ProgressColumnz3Base class for a widget to use in progress display.N�max_refresh)�table_columnrLcCs||_i|_d|_dSrR)�
_table_column�_renderable_cacheZ_update_time)rFr�rIrIrJrE�szProgressColumn.__init__rKcCs|jp
t�S)z.Get a table column, used to build tasks table.)r�r6rUrIrIrJ�get_table_column�szProgressColumn.get_table_column�Task�r�rLcCsr|��}|jdk	rT|jsTz|j|j\}}Wntk
r@YnX||j|krT|S|�|�}||f|j|j<|S)aCalled 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)rsr�rCr��id�KeyError�render)rFr��current_time�	timestamp�
renderablerIrIrJ�__call__�s	
zProgressColumn.__call__cCsdS)z"Should return a renderable object.NrI�rFr�rIrIrJr�szProgressColumn.render)N)r_r`rarbr�rrc�__annotations__r6rEr�r/r�rr�rIrIrIrJr��s
r�csDeZdZdZddd�eeed��fdd�Zded	�d
d�Z�Z	S)
�RenderableColumnz�A column to insert an arbitrary column.

    Args:
        renderable (RenderableType, optional): Any renderable. Defaults to empty string.
    �N�r�)r�r�cs||_t�j|d�dS�Nr�)r�rDrE)rFr�r�rGrIrJrE szRenderableColumn.__init__r�r�cCs|jSrR)r�r�rIrIrJr�&szRenderableColumn.render)r�)
r_r`rarbr/rr6rEr�rerIrIrGrJr�s���r�csbeZdZdZdeeeeeee	d��fdd	�
Z
deeeedd
�dd�Zd
ed�dd�Z
�ZS)�
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_nameru�speed�
finished_textr�cs<t|||d�|_t|t�r$t�|�n||_t�j|d�dS)N�rur�r�)	r4�spinner�
isinstancer�r8�from_markupr�rDrE)rFr�rur�r�r�rGrIrJrE4s��zSpinnerColumn.__init__)r��
spinner_styler�rLcCst|||d�|_dS)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)r4r�)rFr�r�r�rIrIrJ�set_spinnerDs
zSpinnerColumn.set_spinnerr�r�cCs |jr|jn|j�|���}|SrR)�finishedr�r�r�rs)rFr��textrIrIrJr�Ss
��zSpinnerColumn.render)r�r�r�r�N)r�r�)r_r`rarbr�rr5rcr9r6rEr�r/r�rerIrIrGrJr�*s,����r�c	sLeZdZdZd
eeeeee	ee
dd��fdd�
Zd	ed
�dd�Z
�ZS)rzA column containing text.�none�leftTN)�text_formatru�justify�markup�highlighterr�rLcs:||_||_||_||_||_t�j|p0tdd�d�dS)NT�Zno_wrapr�)r�r�rur�r�rDrEr6)rFr�rur�r�r�r�rGrIrJrE_s	zTextColumn.__init__r�r�cCsR|jj|d�}|jr*tj||j|jd�}nt||j|jd�}|jrN|j�|�|S�N�r�)rur�)	r��formatr�r8r�rur�r��	highlight)rFr��_textr�rIrIrJr�oszTextColumn.render)r�r�TNN)r_r`rarbr�r5r.r�rr0r6rEr8r�rerIrIrGrJr\s ��rc	sLeZdZdZdeeeeeeeedd��fd	d
�
Zde	d�d
d�Z
�ZS)r�aRenders 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".
    �(rhrirjrkN)�	bar_widthrurvrwrxr�rLcs0||_||_||_||_||_t�j|d�dSr�)r�rurvrwrxrDrE)rFr�rurvrwrxr�rGrIrJrE�s	zBarColumn.__init__r�r�cCs^t|jdk	rtd|j�ndtd|j�|jdkr2dn
td|j�|j|��|j|j|j	|j
d�	S)z&Gets a progress bar widget for a task.Nrr))	rorC�widthZpulseZanimation_timerurvrwrx)r3ro�maxrCr��startedrsrurvrwrxr�rIrIrJr��s
�zBarColumn.render)r�rhrirjrkN)r_r`rarbrr�r5r6rEr3r�rerIrIrGrJr�zs"��r�c@s eZdZdZded�dd�ZdS)�TimeElapsedColumnzRenders time elapsed.r�r�cCsD|jr|jn|j}|dkr&tddd�Stt|�d�}tt|�dd�S)zShow time elapsed.N�-:--:--�progress.elapsed�ru)�seconds)r��
finished_time�elapsedr8rr�r�)rFr�r�deltarIrIrJr��s
zTimeElapsedColumn.renderN�r_r`rarbr8r�rIrIrIrJr��sr�csheZdZdZdeeeeeee	ee
edd	�	�fd
d�
Zeee
ed�d
d��Zded�dd�Z�ZS)r�aShow 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_percentagerur�r�r�r�rzrLc		s(||_||_t�j||||||d�dS)N)r�rur�r�r�r�)r	rzrDrE)	rFr�r	rur�r�r�r�rzrGrIrJrE�s�zTaskProgressColumn.__init__)r�rLcCsT|dkrtddd�St�t|�dddddgd	�\}}||}t|d
�|�d�dd�S)z�Render the speed in iterations per second.

        Args:
            task (Task): A Task object.

        Returns:
            Text: Text object containing the task speed.
        Nr�zprogress.percentageru×10³u×10⁶u×10⁹u×10¹²��z.1fz it/s)r8r*�pick_unit_and_suffixr�)�clsr��unit�suffix�
data_speedrIrIrJ�render_speed�s
�zTaskProgressColumn.render_speedr�r�cCs�|jdkr"|jr"|�|jp|j�S|jdkr2|jn|j}|j|d�}|jr`t	j
||j|jd�}nt	||j|jd�}|j
r�|j
�|�|Sr�)rorzr�finished_speedr�r	r�r�r�r8r�rur�r�r�)rFr�r�r�r�rIrIrJr��s�zTaskProgressColumn.render)rr�r�r�TNNF)r_r`rarbr�r5r.r�rr0r6rE�classmethodrcr8rr�rerIrIrGrJr��s.��r�csDeZdZdZdZdeeeed��fdd�
Zde	d	�d
d�Z
�ZS)
r�aRenders 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�cs||_||_t�j|d�dSr�)rr}rDrE)rFrr}r�rGrIrJrEszTimeRemainingColumn.__init__r�r�cCs�|jr|jr|j}d}n
|j}d}|jdkr8td|d�S|dkrVt|jrLdnd|d�Stt|�d�\}}t|d�\}}|jr�|s�|d	�d
|d	��}n|d�d
|d	�d
|d	��}t||d�S)zShow time remaining.rzprogress.remainingNr�rz--:--r�<Z02d�:�d)	r}r�r�time_remainingror8r�divmodr�)rFr�Z	task_timeru�minutesr�hours�	formattedrIrIrJr�s

zTimeRemainingColumn.render)FFN)r_r`rarbr�r�rr6rEr8r�rerIrIrGrJr��s��
r�c@s eZdZdZded�dd�ZdS)�FileSizeColumnzRenders completed filesize.r�r�cCst�t|j��}t|dd�S)�Show data completed.zprogress.filesizer)r*�decimalr�rCr8�rFr��	data_sizerIrIrJr�,szFileSizeColumn.renderNrrIrIrIrJr)src@s eZdZdZded�dd�ZdS)�TotalFileSizeColumnzRenders total filesize.r�r�cCs*|jdk	rt�t|j��nd}t|dd�S)rNr�zprogress.filesize.totalr)ror*rr�r8r rIrIrJr�5szTotalFileSizeColumn.renderNrrIrIrIrJr"2sr"cs>eZdZdZdeeed��fdd�
Zded�d	d
�Z	�Z
S)�MofNCompleteColumnaHRenders 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�cs||_t�j|d�dSr�)r%rDrE)rFr%r�rGrIrJrEGszMofNCompleteColumn.__init__r�r�cCsPt|j�}|jdk	rt|j�nd}tt|��}t||�d��|j�|��dd�S)zShow completed/total.N�?r�progress.downloadr)r�rCror�r�r8r%)rFr�rCroZtotal_widthrIrIrJr�Ks
�zMofNCompleteColumn.render)r$N)r_r`rarbr�rr6rEr8r�rerIrIrGrJr#;sr#cs@eZdZdZdeeedd��fdd�
Zded�d	d
�Z	�Z
S)r�z�Renders file size downloaded and total, e.g. '0.5/2.3 GB'.

    Args:
        binary_units (bool, optional): Use binary units, KiB, MiB etc. Defaults to False.
    FN)�binary_unitsr�rLcs||_t�j|d�dSr�)r(rDrE)rFr(r�rGrIrJrE]szDownloadColumn.__init__r�r�cCs�t|j�}|jdk	rt|j�n|}|jrNt�|dddddddd	d
g	d�\}}n$t�|ddd
ddddddg	d�\}}|dkr~dnd}||}|d|�d��}|jdk	r�t|j�}	|	|}
|
d|�d��}nd}|�d|�d|��}t|dd�}
|
S)z.Calculate common unit for completed and total.Nr�ZKiBZMiBZGiBZTiBZPiBZEiBZZiBZYiBiZkBZMBZGBZTBZPBZEBZZBZYBr
r)rz,.�fr&r$r�r'r)r�rCror(r*rr8)rFr�rCZ unit_and_suffix_calculation_baser
rZ	precisionZcompleted_ratioZ
completed_strroZtotal_ratioZ	total_strZdownload_statusZ
download_textrIrIrJr�cs2
��
�

zDownloadColumn.render)FN)r_r`rarbr�rr6rEr8r�rerIrIrGrJr�Vs��r�c@s eZdZdZded�dd�ZdS)�TransferSpeedColumnz&Renders human readable transfer speed.r�r�cCs@|jp
|j}|dkr tddd�St�t|��}t|�d�dd�S)zShow data transfer speed.Nr&zprogress.data.speedrz/s)rr�r8r*rr�)rFr�r�rrIrIrJr��s
zTransferSpeedColumn.renderNrrIrIrIrJr*�sr*c@s"eZdZUdZeed<eed<dS)�ProgressSamplez$Sample of progress for a given time.r�rCN)r_r`rarbrcr�rIrIrIrJr+�s
r+c@s�eZdZUdZeed<eed<eeed<eed<e	ed<dZ
eeed<d	Zeed
<e
ed�Zeeefed<e
dd
d
d�Zeeed<e
dd
d
d�Zeeed<dZeeed<e
dd�d
d
d�Zeeed<e
d
ed�Zeed<ed�dd�Zeed�dd��Zeeed�dd��Zeeed�dd ��Zeed�d!d"��Zeed�d#d$��Z eeed�d%d&��Z!eeed�d'd(��Z"dd�d)d*�Z#dS)+r�z�Information regarding a progress task.

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

    r�rnrorC�	_get_timeNrT�visible)�default_factory�fieldsF)�default�init�repr�
start_time�	stop_timercCs
tdd�S)Nr
)�maxlenrrIrIrIrJ�<lambda>��z
Task.<lambda>)r.r1r2�	_progress)r2r.�_lockrKcCs|��S)z(float: Get the current time, in seconds.)r,rUrIrIrJrs�sz
Task.get_timecCs
|jdk	S)z#bool: Check if the task as started.N)r3rUrIrIrJr��szTask.startedcCs|jdkrdS|j|jS)zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N)rorCrUrIrIrJ�	remaining�s
zTask.remainingcCs2|jdkrdS|jdk	r$|j|jS|��|jS)z]Optional[float]: Time elapsed since task was started, or ``None`` if the task hasn't started.N)r3r4rsrUrIrIrJr�s


zTask.elapsedcCs
|jdk	S)zCheck if the task has finished.N)rrUrIrIrJr��sz
Task.finishedcCs.|js
dS|j|jd}tdtd|��}|S)zOfloat: Get progress of task as a percentage. If a None total was set, returns 0��Y@)rorC�minr�)rFrCrIrIrJ�
percentage�s
zTask.percentagec
Cs�|jdkrdS|j�~|j}|s.W5QR�dS|dj|dj}|dkrXW5QR�dSt|�}t|�tdd�|D��}||}|W5QR�SQRXdS)z=Optional[float]: Get the estimated speed in steps per second.Nr�rcss|]}|jVqdSrRr�)�.0�samplerIrIrJ�	<genexpr>szTask.speed.<locals>.<genexpr>)r3r9r8r��iterr�r�)rFr?Z
total_timeZ
iter_progressZtotal_completedr�rIrIrJr��s
z
Task.speedcCs:|jr
dS|j}|sdS|j}|dkr*dSt||�}|S)zJOptional[float]: Get estimated time to completion, or ``None`` if no data.r;N)r�r�r:r)rFr�r:ZestimaterIrIrJrszTask.time_remainingcCs|j��d|_d|_dS)zReset progress.N)r8�clearrrrUrIrIrJ�_resets
zTask._reset)$r_r`rarbr:r�r�rrc�GetTimeCallablerr-r�r�dictr/rrr3r4rr8rr+rr9rsr�r�r:rr�r>r�rrDrIrIrIrJr��sD
�
r�c@s�eZdZdZddddddddddd�
eeefeee	e
e
e	e	e	eee	e	dd�d	d
�Ze
eedfd�d
d��Zeed�dd��Zeeed�dd��Zeeed�dd��Zee	d�dd��Zdd�dd�Zdd�dd�Zdd�dd�Zeeeeeeedd�dd�ZdXeee e!e fee
eeee
ee d"�d#d$�Z"dYdd%d&�e#ee$eeee#d'�d(d)�Z%e&j'dZddd%d+�eed,e(fe)d-e$eeeeeeee$eeee#d.�
d/d0��Z*e&j'd[ddd%d+�eed,e(fee)d1e)d2fe$eeeeeeee$eeee+d.�
d3d0��Z*d\ddd%d+�eed,e(fee)d-e)d2e)d1fe$eeeeeeee$eeeee#e+fd.�
d4d0�Z*edd5�d6d7�Z,edd5�d8d9�Z-ddddddd:�eee
ee
ee
eeee	e	e.dd;�	d<d=�Z/ddd>ddd?�ee	ee
e$ee	eee.dd@�dAdB�Z0d]ee
ddD�dEdF�Z1dd�dGdH�Z2e3d�dIdJ�Z4ee3d�dKdL�Z5eee6dM�dNdO�Z7e3d�dPdQ�Z8d^ee	ee
e$e	e.edS�dTdU�Z9edd5�dVdW�Z:dS)_r>a�Renders an auto-updating progress bar(s).

    Args:
        console (Console, optional): Optional Console instance. Default will 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.
    NTrgg>@F)
rqrprt�speed_estimate_periodrr�redirect_stdout�redirect_stderrrsry�expand)r�rqrprtrGrrrHrIrsryrJrLc
	Gs�|dkstd��t�|_|p"|��|_||_|	|_|
|_i|_t	d�|_
t|pRt�||||||j
d�|_|pr|jj|_|jj|_|jj|_dS)Nrzrefresh_per_second must be > 0)rqrprtrrrHrI�get_renderable)�AssertionErrorrr9�get_default_columnsr�rGryrJ�_tasksr:�_task_indexr2r+rK�liverqrs�print�log)rFrqrprtrGrrrHrIrsryrJr�rIrIrJrE*s(
�	
zProgress.__init__.rKcCstd�t�t�t�fS)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.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{)rr�r�r�)rrIrIrJrMNs
�zProgress.get_default_columnscCs|jjSrR)rPrqrUrIrIrJrqmszProgress.consolec
Cs,|j�t|j���W5QR�SQRXdS)zGet a list of Task instances.N)r9�listrN�valuesrUrIrIrJ�tasksqszProgress.tasksc
Cs,|j�t|j���W5QR�SQRXdS)zA list of task IDs.N)r9rSrN�keysrUrIrIrJ�task_idswszProgress.task_idsc
CsJ|j�:|jsW5QR�dStdd�|j��D��W5QR�SQRXdS)z'Check if all tasks have been completed.Tcss|]}|jVqdSrR)r�)r?r�rIrIrJrA�sz$Progress.finished.<locals>.<genexpr>N)r9rN�allrTrUrIrIrJr�}szProgress.finishedcCs|js|jjdd�dS)zStart the progress display.T)rMN)ryrPrTrUrIrIrJrT�szProgress.startcCs |j��|jjs|j��dS)zStop the progress display.N)rPr�rqZis_interactiverQrUrIrIrJr��s
z
Progress.stopcCs|��|SrRrSrUrIrIrJrV�szProgress.__enter__rWcCs|��dSrR)r�r]rIrIrJr^�szProgress.__exit__rfrl)rmror@rnrArLc
	cs�|dkrtt|��pd}|dkr0|j||d�}n|j||d�|jjr~t|||��$}|D]}|V|jd7_qXW5QRXn,|j}|j	}	|D]}|V||d�|	�q�dS)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).
            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.
        N�ror))
rcr
�add_taskrPrPrpr=rCrNrM)
rFrmror@rnrAZtrack_thread�valuerNrMrIrIrJr��s 
zProgress.trackr�)r@rn)r�ror@rnrLc	Cs~d}|dk	r|}n&|dk	r8|j�|j|j}W5QRX|dkrHtd��|dkr`|j||d�}n|j||d�t|||dd�S)ajTrack 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'rYF�r�)r9rNro�
ValueErrorrZrPr�)rFr�ror@rn�total_bytesrIrIrJr��s�zProgress.wrap_filer�)ror@rnr�r�)
r�r�r�r�r�r�ror@rnrLc
CsdSrRrI�
rFr�r�r�r�r�r�ror@rnrIrIrJr��sz
Progress.openr�r�c
CsdSrRrIr_rIrIrJr��scCs�d�t|dd��}
|
dkr(td�|���|dk}|
dkrR|dkrRt�dt�d	}n&|
d
krx|dkrltd��n|dkrxd	}|d
kr�t|�j}|d
kr�|j	|	|d�}n|j
||d�tj|d|d�}t
|||dd�}
|dkr�tj|
||||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�zinvalid mode {!r}r)razaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr�)r�r�rzcan't have unbuffered text I/ONrYr�)r�Tr\)r�r�)r�r�r��line_buffering)r\�sortedr]r��warnings�warn�RuntimeWarningr�st_sizerZrP�ior�r��
TextIOWrapper)rFr�r�r�r�r�r�ror@rn�_moderbr�r�rIrIrJr�s>!�

�)r@rLc	Cs4|j�$|j|}|jdkr&|��|_W5QRXdS)z�Start a task.

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

        Args:
            task_id (TaskID): ID of task.
        N)r9rNr3rs)rFr@r�rIrIrJ�
start_task\s	

zProgress.start_taskc	Cs>|j�.|j|}|��}|jdkr*||_||_W5QRXdS)z�Stop a task.

        This will freeze the elapsed time on the task.

        Args:
            task_id (TaskID): ID of task.
        N)r9rNrsr3r4)rFr@r�r�rIrIrJ�	stop_taskjs

zProgress.stop_task)rorCrNrnr-rM)	r@rorCrNrnr-rMr/rLc	Ks*|j��
|j|}	|	j}
|dk	r:||	jkr:||	_|	��|dk	rP|	j|7_|dk	r^||	_|dk	rl||	_|dk	rz||	_|	j�|�|	j|
}|�	�}||j
}
|	j}|j}|r�|dj
|
kr�|�q�|dkr�|�t||��|	jdk	�r|	j|	jk�r|	jdk�r|	j|	_W5QRX|�r&|��dS)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)r9rNrCrorDrnr-r/rPrsrGr8�popleftr��appendr+rrrM)rFr@rorCrNrnr-rMr/r��completed_start�update_completedr��old_sample_timer8rmrIrIrJrPysB



�
��zProgress.updater)rTrorCr-rn)r@rTrorCr-rnr/rLc
	Ks�|��}|j�f|j|}	|	��|r*|nd|	_|dk	r>||	_||	_|dk	rR||	_|r\||	_|dk	rj||	_	d|	_
W5QRX|��dS)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)rsr9rNrDr3rorCr-r/rnrrM)
rFr@rTrorCr-rnr/r�r�rIrIrJ�reset�s 
zProgress.resetr))r@rNrLc
	Cs�|��}|j��|j|}|j}|j|7_|j|}||j}|j}|j}	|rh|dj|krh|	�qNt|�dkr||	�qh|�	t
||��|jdk	r�|j|jkr�|jdkr�|j
|_|j|_W5QRXdS)z�Advance task by a number of steps.

        Args:
            task_id (TaskID): ID of task.
            advance (float): Number of steps to advance. Default is 1.
        rr
N)rsr9rNrCrGr8rmr�r�rnr+rorrr�r)
rFr@rNr�r�rorprqr8rmrIrIrJrN�s,


�
��zProgress.advancecCs|js|jjr|j��dS)z*Refresh (render) the progress information.N)ryrPZ
is_startedrMrUrIrIrJrM�szProgress.refreshcCst|���}|S)z*Get a renderable for the progress display.)r-�get_renderables)rFr�rIrIrJrKszProgress.get_renderableccs|�|j�}|VdS)z5Get a number of renderables for the progress display.N)�make_tasks_tablerU)rF�tablerIrIrJrsszProgress.get_renderables)rUrLcsRdd�|jD�}tj|d|jd��}|D]$��jr(|j�fdd�|jD��q(|S)z�Get a table to render the Progress display.

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

        Returns:
            Table: A table instance.
        css.|]&}t|t�rtdd�n
|����VqdS)Tr�N)r�r�r6r��copy)r?Z_columnrIrIrJrAs��z,Progress.make_tasks_table.<locals>.<genexpr>)rr))�paddingrJc3s,|]$}t|t�r|j�d�n|��VqdS)r�N)r�r�r�)r?�columnr�rIrJrA s��)r�r7ZgridrJr-�add_row)rFrUZ
table_columnsrurIr�rJrt
s	�
��
zProgress.make_tasks_tablec
Cs&|j�|��W5QR�SQRXdS)z+Makes the Progress class itself renderable.N)r9rKrUrIrIrJ�__rich__+szProgress.__rich__r<)rnrTrorCr-r/rLc	Ksr|j�Zt|j||||||j|jd�}||j|j<|rB|�|j�|j}tt|j�d�|_W5QRX|��|S)aAdd 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,r9r))	r9r�rOrsrNrkr:r�rM)	rFrnrTrorCr-r/r�Znew_task_indexrIrIrJrZ0s$�
zProgress.add_taskc	Cs|j�|j|=W5QRXdS)z]Delete a task if it exists.

        Args:
            task_id (TaskID): A task ID.

        N)r9rN)rFr@rIrIrJ�remove_task[szProgress.remove_task)NNrfrl)N)r�NNN)r�NNN)r�r�NNN)r))Tr<rT);r_r`rarbr%r�r�rr,r�rcrErErr"rMr�rqrr�rUr:rWr�rTr�rVr#rdrr^rr;r r�rr�r��typing�overloadr�r(r�r!rkrlrrPrrrNrMr/rKrsr7rtrzrZr{rIrIrIrJr>sn�
�$
���,���*�	���	���	�
�M��A��'!��+r>�__main__)�Panel)�Rule)�Syntax)r7a~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_numbersZfoo�barZbaz�1�2�3z:Text may be printed while the progress bars are rendering.z(In fact, [i]any[/i] renderable will workzSuch as [magenta]tables[/]...zPretty printed structures...ZexamplezPretty printed)�typer�z	Syntax...zGive it a try!)�cycle)�record)rqrrz[red]Downloadingr
rYz[green]Processingz[yellow]Thinkingrr�g333333�?g{�G�z�?�d)rfNTNFNrgrhrirjrkrlFT)r�NNN)r�NNN)r�r�NNN)�rh�sysr|rd�abcrr�collectionsrZdataclassesrr�datetimerr	r
�mathrr�operatorr
�osrr�	threadingrrr�typesrrrrrrrrrrrrrr r!r"r#r$r%�version_infor(Zpip._vendor.typing_extensionsr�r*r+rqr,r-r.r/r�r0Zjupyterr1rPr2�progress_barr3r�r4rur5rur6r7r�r8r9r�r:r;rcrEr<r=r�r�r�r�r�r�r}r�r�r�r�r�rr�r�r�r�rr"r#r�r*r+r�r>r_�random�timeZpanelrZruler�Zsyntaxr�ryZprogress_renderables�	itertoolsr�ZexamplesrMr?rZZtask1Ztask2Ztask3r�rP�sleep�randintrRr�rIrIrIrJ�<module>s,P
*��Fd��A���������V*2*I0		1	}P
��
���