HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/site-packages/pip/_vendor/rich/__pycache__/progress.cpython-37.pyc
B

L��g:��@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�xTe|j��s�e|j�e~dd��e|j�ed�d��eo��d��en��dd��dk�r�e|��e�ez���q�WWdQRXdS)��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.�Progressr9)�progress�task_id�
update_periodcs.||_||_||_t�|_d|_t���dS)Nr)r>r?r@r�done�	completed�super�__init__)�selfr>r?r@)�	__class__��=/tmp/pip-unpacked-wheel-hv55ucu3/pip/_vendor/rich/progress.pyrDBsz_TrackThread.__init__N)�returncCsh|j}|jj}|j}d}|jj}x,||�sL|j}||kr"||||�|}q"W|jj|j|jdd�dS)NrT)rB�refresh)r?r>�advancer@rA�waitrB�update)rEr?rKr@Zlast_completedrLrBrGrGrH�runKs
z_TrackThread.runcCs|��|S)N)�start)rErGrGrH�	__enter__Ysz_TrackThread.__enter__)�exc_type�exc_val�exc_tbrIcCs|j��|��dS)N)rA�set�join)rErQrRrSrGrGrH�__exit__]s
z_TrackThread.__exit__)�__name__�
__module__�__qualname__�__doc__�floatrDrNrPrr"�
BaseExceptionrrV�
__classcell__rGrG)rFrHr<?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_styler@�disable�
show_speedrIc	cs�|rtd�gng}|�t||	|
|d�t|d�tdd�f�t||||||pLd|
d��}|�|j||||d�Ed	HWd	QRXd	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.

    z([progress.description]{task.description})rmrnrorp)rrT)�elapsed_when_finishedr_)rhrirjrkrlrq)rgrfr@N)�
TextColumn�extend�	BarColumn�TaskProgressColumn�TimeRemainingColumnr=�track)rerfrgrhrirjrkrlrmrnrorpr@rqrr�columnsr>rGrGrHrygs((
ryc@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_handlerIcCs"||_||_||_||_d|_dS)NF)r|r>r}r~�_closed)rEr|r>r}r~rGrGrHrD�s
z_Reader.__init__)rIcCs|j��|S)N)r|rP)rErGrGrHrP�s
z_Reader.__enter__)rQrRrSrIcCs|��dS)N)�close)rErQrRrSrGrGrHrV�sz_Reader.__exit__cCs|S)NrG)rErGrGrH�__iter__�sz_Reader.__iter__cCs$t|j�}|jj|jt|�d�|S)N)rK)�nextr|r>rKr}�len)rE�linerGrGrH�__next__�s
z_Reader.__next__cCs|jS)N)r)rErGrGrH�closed�sz_Reader.closedcCs
|j��S)N)r|�fileno)rErGrGrHr��sz_Reader.filenocCs
|j��S)N)r|�isatty)rErGrGrHr��sz_Reader.isattycCs|jjS)N)r|�mode)rErGrGrHr��sz_Reader.modecCs|jjS)N)r|�name)rErGrGrHr��sz_Reader.namecCs
|j��S)N)r|�readable)rErGrGrHr��sz_Reader.readablecCs
|j��S)N)r|�seekable)rErGrGrHr��sz_Reader.seekablecCsdS)NFrG)rErGrGrH�writable�sz_Reader.writable���)�sizerIcCs&|j�|�}|jj|jt|�d�|S)N)rK)r|�readr>rKr}r�)rEr��blockrGrGrHr��sz_Reader.read)�bcCs"|j�|�}|jj|j|d�|S)N)rK)r|�readintor>rKr})rEr��nrGrGrHr��sz_Reader.readintocCs&|j�|�}|jj|jt|�d�|S)N)rK)r|�readliner>rKr}r�)rEr�r�rGrGrHr��sz_Reader.readline)�hintrIcCs,|j�|�}|jj|jttt|��d�|S)N)rK)r|�	readlinesr>rKr}�sum�mapr�)rEr��linesrGrGrHr��sz_Reader.readlinescCs|jr|j��d|_dS)NT)r~r|r�r)rErGrGrHr�s
z
_Reader.closer)�offset�whencerIcCs$|j�||�}|jj|j|d�|S)N)rB)r|�seekr>rMr})rEr�r��posrGrGrHr�sz_Reader.seekcCs
|j��S)N)r|�tell)rErGrGrHr�
sz_Reader.tell)�srIcCstd��dS)N�write)r	)rEr�rGrGrHr�
sz
_Reader.write)T)r�)r�)r�)r)*rWrXrYrZrr9�boolrDrPrr"r\rrVr��bytesr��propertyr��intr�r��strr�r�r�r�r�r�r$�	bytearray�
memoryviewrr�r�rr�r�r�r�rr�rGrGrGrHr{�s:

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>�readerrIcCs||_||_dS)N)r>r�)rEr>r�rGrGrHrDsz_ReadContext.__init__)rIcCs|j��|j��S)N)r>rOr�rP)rErGrGrHrPs
z_ReadContext.__enter__)rQrRrSrIcCs|j��|j�|||�dS)N)r>�stopr�rV)rErQrRrSrGrGrHrVs
z_ReadContext.__exit__)rWrXrYrZr;rDrPrr"r\rrVrGrGrGrHr�s
r�z
Reading...)rfrhrirjrkrlrmrnrorprq)�filergrfrhrirjrkrlrmrnrorprqrIc	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.

    z([progress.description]{task.description})rmrnrorpr_)rhrirjrkrlrq)rgrf)rtrurv�DownloadColumnrxr=�	wrap_filer�)r�rgrfrhrirjrkrlrmrnrorprqrzr>r�rGrGrHr�&s&%

r�r�)rgrfrhrirjrkrlrmrnrorprqz
PathLike[str]�rt�r)r�r��	buffering�encoding�errors�newlinergrfrhrirjrkrlrmrnrorprqrIcCsdS)NrG)r�r�r�r�r�r�rgrfrhrirjrkrlrmrnrorprqrGrGrH�opengsr��rbcCsdS)NrG)r�r�r�r�r�r�rgrfrhrirjrkrlrmrnrorprqrGrGrHr��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.

    z([progress.description]{task.description})rmrnrorpr_)rhrirjrkrlrq)r�r�r�r�r�rgrf)rtrurvr�rxr=r�r�)r�r�r�r�r�r�rgrfrhrirjrkrlrmrnrorprqrzr>r�rGrGrHr��s61

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_columnrIcCs||_i|_d|_dS)N)�
_table_column�_renderable_cacheZ_update_time)rEr�rGrGrHrD�szProgressColumn.__init__)rIcCs|jp
t�S)z.Get a table column, used to build tasks table.)r�r5)rErGrGrH�get_table_column�szProgressColumn.get_table_column�Task)r}rIcCsr|��}|jdk	rT|jsTy|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)rkr�rBr��id�KeyError�render)rEr}�current_time�	timestamp�
renderablerGrGrH�__call__�s	
zProgressColumn.__call__cCsdS)z"Should return a renderable object.NrG)rEr}rGrGrHr�szProgressColumn.render)N)rWrXrYrZr�rr[�__annotations__r5rDr�r.r�rr�rGrGrGrHr��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)N)r�)r�rCrD)rEr�r�)rFrGrHrD szRenderableColumn.__init__r�)r}rIcCs|jS)N)r�)rEr}rGrGrHr�&szRenderableColumn.render)r�)
rWrXrYrZr.rr5rDr�r]rGrG)rFrHr�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_namerm�speed�
finished_textr�cs<t|||d�|_t|t�r$t�|�n||_t�j|d�dS)N)rmr�)r�)	r3�spinner�
isinstancer�r7�from_markupr�rCrD)rEr�rmr�r�r�)rFrGrHrD4szSpinnerColumn.__init__)r��
spinner_styler�rIcCst|||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.
        )rmr�N)r3r�)rEr�r�r�rGrGrH�set_spinnerDs
zSpinnerColumn.set_spinnerr�)r}rIcCs |jr|jn|j�|���}|S)N)�finishedr�r�r�rk)rEr}�textrGrGrHr�SszSpinnerColumn.render)r�r�r�r�N)r�r�)rWrXrYrZr�rr4r[r8r5rDr�r.r�r]rGrG)rFrHr�*s$

r�c	sLeZdZdZd
eeeeee	ee
dd��fdd�
Zd	ed
�dd�Z
�ZS)rtzA column containing text.�none�leftTN)�text_formatrm�justify�markup�highlighterr�rIcs:||_||_||_||_||_t�j|p0tdd�d�dS)NT)�no_wrap)r�)r�r�rmr�r�rCrDr5)rEr�rmr�r�r�r�)rFrGrHrD_s	zTextColumn.__init__r�)r}rIcCsR|jj|d�}|jr*tj||j|jd�}nt||j|jd�}|jrN|j�|�|S)N)r})rmr�)	r��formatr�r7r�rmr�r��	highlight)rEr}�_textr�rGrGrHr�oszTextColumn.render)r�r�TNN)rWrXrYrZr�r4r-r�rr/r5rDr7r�r]rGrG)rFrHrt\srtc	sLeZdZdZdeeeeeeeedd��fd	d
�
Zde	d�d
d�Z
�ZS)rvaRenders 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".
    �(�bar.back�bar.complete�bar.finished�	bar.pulseN)�	bar_widthrmrnrorpr�rIcs0||_||_||_||_||_t�j|d�dS)N)r�)r�rmrnrorprCrD)rEr�rmrnrorpr�)rFrGrHrD�s	zBarColumn.__init__r�)r}rIcCs^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()	rgrB�widthZpulseZanimation_timermrnrorp)r2rg�maxrBr��startedrkrmrnrorp)rEr}rGrGrHr��s
zBarColumn.render)r�r�r�r�r�N)rWrXrYrZrr�r4r5rDr2r�r]rGrG)rFrHrvzs	rvc@s eZdZdZded�dd�ZdS)�TimeElapsedColumnzRenders time elapsed.r�)r}rIcCsD|jr|jn|j}|dkr&tddd�Stt|�d�}tt|�dd�S)zShow time elapsed.Nz-:--:--zprogress.elapsed)rm)�seconds)r��
finished_time�elapsedr7rr�r�)rEr}r��deltarGrGrHr��s
zTimeElapsedColumn.renderN)rWrXrYrZr7r�rGrGrGrHr��sr�csheZdZdZdeeeeeee	ee
edd	�	�fd
d�
Zeee
ed�d
d��Zded�dd�Z�ZS)rwaShow 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_percentagermr�r�r�r�rrrIc		s(||_||_t�j||||||d�dS)N)r�rmr�r�r�r�)r�rrrCrD)	rEr�r�rmr�r�r�r�rr)rFrGrHrD�szTaskProgressColumn.__init__)r�rIcCsT|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.percentage)rmu×10³u×10⁶u×10⁹u×10¹²i�z.1fz it/s)r7r)�pick_unit_and_suffixr�)�clsr��unit�suffix�
data_speedrGrGrH�render_speed�s

zTaskProgressColumn.render_speedr�)r}rIcCs�|jdkr"|jr"|�|jp|j�S|jdkr2|jn|j}|j|d�}|jr`t	j
||j|jd�}nt	||j|jd�}|j
r�|j
�|�|S)N)r})rmr�)rgrrr��finished_speedr�r�r�r�r�r7r�rmr�r�r�)rEr}r�r�r�rGrGrHr��szTaskProgressColumn.render)r�r�r�r�TNNF)rWrXrYrZr�r4r-r�rr/r5rD�classmethodr[r7r�r�r]rGrG)rFrHrw�s
rwcsDeZdZdZdZdeeeed��fdd�
Zde	d	�d
d�Z
�ZS)
rxaRenders 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.
    g�?FN)�compactrsr�cs||_||_t�j|d�dS)N)r�)r�rsrCrD)rEr�rsr�)rFrGrHrDszTimeRemainingColumn.__init__r�)r}rIcCs�|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.zprogress.elapsedzprogress.remainingNr�)rmz--:--z-:--:--�<Z02d�:�d)	rsr�r��time_remainingrgr7r��divmodr�)rEr}Z	task_timerm�minutesr��hours�	formattedrGrGrHr�s

zTimeRemainingColumn.render)FFN)rWrXrYrZr�r�rr5rDr7r�r]rGrG)rFrHrx�srxc@s eZdZdZded�dd�ZdS)�FileSizeColumnzRenders completed filesize.r�)r}rIcCst�t|j��}t|dd�S)zShow data completed.zprogress.filesize)rm)r)�decimalr�rBr7)rEr}�	data_sizerGrGrHr�,szFileSizeColumn.renderN)rWrXrYrZr7r�rGrGrGrHr)src@s eZdZdZded�dd�ZdS)�TotalFileSizeColumnzRenders total filesize.r�)r}rIcCs*|jdk	rt�t|j��nd}t|dd�S)zShow data completed.Nr�zprogress.filesize.total)rm)rgr)rr�r7)rEr}rrGrGrHr�5szTotalFileSizeColumn.renderN)rWrXrYrZr7r�rGrGrGrHr2srcs>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�dS)N)r�)rrCrD)rErr�)rFrGrHrDGszMofNCompleteColumn.__init__r�)r}rIcCsPt|j�}|jdk	rt|j�nd}tt|��}t||�d��|j�|��dd�S)zShow completed/total.N�?r�zprogress.download)rm)r�rBrgr�r�r7r)rEr}rBrgZtotal_widthrGrGrHr�Ks
zMofNCompleteColumn.render)rN)rWrXrYrZr�rr5rDr7r�r]rGrG)rFrHr;s
rcs@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�rIcs||_t�j|d�dS)N)r�)r
rCrD)rEr
r�)rFrGrHrD]szDownloadColumn.__init__r�)r}rIc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�ZKiBZMiBZGiBZTiBZPiBZEiBZZiBZYiBiZkBZMBZGBZTBZPBZEBZZBZYBi�r(rz,.�fr	rr�zprogress.download)rm)r�rBrgr
r)r�r7)rEr}rBZ unit_and_suffix_calculation_baser�r�Z	precisionZcompleted_ratioZ
completed_strrgZtotal_ratioZ	total_strZdownload_statusZ
download_textrGrGrHr�cs,



zDownloadColumn.render)FN)rWrXrYrZr�rr5rDr7r�r]rGrG)rFrHr�Vs
r�c@s eZdZdZded�dd�ZdS)�TransferSpeedColumnz&Renders human readable transfer speed.r�)r}rIcCs@|jp
|j}|dkr tddd�St�t|��}t|�d�dd�S)zShow data transfer speed.Nr	zprogress.data.speed)rmz/s)r�r�r7r)rr�)rEr}r�r�rGrGrHr��s
zTransferSpeedColumn.renderN)rWrXrYrZr7r�rGrGrGrHr�src@s"eZdZUdZeed<eed<dS)�ProgressSamplez$Sample of progress for a given time.r�rBN)rWrXrYrZr[r�rGrGrGrHr
�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�rfrgrB�	_get_timeNr�T�visible)�default_factory�fieldsF)�default�init�repr�
start_time�	stop_timer�cCs
tdd�S)Ni�)�maxlen)rrGrGrGrH�<lambda>��z
Task.<lambda>)rrr�	_progress)rr�_lock)rIcCs|��S)z(float: Get the current time, in seconds.)r)rErGrGrHrk�sz
Task.get_timecCs
|jdk	S)z#bool: Check if the task as started.N)r)rErGrGrHr��szTask.startedcCs|jdkrdS|j|jS)zPOptional[float]: Get the number of steps remaining, if a non-None total was set.N)rgrB)rErGrGrH�	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)rrrk)rErGrGrHr��s


zTask.elapsedcCs
|jdk	S)zCheck if the task has finished.N)r�)rErGrGrHr��sz
Task.finishedcCs.|js
dS|j|jd}tdtd|��}|S)zOfloat: Get progress of task as a percentage. If a None total was set, returns 0ggY@)rgrB�minr�)rErBrGrGrH�
percentage�s
zTask.percentagec	Cs||jdkrdS|j�^|j}|s$dS|dj|dj}|dkrDdSt|�}t|�tdd�|D��}||}|SQRXdS)z=Optional[float]: Get the estimated speed in steps per second.Nr�rcss|]}|jVqdS)N)rB)�.0�samplerGrGrH�	<genexpr>szTask.speed.<locals>.<genexpr>)rrrr��iterr�r�)rEr>Z
total_timeZ
iter_progressZtotal_completedr�rGrGrHr��s
z
Task.speedcCs:|jr
dS|j}|sdS|j}|dkr*dSt||�}|S)zJOptional[float]: Get estimated time to completion, or ``None`` if no data.gN)r�r�rr
)rEr�rZestimaterGrGrHr�szTask.time_remainingcCs|j��d|_d|_dS)zReset progress.N)r�clearr�r�)rErGrGrH�_resets
zTask._reset)$rWrXrYrZr9r�r�rr[�GetTimeCallabler�rr�r�dictrrrrrr�rrr
rrrkr�r�rr�r�rr�r�r$rGrGrGrHr��s>

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.
    NTr_g>@F)
rirhrl�speed_estimate_periodrj�redirect_stdout�redirect_stderrrkrq�expand)rzrirhrlr'rjr(r)rkrqr*rIc
	Gs�|dkstd��t�|_|p"|��|_||_|	|_|
|_i|_t	d�|_
t|pRt�||||||j
d�|_|pr|jj|_|jj|_|jj|_dS)Nrzrefresh_per_second must be > 0)rirhrlrjr(r)�get_renderable)�AssertionErrorrr�get_default_columnsrzr'rqr*�_tasksr9�_task_indexr1r*r+�liverirk�print�log)rErirhrlr'rjr(r)rkrqr*rzrGrGrHrD*s&

zProgress.__init__.)rIcCstd�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.
        z([progress.description]{task.description})rtrvrwrx)r�rGrGrHr-NszProgress.get_default_columnscCs|jjS)N)r0ri)rErGrGrHrimszProgress.consolec	Cs |j�t|j���SQRXdS)zGet a list of Task instances.N)r�listr.�values)rErGrGrH�tasksqszProgress.tasksc	Cs |j�t|j���SQRXdS)zA list of task IDs.N)rr3r.�keys)rErGrGrH�task_idswszProgress.task_idsc	Cs4|j�$|jsdStdd�|j��D��SQRXdS)z'Check if all tasks have been completed.Tcss|]}|jVqdS)N)r�)rr}rGrGrHr!�sz$Progress.finished.<locals>.<genexpr>N)rr.�allr4)rErGrGrHr�}szProgress.finishedcCs|js|jjdd�dS)zStart the progress display.T)rJN)rqr0rO)rErGrGrHrO�szProgress.startcCs |j��|jjs|j��dS)zStop the progress display.N)r0r�riZis_interactiver1)rErGrGrHr��s
z
Progress.stopcCs|��|S)N)rO)rErGrGrHrP�szProgress.__enter__)rQrRrSrIcCs|��dS)N)r�)rErQrRrSrGrGrHrV�szProgress.__exit__�
Working...皙�����?)rergr?rfr@rIc
	cs�|dkrtt|��pd}|dkr0|j||d�}n|j||d�|jjr�t|||��(}x |D]}|V|jd7_qZWWdQRXn0|j}|j	}	x"|D]}|V||d�|	�q�WdS)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)rgr()
r[r�add_taskrMr0rhr<rBrKrJ)
rErergr?rfr@Ztrack_thread�valuerKrJrGrGrHry�s 


zProgress.trackz
Reading...)r?rf)r�rgr?rfrIc	Cs~d}|dk	r|}n&|dk	r8|j�|j|j}WdQRX|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')rgF)r~)rr.rg�
ValueErrorr;rMr{)rEr�rgr?rf�total_bytesrGrGrHr��szProgress.wrap_filer�)rgr?rfz
PathLike[str]r�)
r�r�r�r�r�r�rgr?rfrIc
CsdS)NrG)
rEr�r�r�r�r�r�rgr?rfrGrGrHr��sz
Progress.openr�r�c
CsdS)NrG)
rEr�r�r�r�r�r�rgr?rfrGrGrHr��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(r@zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedr�)r�r�rzcan't have unbuffered text I/ON)rgr�)r�T)r~)r�r�)r�r�r��line_buffering)rU�sortedr=r��warnings�warn�RuntimeWarningr�st_sizer;rM�ior�r{�
TextIOWrapper)rEr�r�r�r�r�r�rgr?rf�_moderAr|r�rGrGrHr�s:!

)r?rIc	Cs4|j�$|j|}|jdkr&|��|_WdQRXdS)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)rr.rrk)rEr?r}rGrGrH�
start_task\s	

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

        This will freeze the elapsed time on the task.

        Args:
            task_id (TaskID): ID of task.
        N)rr.rkrr)rEr?r}r�rGrGrH�	stop_taskjs

zProgress.stop_task)rgrBrKrfrrJ)	r?rgrBrKrfrrJrrIc	Ks.|j��|j|}	|	j}
|dk	r:||	jkr:||	_|	��|dk	rP|	j|7_|dk	r^||	_|dk	rl||	_|dk	rz||	_|	j�|�|	j|
}|�	�}||j
}
|	j}|j}x|r�|dj
|
kr�|�q�W|dkr�|�t||��|	jdk	�r|	j|	jk�r|	jdk�r|	j|	_WdQRX|�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)rr.rBrgr$rfrrrMrkr'r�popleftr��appendr
r�r�rJ)rEr?rgrBrKrfrrJrr}�completed_start�update_completedr��old_sample_timerrLrGrGrHrMys<




zProgress.updater)rOrgrBrrf)r?rOrgrBrrfrrIc
	Ks�|��}|j�f|j|}	|	��|r*|nd|	_|dk	r>||	_||	_|dk	rR||	_|r\||	_|dk	rj||	_	d|	_
WdQRX|��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)rkrr.r$rrgrBrrrfr�rJ)
rEr?rOrgrBrrfrr�r}rGrGrH�reset�s 
zProgress.resetr()r?rKrIc
	Cs�|��}|j��|j|}|j}|j|7_|j|}||j}|j}|j}	x|rj|dj|krj|	�qPWxt|�dkr�|	�qnW|�	t
||��|jdk	r�|j|jkr�|jdkr�|j
|_|j|_WdQRXdS)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.
        ri�N)rkrr.rBr'rrLr�r�rMr
rgr�r�r�r�)
rEr?rKr�r}rNrOrPrrLrGrGrHrK�s&






zProgress.advancecCs|js|jjr|j��dS)z*Refresh (render) the progress information.N)rqr0Z
is_startedrJ)rErGrGrHrJ�szProgress.refreshcCst|���}|S)z*Get a renderable for the progress display.)r,�get_renderables)rEr�rGrGrHr+szProgress.get_renderableccs|�|j�}|VdS)z5Get a number of renderables for the progress display.N)�make_tasks_tabler5)rE�tablerGrGrHrRszProgress.get_renderables)r5rIcsVdd�|jD�}tj|d|jd��}x,|D]$��jr*|j�fdd�|jD��q*W|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)T)r�N)r�r�r5r��copy)rZ_columnrGrGrHr!sz,Progress.make_tasks_table.<locals>.<genexpr>)rr()�paddingr*c3s,|]$}t|t�r|j�d�n|��VqdS))r}N)r�r�r�)r�column)r}rGrHr!!s)rzr6Zgridr*r�add_row)rEr5Z
table_columnsrTrG)r}rHrS
s



zProgress.make_tasks_tablec	Cs|j�
|��SQRXdS)z+Makes the Progress class itself renderable.N)rr+)rErGrGrH�__rich__+szProgress.__rich__�Y@)rfrOrgrBrrrIc	Ksr|j�Zt|j||||||j|jd�}||j|j<|rB|�|j�|j}tt|j�d�|_WdQRX|��|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`.
        )rrrrr(N)	rr�r/rkr.rJr9r�rJ)	rErfrOrgrBrrr}Znew_task_indexrGrGrHr;0s"
zProgress.add_taskc	Cs|j�|j|=WdQRXdS)z]Delete a task if it exists.

        Args:
            task_id (TaskID): A task ID.

        N)rr.)rEr?rGrGrH�remove_task[szProgress.remove_task)NNr9r:)N)r�NNN)r�NNN)r�r�NNN)r()TrZrT);rWrXrYrZr$r�r�rr+r�r[r%rDr�r!r-r�rirr�r5r9r7r�rOr�rPr"r\rrVrr:rryrr�r��typing�overloadr�r'r�r rJrKrrMrQrKrJr.r+rRr6rSrYr;r[rGrGrGrHr=s�,
$%#:FLA(6!#r=�__main__)�Panel)�Rule)�Syntax)r6a~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)rirjz[red]Downloadingi�)rgz[green]Processingz[yellow]Thinkingg�?)rKg333333�?g{�G�z�?�d)r^NTNFNr_r`rarbrcrdFT)r�NNN)r�NNN)r�r�NNN)�rG�sysr\rC�abcrr�collectionsrZdataclassesrr�datetimerrr	�mathr
r�operatorr�osr
r�	threadingrrr�typesrrrrrrrrrrrrrrr r!r"r#r$�version_infor'Zpip._vendor.typing_extensionsr�r)r*rir+r,r-r.r�r/Zjupyterr0r0r1�progress_barr2r�r3rmr4rTr5r6r�r7r8r�r9r:r[r%r;r<r�r�ryr{r�r�r]r�r�r�r�r�rtrvr�rwrxrrrr�rr
r�r=rW�random�timeZpanelr_Zruler`ZsyntaxrarXZprogress_renderables�	itertoolsrhZexamplesr-r>r;Ztask1Ztask2Ztask3r�rM�sleep�randintr2r�rGrGrGrH�<module>sbP
*D6d02dXjB*2*I0		1	~P