o
    Ú­jéë  ã                   @  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ƒZT	 		 	!		"		#	$	%	&	'	(	"	!d¨d©dCdD„ZUG dEdF„ dFee!ƒZVG dGdH„ dHe#eS e&eS ƒZWdId!dd"dd#d$d%d&d'd"dJœdªdNdO„ZXejY	P			d«ddId!dd"dd#d$d%d&d'd"dQœd¬d\d]„ƒZZejY	P			d«ddId!dd"dd#d$d%d&d'd"dQœd­d_d]„ƒZZ	`	P			d®ddId!dd"dd#d$d%d&d'd"dQœd¯dcd]„ZZG ddde„ deeƒZ[G dfdg„ dge[ƒZ\G dhdi„ die[ƒZ]G djdk„ dke[ƒZ^G dldm„ dme[ƒZ_G dndo„ doe[ƒZ`G dpdq„ dqe^ƒZaG drds„ dse[ƒZbG dtdu„ due[ƒZcG dvdw„ dwe[ƒZdG dxdy„ dye[ƒZeG dzd{„ d{e[ƒZfG d|d}„ d}e[ƒZgG d~d„ de*ƒZheG d€d�„ d�ƒƒZiG d‚dƒ„ dƒe?ƒZjekd„k�rÍd dllZld dlmZmdd…lnmoZo dd†lpmqZq dd‡lrmsZs ddˆlHmJZJ esd‰dŠd!d‹�ZreJdŒd�dŽƒZHeH td�d�d‘¡ d’eod“ƒd”eHd•d–d—d˜œd™ereqdšƒg	Zud d›lvmwZw eweuƒZxe8d!dœ�Z7eje]ƒ gej y¡ ¢e`ƒ ‘R e7d"d�œŽ�QZzezj{dždŸd �Z|ezj{d¡dŸd �Z}ezj{d¢dd �Z~ezj�sºezj€e|d£d¤� ezj€e}d¥d¤� em �d¦¡ el ‚d d§¡dk �r®ez ƒe„exƒ¡ ezj�r‹W d  ƒ dS W d  ƒ dS 1 �sÆw   Y  dS 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                      s@   e Zd ZdZd‡ fdd	„Zddd„Zddd„Zddd„Z‡  ZS )Ú_TrackThreadz)A thread to periodically update progress.Úprogressú
'Progress'Útask_idú'TaskID'Úupdate_periodÚfloatc                   s2   || _ || _|| _tƒ | _d| _tƒ jdd� d S )Nr   T)Údaemon)r>   r@   rB   r   ÚdoneÚ	completedÚsuperÚ__init__)Úselfr>   r@   rB   ©Ú	__class__© úJ/var/www/html/CropPilot/venv/lib/python3.10/site-packages/rich/progress.pyrH   C   s   z_TrackThread.__init__ÚreturnÚNonec                 C  s~   | j }| jj}| j}d}| jj}||ƒs2| jjjr2| j}||kr)|||| ƒ |}||ƒs2| jjjs| jj	| j | jdd� d S )Nr   T)rF   Úrefresh)
r@   r>   ÚadvancerB   rE   ÚwaitÚliveÚ
is_startedrF   Úupdate)rI   r@   rQ   rB   Úlast_completedrR   rF   rL   rL   rM   ÚrunL   s   üz_TrackThread.runú'_TrackThread'c                 C  ó   |   ¡  | S ©N©Ústart©rI   rL   rL   rM   Ú	__enter__Z   ó   z_TrackThread.__enter__Úexc_typeúOptional[Type[BaseException]]Úexc_valúOptional[BaseException]Úexc_tbúOptional[TracebackType]c                 C  s   | j  ¡  |  ¡  d S rZ   )rE   ÚsetÚjoin©rI   r`   rb   rd   rL   rL   rM   Ú__exit__^   s   
z_TrackThread.__exit__)r>   r?   r@   rA   rB   rC   ©rN   rO   )rN   rX   ©r`   ra   rb   rc   rd   re   rN   rO   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rH   rW   r^   ri   Ú__classcell__rL   rL   rJ   rM   r=   @   s    
	
r=   ú
Working...TFé
   úbar.backúbar.completeúbar.finishedú	bar.pulseçš™™™™™¹?ÚsequenceúIterable[ProgressType]ÚdescriptionÚstrÚtotalúOptional[float]rF   ÚintÚauto_refreshÚboolÚconsoleúOptional[Console]Ú	transientÚget_timeúOptional[Callable[[], float]]Úrefresh_per_secondrC   Ústyler5   Úcomplete_styleÚfinished_styleÚpulse_stylerB   ÚdisableÚ
show_speedrN   c              	   c  sœ   � |rt dƒgng }| t|	|
||d�t|d�tdd�f¡ t||||||p'd|dœŽ}|� |j| ||||d�E d	H  W d	  ƒ d	S 1 sGw   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_finishedrr   ©r   r�   rƒ   r„   r†   r‹   )r|   rF   rz   rB   N)Ú
TextColumnÚextendÚ	BarColumnÚTaskProgressColumnÚTimeRemainingColumnÚProgressÚtrack)rx   rz   r|   rF   r   r�   rƒ   r„   r†   r‡   rˆ   r‰   rŠ   rB   r‹   rŒ   Úcolumnsr>   rL   rL   rM   r—   h   s@   €,ÿüøÿù
û"ÿr—   c                   @  s  e Zd ZdZ	dQdRdd„ZdSdd„ZdTdd„ZdUdd„ZdVdd„Ze	dWdd „ƒZ
dXd"d#„ZdWd$d%„Ze	dYd'd(„ƒZe	dYd)d*„ƒZdWd+d,„ZdWd-d.„ZdWd/d0„ZdZd[d3d4„Zd\d7d8„ZdZd[d9d:„ZdZd]d=d>„Zd^d?d@„Zd_d`dDdE„ZdXdFdG„ZdadJdK„ZdbdNdO„ZdPS )cÚ_Readerz9A reader that tracks progress while it's being read from.TÚhandler   r>   r?   Útaskr:   Úclose_handler€   rN   rO   c                 C  s"   || _ || _|| _|| _d| _d S ©NF)rš   r>   r›   rœ   Ú_closed)rI   rš   r>   r›   rœ   rL   rL   rM   rH   ¹   s
   
z_Reader.__init__ú	'_Reader'c                 C  s   | j  ¡  | S rZ   )rš   r^   r]   rL   rL   rM   r^   Æ   s   
z_Reader.__enter__r`   ra   rb   rc   rd   re   c                 C  ó   |   ¡  d S rZ   )Úcloserh   rL   rL   rM   ri   Ê   ó   z_Reader.__exit__c                 C  s   | S rZ   rL   r]   rL   rL   rM   Ú__iter__Ò   ó   z_Reader.__iter__Úbytesc                 C  s$   t | jƒ}| jj| jt|ƒd� |S ©N©rQ   )Únextrš   r>   rQ   r›   Úlen)rI   ÚlinerL   rL   rM   Ú__next__Õ   s   
z_Reader.__next__c                 C  ó   | j S rZ   )rž   r]   rL   rL   rM   ÚclosedÚ   s   z_Reader.closedr~   c                 C  ó
   | j  ¡ S rZ   )rš   Úfilenor]   rL   rL   rM   r¯   Þ   ó   
z_Reader.filenoc                 C  r®   rZ   )rš   Úisattyr]   rL   rL   rM   r±   á   r°   z_Reader.isattyr{   c                 C  ó   | j jS rZ   )rš   Úmoder]   rL   rL   rM   r³   ä   ó   z_Reader.modec                 C  r²   rZ   )rš   Únamer]   rL   rL   rM   rµ   è   r´   z_Reader.namec                 C  r®   rZ   )rš   Úreadabler]   rL   rL   rM   r¶   ì   r°   z_Reader.readablec                 C  r®   rZ   )rš   Úseekabler]   rL   rL   rM   r·   ï   r°   z_Reader.seekablec                 C  ó   dS r�   rL   r]   rL   rL   rM   Úwritableò   r¤   z_Reader.writableéÿÿÿÿÚsizec                 C  ó&   | j  |¡}| jj| jt|ƒd� |S r¦   )rš   Úreadr>   rQ   r›   r©   )rI   r»   ÚblockrL   rL   rM   r½   õ   ó   z_Reader.readÚbú"Union[bytearray, memoryview, mmap]c                 C  s"   | j  |¡}| jj| j|d� |S r¦   )rš   Úreadintor>   rQ   r›   )rI   rÀ   ÚnrL   rL   rM   rÂ   ú   s   z_Reader.readintoc                 C  r¼   r¦   )rš   Úreadliner>   rQ   r›   r©   )rI   r»   rª   rL   rL   rM   rÄ   ÿ   r¿   z_Reader.readlineÚhintúList[bytes]c                 C  s,   | j  |¡}| jj| jttt|ƒƒd� |S r¦   )rš   Ú	readlinesr>   rQ   r›   ÚsumÚmapr©   )rI   rÅ   ÚlinesrL   rL   rM   rÇ     s   z_Reader.readlinesc                 C  s   | j r| j ¡  d| _d S )NT)rœ   rš   r¡   rž   r]   rL   rL   rM   r¡   	  s   

z_Reader.closer   ÚoffsetÚwhencec                 C  s$   | j  ||¡}| jj| j|d� |S )N©rF   )rš   Úseekr>   rU   r›   )rI   rË   rÌ   ÚposrL   rL   rM   rÎ     s   z_Reader.seekc                 C  r®   rZ   )rš   Útellr]   rL   rL   rM   rÐ     r°   z_Reader.tellÚsr   c                 C  ó   t dƒ‚)NÚwrite©r   )rI   rÑ   rL   rL   rM   rÓ     ó   z_Reader.writerÊ   úIterable[Any]c                 C  rÒ   )NÚ
writelinesrÔ   )rI   rÊ   rL   rL   rM   r×     rÕ   z_Reader.writelinesN)T)
rš   r   r>   r?   r›   r:   rœ   r€   rN   rO   )rN   rŸ   rk   )rN   r   )rN   r¥   ©rN   r€   )rN   r~   )rN   r{   )rº   )r»   r~   rN   r¥   )rÀ   rÁ   )rÅ   r~   rN   rÆ   rj   )r   )rË   r~   rÌ   r~   rN   r~   )rÑ   r   rN   r~   )rÊ   rÖ   rN   rO   )rl   rm   rn   ro   rH   r^   ri   r£   r«   Úpropertyr­   r¯   r±   r³   rµ   r¶   r·   r¹   r½   rÂ   rÄ   rÇ   r¡   rÎ   rÐ   rÓ   r×   rL   rL   rL   rM   r™   ¶   s8    û












r™   c                   @  s.   e Zd ZdZddd	„Zdd
d„Zddd„ZdS )Ú_ReadContextzEA utility class to handle a context for both a reader and a progress.r>   r?   Úreaderr<   rN   rO   c                 C  s   || _ || _d S rZ   )r>   rÛ   )rI   r>   rÛ   rL   rL   rM   rH      s   
z_ReadContext.__init__c                 C  s   | j  ¡  | j ¡ S rZ   )r>   r\   rÛ   r^   r]   rL   rL   rM   r^   $  s   

z_ReadContext.__enter__r`   ra   rb   rc   rd   re   c                 C  s   | j  ¡  | j |||¡ d S rZ   )r>   ÚstoprÛ   ri   rh   rL   rL   rM   ri   (  s   
z_ReadContext.__exit__N)r>   r?   rÛ   r<   rN   rO   )rN   r<   rk   )rl   rm   rn   ro   rH   r^   ri   rL   rL   rL   rM   rÚ     s
    

rÚ   ú
Reading...)rz   r   r�   rƒ   r„   r†   r‡   rˆ   r‰   rŠ   r‹   Úfiler   úContextManager[BinaryIO]c             	   C  sh   |rt dƒgng }| t||	|
|d�tƒ tƒ f¡ t||||||p"d|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Ž   rr   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Û   rL   rL   rM   rá   2  s0   %ÿüøÿù

rá   rº   )r|   rz   r   r�   rƒ   r„   r†   r‡   rˆ   r‰   rŠ   r‹   ú"Union[str, 'PathLike[str]', bytes]r³   ú"Union[Literal['rt'], Literal['r']]Ú	bufferingÚencodingúOptional[str]ÚerrorsÚnewlineúOptional[int]úContextManager[TextIO]c                C  ó   d S rZ   rL   ©rÞ   r³   rä   rå   rç   rè   r|   rz   r   r�   rƒ   r„   r†   r‡   rˆ   r‰   rŠ   r‹   rL   rL   rM   Úopens  ó   rí   úLiteral['rb']c                C  rë   rZ   rL   rì   rL   rL   rM   rí   Œ  rî   Úrú1Union[Literal['rb'], Literal['rt'], Literal['r']]ú7Union[ContextManager[BinaryIO], ContextManager[TextIO]]c             
   C  sr   |rt dƒgng }| t||||d�tƒ tƒ f¡ t|||	|
||p"d|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Ž   rr   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Û   rL   rL   rM   rí   ¥  sB   1ÿüøÿù
ø

c                   @  sL   e Zd ZU dZdZded< ddd	d
„Zddd„Zddd„Ze	ddd„ƒZ
dS )ÚProgressColumnz3Base class for a widget to use in progress display.Nr}   Úmax_refreshÚtable_columnúOptional[Column]rN   rO   c                 C  s   || _ i | _d | _d S rZ   )Ú_table_columnÚ_renderable_cacheÚ_update_time)rI   rõ   rL   rL   rM   rH      s   
zProgressColumn.__init__r6   c                 C  s   | j ptƒ S )z.Get a table column, used to build tasks table.)r÷   r6   r]   rL   rL   rM   Úget_table_column  s   zProgressColumn.get_table_columnr›   ú'Task'r/   c                 C  sp   |  ¡ }| jdur)|js)z
| j|j \}}W n	 ty   Y n
w || j |kr)|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ô   rF   rø   ÚidÚKeyErrorÚrender)rI   r›   Úcurrent_timeÚ	timestampÚ
renderablerL   rL   rM   Ú__call__	  s   	ÿ
zProgressColumn.__call__c                 C  r¸   )z"Should return a renderable object.NrL   ©rI   r›   rL   rL   rM   rþ      s    zProgressColumn.renderrZ   )rõ   rö   rN   rO   )rN   r6   ©r›   rû   rN   r/   )rl   rm   rn   ro   rô   Ú__annotations__rH   rú   r  r   rþ   rL   rL   rL   rM   ró   û  s   
 

ró   c                      s6   e Zd ZdZ	dddœd‡ fd	d
„Zddd„Z‡  ZS )ÚRenderableColumnz�A column to insert an arbitrary column.

    Args:
        renderable (RenderableType, optional): Any renderable. Defaults to empty string.
    Ú N©rõ   r  r/   rõ   rö   c                  ó   || _ tƒ j|d� d S ©Nr  )r  rG   rH   )rI   r  rõ   rJ   rL   rM   rH   ,  ó   zRenderableColumn.__init__r›   rû   rN   c                 C  r¬   rZ   )r  r  rL   rL   rM   rþ   2  s   zRenderableColumn.render)r  )r  r/   rõ   rö   r  ©rl   rm   rn   ro   rH   rþ   rp   rL   rL   rJ   rM   r  %  s    ÿÿr  c                      sH   e Zd ZdZ					dd‡ fdd„Z		dd dd„Zd!dd„Z‡  ZS )"ÚSpinnerColumna‰  A column with a 'spinner' animation.

    Args:
        spinner_name (str, optional): Name of spinner animation. Defaults to "dots".
        style (StyleType, optional): Style of spinner. Defaults to "progress.spinner".
        speed (float, optional): Speed factor of spinner. Defaults to 1.0.
        finished_text (TextType, optional): Text used when task is finished. Defaults to " ".
    Údotsúprogress.spinnerç      ð?ú NÚspinner_namer{   r‡   úOptional[StyleType]ÚspeedrC   Úfinished_textr9   rõ   rö   c                   s<   t |||d�| _t|tƒrt |¡n|| _tƒ j|d� d S )N©r‡   r  r  )	r4   ÚspinnerÚ
isinstancer{   r8   Úfrom_markupr  rG   rH   )rI   r  r‡   r  r  rõ   rJ   rL   rM   rH   @  s   ÿýzSpinnerColumn.__init__Úspinner_stylerN   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  )rI   r  r  r  rL   rL   rM   Úset_spinnerP  s   zSpinnerColumn.set_spinnerr›   rû   r/   c                 C  s$   |j r| j}|S | j | ¡ ¡}|S rZ   )Úfinishedr  r  rþ   r„   )rI   r›   ÚtextrL   rL   rM   rþ   _  s   ÿÿþýzSpinnerColumn.render)r  r  r  r  N)
r  r{   r‡   r  r  rC   r  r9   rõ   rö   )r  r  )r  r{   r  r  r  rC   rN   rO   r  )rl   rm   rn   ro   rH   r  rþ   rp   rL   rL   rJ   rM   r  6  s    úür  c                      s8   e Zd ZdZ					dd‡ fdd„Zddd„Z‡  ZS )r‘   zA column containing text.ÚnoneÚleftTNÚtext_formatr{   r‡   r5   Újustifyr.   Úmarkupr€   ÚhighlighterúOptional[Highlighter]rõ   rö   rN   rO   c                   s:   || _ || _|| _|| _|| _tƒ j|ptdd�d� d S )NT©Úno_wrapr  )r   r!  r‡   r"  r#  rG   rH   r6   )rI   r   r‡   r!  r"  r#  rõ   rJ   rL   rM   rH   k  s   	zTextColumn.__init__r›   rû   r8   c                 C  sR   | j j|d�}| jrtj|| j| jd�}n	t|| j| jd�}| jr'| j |¡ |S ©N©r›   )r‡   r!  )	r   Úformatr"  r8   r  r‡   r!  r#  Ú	highlight)rI   r›   Ú_textr  rL   rL   rM   rþ   {  s   zTextColumn.render)r  r  TNN)r   r{   r‡   r5   r!  r.   r"  r€   r#  r$  rõ   rö   rN   rO   ©r›   rû   rN   r8   r  rL   rL   rJ   rM   r‘   h  s    ùr‘   c                      s:   e Zd ZdZ						dd‡ fdd„Z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".
    é(   rs   rt   ru   rv   NÚ	bar_widthré   r‡   r5   rˆ   r‰   rŠ   rõ   rö   rN   rO   c                   s0   || _ || _|| _|| _|| _tƒ j|d� d S r
  )r.  r‡   rˆ   r‰   rŠ   rG   rH   )rI   r.  r‡   rˆ   r‰   rŠ   rõ   rJ   rL   rM   rH   ‘  s   	zBarColumn.__init__r›   rû   r3   c                 C  s^   t |jdurtd|jƒndtd|jƒ| jdu rdntd| jƒ|j | ¡ | j| j| j	| j
d�	S )z&Gets a progress bar widget for a task.Nr   r)   )	r|   rF   ÚwidthÚpulseÚanimation_timer‡   rˆ   r‰   rŠ   )r3   r|   ÚmaxrF   r.  Ústartedr„   r‡   rˆ   r‰   rŠ   r  rL   rL   rM   rþ   ¡  s   
÷zBarColumn.render)r-  rs   rt   ru   rv   N)r.  ré   r‡   r5   rˆ   r5   r‰   r5   rŠ   r5   rõ   rö   rN   rO   )r›   rû   rN   r3   r  rL   rL   rJ   rM   r“   †  s    ùr“   c                   @  ó   e Zd ZdZd	dd„ZdS )
ÚTimeElapsedColumnzRenders time elapsed.r›   rû   rN   r8   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	   r2  r~   r{   )rI   r›   r;  ÚdeltarL   rL   rM   rþ   ³  s
   zTimeElapsedColumn.renderNr,  ©rl   rm   rn   ro   rþ   rL   rL   rL   rM   r5  °  ó    r5  c                      sL   e Zd ZdZ								d$d%‡ fdd„Zed&dd„ƒZ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  TNFr   r{   Útext_format_no_percentager‡   r5   r!  r.   r"  r€   r#  r$  rõ   rö   rŒ   rN   rO   c	           	        s(   || _ || _tƒ j||||||d� d S )N)r   r‡   r!  r"  r#  rõ   )r@  rŒ   rG   rH   )	rI   r   r@  r‡   r!  r"  r#  rõ   rŒ   rJ   rL   rM   rH   Ê  s   
úzTaskProgressColumn.__init__r  r}   r8   c                 C  sN   |du r
t ddd�S t t|ƒg d¢d¡\}}|| }t |d›|› d�dd�S )	zµRender the speed in iterations per second.

        Args:
            task (Task): A Task object.

        Returns:
            Text: Text object containing the task speed.
        Nr  zprogress.percentager8  )r  u   Ã—10Â³u   Ã—10â�¶u   Ã—10â�¹u   Ã—10Â¹Â²éè  z.1fz it/s)r8   r*   Úpick_unit_and_suffixr~   )Úclsr  ÚunitÚsuffixÚ
data_speedrL   rL   rM   Úrender_speedà  s   
ýzTaskProgressColumn.render_speedr›   rû   c                 C  sˆ   |j d u r| jr|  |jp|j¡S |j d u r| jn| j}|j|d�}| jr0t	j
|| j| jd�}n	t	|| j| jd�}| jrB| j |¡ |S r'  )r|   rŒ   rG  Úfinished_speedr  r@  r   r)  r"  r8   r  r‡   r!  r#  r*  )rI   r›   r   r+  r  rL   rL   rM   rþ   ô  s   ÿzTaskProgressColumn.render)r?  r  r  r  TNNF)r   r{   r@  r{   r‡   r5   r!  r.   r"  r€   r#  r$  rõ   rö   rŒ   r€   rN   rO   )r  r}   rN   r8   r,  )	rl   rm   rn   ro   rH   ÚclassmethodrG  rþ   rp   rL   rL   rJ   rM   r”   ¼  s    ÷r”   c                      s8   e Zd ZdZdZ			dd‡ fd
d„Zddd„Z‡  ZS )r•   a  Renders estimated time remaining.

    Args:
        compact (bool, optional): Render MM:SS when time remaining is less than an hour. Defaults to False.
        elapsed_when_finished (bool, optional): Render time elapsed when the task is finished. Defaults to False.
    ç      à?FNÚcompactr€   r�   rõ   rö   c                   s   || _ || _tƒ j|d� d S r
  )rK  r�   rG   rH   )rI   rK  r�   rõ   rJ   rL   rM   rH     s   zTimeRemainingColumn.__init__r›   rû   rN   r8   c                 C  sÀ   | j r|jr|j}d}n|j}d}|jdu rtd|d�S |du r.t| jr)d|d�S d|d�S tt|ƒdƒ\}}t|dƒ\}}| jrM|sM|d	›d
|d	›�}n|d›d
|d	›d
|d	›�}t||d�S )zShow time remaining.r7  zprogress.remainingNr  r8  z--:--r6  é<   Ú02dú:Úd)	r�   r  r:  Útime_remainingr|   r8   rK  Údivmodr~   )rI   r›   Ú	task_timer‡   Úminutesr9  ÚhoursÚ	formattedrL   rL   rM   rþ     s   

zTimeRemainingColumn.render)FFN)rK  r€   r�   r€   rõ   rö   r,  )rl   rm   rn   ro   rô   rH   rþ   rp   rL   rL   rJ   rM   r•     s    ü
r•   c                   @  r4  )
ÚFileSizeColumnzRenders completed filesize.r›   rû   rN   r8   c                 C  s   t  t|jƒ¡}t|dd�S )úShow data completed.zprogress.filesizer8  )r*   Údecimalr~   rF   r8   ©rI   r›   Ú	data_sizerL   rL   rM   rþ   7  s   zFileSizeColumn.renderNr,  r=  rL   rL   rL   rM   rV  4  r>  rV  c                   @  r4  )
ÚTotalFileSizeColumnzRenders total filesize.r›   rû   rN   r8   c                 C  s*   |j durt t|j ƒ¡nd}t|dd�S )rW  Nr  zprogress.filesize.totalr8  )r|   r*   rX  r~   r8   rY  rL   rL   rM   rþ   @  s   zTotalFileSizeColumn.renderNr,  r=  rL   rL   rL   rM   r[  =  r>  r[  c                      s.   e Zd ZdZdd‡ fdd	„Zddd„Z‡  ZS )ÚMofNCompleteColumnaH  Renders completed count/total, e.g. '  10/1000'.

    Best for bounded tasks with int quantities.

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

    Args:
        separator (str, optional): Text to separate completed and total values. Defaults to "/".
    ú/NÚ	separatorr{   rõ   rö   c                   r	  r
  )r^  rG   rH   )rI   r^  rõ   rJ   rL   rM   rH   R  s   zMofNCompleteColumn.__init__r›   rû   rN   r8   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ú?rO  úprogress.downloadr8  )r~   rF   r|   r©   r{   r8   r^  )rI   r›   rF   r|   Útotal_widthrL   rL   rM   rþ   V  s   
þzMofNCompleteColumn.render)r]  N)r^  r{   rõ   rö   r,  r  rL   rL   rJ   rM   r\  F  s    r\  c                      s0   e Zd ZdZ	dd‡ fd
d„Zddd„Z‡  ZS )rà   z¤Renders file size downloaded and total, e.g. '0.5/2.3 GB'.

    Args:
        binary_units (bool, optional): Use binary units, KiB, MiB etc. Defaults to False.
    FNÚbinary_unitsr€   rõ   rö   rN   rO   c                   r	  r
  )rb  rG   rH   )rI   rb  rõ   rJ   rL   rM   rH   h  r  zDownloadColumn.__init__r›   rû   r8   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r1dnd}|| }|d|› d	�›}|jdurVt |jƒ}	|	| }
|
d|› d	�›}nd
}|› d|› d|› �}t|dd�}|S )z.Calculate common unit for completed and total.N)	r¥   ÚKiBÚMiBÚGiBÚTiBÚPiBÚEiBÚZiBÚYiBi   )	r¥   ÚkBÚMBÚGBÚTBÚPBÚEBÚZBÚYBrA  r)   r   z,.Úfr_  r]  r  r`  r8  )r~   rF   r|   rb  r*   rB  r8   )rI   r›   rF   Ú unit_and_suffix_calculation_baserD  rE  Ú	precisionÚcompleted_ratioÚcompleted_strr|   Útotal_ratioÚ	total_strÚdownload_statusÚdownload_textrL   rL   rM   rþ   n  s2   
ÿ
ýý

zDownloadColumn.render)FN)rb  r€   rõ   rö   rN   rO   r,  r  rL   rL   rJ   rM   rà   a  s
    ÿrà   c                   @  r4  )
ÚTransferSpeedColumnz&Renders human readable transfer speed.r›   rû   rN   r8   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.Nr_  zprogress.data.speedr8  z/s)rH  r  r8   r*   rX  r~   )rI   r›   r  rF  rL   rL   rM   rþ   •  s
   zTransferSpeedColumn.renderNr,  r=  rL   rL   rL   rM   r|  ’  r>  r|  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.rC   r   rF   N)rl   rm   rn   ro   r  rL   rL   rL   rM   r}  ž  s   
 r}  c                   @  sX  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 < 	 d5d"d#„Zed6d$d%„ƒZed7d&d'„ƒZed7d(d)„ƒZed6d*d+„ƒZed5d,d-„ƒZed7d.d/„ƒZed7d0d1„ƒZd8d3d4„ZdS )9ÚTaskz…Information regarding a progress task.

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

    r:   rü   r{   rz   r}   r|   rC   rF   ÚGetTimeCallableÚ	_get_timeNr:  Tr€   Úvisible)Údefault_factoryzDict[str, Any]ÚfieldsF)ÚdefaultÚinitÚreprÚ
start_timeÚ	stop_timerH  c                   C  s
   t dd�S )NrA  )Úmaxlenr   rL   rL   rL   rM   Ú<lambda>Ñ  s   
 zTask.<lambda>)r‚  r…  r†  zDeque[ProgressSample]Ú	_progress)r†  r‚  r   Ú_lockrN   c                 C  s   |   ¡ S )z(float: Get the current time, in seconds.)r€  r]   rL   rL   rM   r„   ×  r´   zTask.get_timec                 C  ó
   | j duS )z#bool: Check if the task as started.N)r‡  r]   rL   rL   rM   r3  Û  ó   
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|   rF   r]   rL   rL   rM   Ú	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)r‡  rˆ  r„   r]   rL   rL   rM   r;  ç  s
   

zTask.elapsedc                 C  r�  )zCheck if the task has finished.N)r:  r]   rL   rL   rM   r  ð  rŽ  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|   rF   Úminr2  )rI   rF   rL   rL   rM   Ú
percentageõ  s
   zTask.percentagec                 C  s°   | j du rdS | j�D | j}|s	 W d  ƒ dS |d j|d j }|dkr0	 W d  ƒ dS t|ƒ}t|ƒ tdd„ |D ƒƒ}|| }|W  d  ƒ S 1 sQw   Y  dS )z=Optional[float]: Get the estimated speed in steps per second.Nrº   r   c                 s  ó   � | ]}|j V  qd S rZ   rÍ   )Ú.0ÚsamplerL   rL   rM   Ú	<genexpr>  ó   € zTask.speed.<locals>.<genexpr>)r‡  rŒ  r‹  r   Úiterr¨   rÈ   )rI   r>   Ú
total_timeÚiter_progressÚtotal_completedr  rL   rL   rM   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.r‘  N)r  r  r�  r   )rI   r  r�  ÚestimaterL   rL   rM   rP    s   zTask.time_remainingrO   c                 C  s   | j  ¡  d| _d| _dS )zReset progress.N)r‹  Úclearr:  rH  r]   rL   rL   rM   Ú_reset  s   

zTask._reset)rN   rC   rØ   )rN   r}   rj   )rl   rm   rn   ro   r  r:  r�  r   Údictrƒ  r‡  rˆ  rH  r‹  r   rŒ  r„   rÙ   r3  r�  r;  r  r”  r  rP  r   rL   rL   rL   rM   r~  §  sZ   
 
ÿ
r~  c                   @  sÖ  e Zd ZdZdddddddddddœ
dŒdd„Zed�dd„ƒZedŽd d!„ƒZed�d#d$„ƒZ	ed�d&d'„ƒZ
ed‘d(d)„ƒZd’d*d+„Zd’d,d-„Zd“d/d0„Zd”d7d8„Z		9		:	;d•d–dGdH„Z	d—ddIdJœd˜dNdO„Zej	P			d™dddIdQœdšdZd[„ƒZej	P			d™dddIdQœd›d^d[„ƒZ	_	P			dœdddIdQœd�dbd[„Zdžddde„Zdždfdg„ZdddddddhœdŸdodp„Zddd9dddqœd dsdt„Zd¡d¢dvdw„Zd’dxdy„Zd£d{d|„Zd¤d~d„Zd¥dƒd„„Zd£d…d†„Z		‡	9	d¦d§dˆd‰„ZdždŠd‹„Z dS )¨r–   ad  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 (float, optional): Number of times per second to refresh the progress information. Defaults to 10.
        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.
    NTrr   g      >@F)
r�   r   r†   Úspeed_estimate_periodrƒ   Úredirect_stdoutÚredirect_stderrr„   r‹   Úexpandr˜   úUnion[str, ProgressColumn]r�   r‚   r   r€   r†   rC   r¢  rƒ   r£  r¤  r„   úOptional[GetTimeCallable]r‹   r¥  rN   rO   c       
      	   G  sŽ   |dksJ dƒ‚t ƒ | _|p|  ¡ | _|| _|	| _|
| _i | _tdƒ| _	t
|p)tƒ |||||| jd�| _|p9| jj| _| jj| _| jj| _d S )Nr   zrefresh_per_second must be > 0)r�   r   r†   rƒ   r£  r¤  Úget_renderable)r   rŒ  Úget_default_columnsr˜   r¢  r‹   r¥  Ú_tasksr:   Ú_task_indexr2   r+   r¨  rS   r�   r„   ÚprintÚlog)rI   r�   r   r†   r¢  rƒ   r£  r¤  r„   r‹   r¥  r˜   rL   rL   rM   rH   5  s(   
ù	
zProgress.__init__úTuple[ProgressColumn, ...]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•   )rC  rL   rL   rM   r©  Y  s
   üzProgress.get_default_columnsr,   c                 C  r²   rZ   )rS   r�   r]   rL   rL   rM   r�   x  r´   zProgress.consoleú
List[Task]c                 C  ó8   | j � t| j ¡ ƒW  d  ƒ S 1 sw   Y  dS )zGet a list of Task instances.N)rŒ  Úlistrª  Úvaluesr]   rL   rL   rM   Útasks|  ó   $ÿzProgress.tasksúList[TaskID]c                 C  r°  )zA list of task IDs.N)rŒ  r±  rª  Úkeysr]   rL   rL   rM   Útask_ids‚  r´  zProgress.task_idsc                 C  sZ   | j �  | js	 W d  ƒ dS tdd„ | j ¡ D ƒƒW  d  ƒ S 1 s&w   Y  dS )z'Check if all tasks have been completed.NTc                 s  r•  rZ   )r  )r–  r›   rL   rL   rM   r˜  Ž  r™  z$Progress.finished.<locals>.<genexpr>)rŒ  rª  Úallr²  r]   rL   rL   rM   r  ˆ  s   þ$ýzProgress.finishedc                 C  s   | j s| jjdd� dS dS )zStart the progress display.T)rP   N)r‹   rS   r\   r]   rL   rL   rM   r\   �  s   ÿzProgress.startc                 C  s:   | j s| j ¡  | jjs| jjs| j ¡  dS dS dS dS )zStop the progress display.N)r‹   rS   rÜ   r�   Úis_interactiveÚ
is_jupyterr¬  r]   rL   rL   rM   rÜ   •  s   
ýzProgress.stopr(   c                 C  rY   rZ   r[   r]   rL   rL   rM   r^   œ  r_   zProgress.__enter__r`   ra   rb   rc   rd   re   c                 C  r    rZ   )rÜ   rh   rL   rL   rM   ri      r¢   zProgress.__exit__r   rq   rw   rx   ry   r|   r}   rF   r~   r@   úOptional[TaskID]rz   r{   rB   c                 c  sÌ   � |du rt t|ƒƒpd}|du r| j|||d�}n| j|||d� | jjrNt| ||ƒ�}|D ]}|V  | jd7  _q/W d  ƒ dS 1 sGw   Y  dS | j}	| j	}
|D ]}|V  |	|dƒ |
ƒ  qVd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.
        Nr�  r)   )
rC   r   Úadd_taskrU   rS   r   r=   rF   rQ   rP   )rI   rx   r|   rF   r@   rz   rB   Útrack_threadÚvaluerQ   rP   rL   rL   rM   r—   ¨  s(   €þ"ÿ
ýzProgress.trackrÝ   )r@   rz   rÞ   r   ré   c                C  s’   d}|dur	|}n|dur&| j � | j| j}W d  ƒ n1 s!w   Y  |du r.tdƒ‚|du r:| j||d�}n| j||d� t|| |dd�S )aj  Track progress file reading from a binary file.

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

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

        Raises:
            ValueError: When no total value can be extracted from the arguments or the task.
        Nz?unable to get the total number of bytes, please specify 'total'©r|   F©rœ   )rŒ  rª  r|   Ú
ValueErrorr¼  rU   r™   )rI   rÞ   r|   r@   rz   Útotal_bytesrL   rL   rM   rá   Õ  s   ÿÿzProgress.wrap_filerº   )r|   r@   rz   râ   r³   rï   rä   rå   ræ   rç   rè   c          
      C  rë   rZ   rL   ©
rI   rÞ   r³   rä   rå   rç   rè   r|   r@   rz   rL   rL   rM   rí   ÿ  ó   zProgress.openú"Union[Literal['r'], Literal['rt']]r#   c          
      C  rë   rZ   rL   rÃ  rL   rL   rM   rí     rÄ  rð   rñ   úUnion[BinaryIO, TextIO]c                C  sî   d  t|dd�¡}
|
dvrtd|›�ƒ‚|dk}|
dkr)|dkr)t dt¡ d	}n|
d
v r;|dkr5tdƒ‚|dkr;d	}|du rDt|ƒj}|du rP| j|	|d�}n| j	||d� t
j|d|d�}t|| |dd�}|dv rut
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)   rÈ  zaline buffering (buffering=1) isn't supported in binary mode, the default buffer size will be usedrº   )rÉ  rð   r   zcan't have unbuffered text I/ONr¿  Úrb)rä   TrÀ  )rð   rÉ  )rå   rç   rè   Úline_buffering)rg   ÚsortedrÁ  ÚwarningsÚwarnÚRuntimeWarningr   Úst_sizer¼  rU   Úiorí   r™   ÚTextIOWrapper)rI   rÞ   r³   rä   rå   rç   rè   r|   r@   rz   Ú_moderË  rš   rÛ   rL   rL   rM   rí     s>   !þ
ûr:   c                 C  sZ   | j �  | j| }|jdu r|  ¡ |_W d  ƒ dS W d  ƒ dS 1 s&w   Y  dS )zéStart a task.

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

        Args:
            task_id (TaskID): ID of task.
        N)rŒ  rª  r‡  r„   )rI   r@   r›   rL   rL   rM   Ú
start_taskl  s   	

ý"þzProgress.start_taskc                 C  sT   | j � | j| }|  ¡ }|jdu r||_||_W d  ƒ dS 1 s#w   Y  dS )z†Stop a task.

        This will freeze the elapsed time on the task.

        Args:
            task_id (TaskID): ID of task.
        N)rŒ  rª  r„   r‡  rˆ  )rI   r@   r›   rÿ   rL   rL   rM   Ú	stop_taskz  s   

"ûzProgress.stop_task)r|   rF   rQ   rz   r�  rP   rQ   r�  úOptional[bool]rP   rƒ  r   c                K  sH  | j �� | j| }	|	j}
|dur||	jkr||	_|	 ¡  |dur'|	 j|7  _|dur.||	_|dur5||	_|dur<||	_|	j |¡ |	j|
 }|  	¡ }|| j
 }|	j}|j}|rk|d j|k rk|ƒ  |rk|d j|k s_|dkrw| t||ƒ¡ |	jdur‹|	j|	jkr‹|	jdu r‹|	j|	_W d  ƒ n1 s•w   Y  |r¢|  ¡  dS dS )a˜  Update information associated with a task.

        Args:
            task_id (TaskID): Task id (returned by add_task).
            total (float, optional): Updates task.total if not None.
            completed (float, optional): Updates task.completed if not None.
            advance (float, optional): Add a value to task.completed if not None.
            description (str, optional): Change task description if not None.
            visible (bool, optional): Set visible flag if not None.
            refresh (bool): Force a refresh of progress information. Default is False.
            **fields (Any): Additional data fields required for rendering.
        Nr   )rŒ  rª  rF   r|   r   rz   r�  rƒ  rU   r„   r¢  r‹  Úpopleftr   Úappendr}  r:  r;  rP   )rI   r@   r|   rF   rQ   rz   r�  rP   rƒ  r›   Úcompleted_startÚupdate_completedrÿ   Úold_sample_timer‹  r×  rL   rL   rM   rU   ‰  sD   


ÿ

€à"ÿzProgress.update)r\   r|   rF   r�  rz   r\   c          
      K  sš   |   ¡ }| j�8 | j| }	|	 ¡  |r|nd|	_|dur||	_||	_|dur)||	_|r.||	_|dur5||	_	d|	_
W d  ƒ n1 sBw   Y  |  ¡  dS )ax  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): Set visible flag if not None.
            description (str, optional): Change task description if not None. Defaults to None.
            **fields (str): Additional data fields required for rendering.
        N)r„   rŒ  rª  r   r‡  r|   rF   r�  rƒ  rz   r:  rP   )
rI   r@   r\   r|   rF   r�  rz   rƒ  rÿ   r›   rL   rL   rM   ÚresetÆ  s"   
ózProgress.resetr)   c           
      C  s*  |   ¡ }| j�„ | j| }|j}| j|7  _|j| }|| j }|j}|j}	|r<|d j|k r<|	ƒ  |r<|d j|k s0t|ƒdkrK|	ƒ  t|ƒdksB| 	t
||ƒ¡ |jdurs|j|jkr{|jdu rƒ|j|_|j|_W d  ƒ dS W d  ƒ dS W d  ƒ dS W d  ƒ dS 1 sŽw   Y  dS )z«Advance task by a number of steps.

        Args:
            task_id (TaskID): ID of task.
            advance (float): Number of steps to advance. Default is 1.
        r   rA  N)r„   rŒ  rª  rF   r¢  r‹  r×  r   r©   rØ  r}  r|   r:  r;  r  rH  )
rI   r@   rQ   rÿ   r›   rÙ  rÚ  rÛ  r‹  r×  rL   rL   rM   rQ   í  s8   


ÿÿ


ìñð"ïzProgress.advancec                 C  s$   | j s| jjr| j ¡  dS dS dS )z*Refresh (render) the progress information.N)r‹   rS   rT   rP   r]   rL   rL   rM   rP     s   ÿzProgress.refreshr/   c                 C  s   t |  ¡ Ž }|S )z*Get a renderable for the progress display.)r-   Úget_renderables)rI   r  rL   rL   rM   r¨    s   zProgress.get_renderableúIterable[RenderableType]c                 c  s   � |   | j¡}|V  dS )z5Get a number of renderables for the progress display.N)Úmake_tasks_tabler³  )rI   ÚtablerL   rL   rM   rÝ    s   €
zProgress.get_renderablesr³  úIterable[Task]r7   c                   sR   dd„ | j D ƒ}tj|d| jdœŽ}|D ]‰ ˆ jr&|j‡ fdd„| j D ƒŽ  q|S )z×Get a table to render the Progress display.

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

        Returns:
            Table: A table instance.
        c                 s  s0   � | ]}t |tƒrtd d�n| ¡  ¡ V  qdS )Tr%  N)r  r{   r6   rú   Úcopy)r–  Ú_columnrL   rL   rM   r˜  #  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  r{   r)  )r–  Úcolumnr(  rL   rM   r˜  0  s   € ýÿ
ü)r˜   r7   Úgridr¥  r�  Úadd_row)rI   r³  Útable_columnsrà  rL   r(  rM   rß    s   	ú
úÿ€
zProgress.make_tasks_tablec                 C  s2   | j � |  ¡ W  d  ƒ S 1 sw   Y  dS )z+Makes the Progress class itself renderable.N)rŒ  r¨  r]   rL   rL   rM   Ú__rich__;  s   $ÿzProgress.__rich__r’  c           	      K  s†   | j �2 t| j|||||| j| j d�}|| j| j< |r!|  | j¡ | j}tt| jƒd ƒ| _W d  ƒ n1 s8w   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€  rŒ  r)   N)	rŒ  r~  r«  r„   rª  rÔ  r:   r~   rP   )	rI   rz   r\   r|   rF   r�  rƒ  r›   Únew_task_indexrL   rL   rM   r¼  @  s&   ø
ñzProgress.add_taskc                 C  s4   | j � | j|= W d  ƒ dS 1 sw   Y  dS )z]Delete a task if it exists.

        Args:
            task_id (TaskID): A task ID.

        N)rŒ  rª  )rI   r@   rL   rL   rM   Úremove_taskk  s   
"ÿzProgress.remove_task)r˜   r¦  r�   r‚   r   r€   r†   rC   r¢  rC   rƒ   r€   r£  r€   r¤  r€   r„   r§  r‹   r€   r¥  r€   rN   rO   )rN   r®  )rN   r,   )rN   r¯  )rN   rµ  rØ   rj   )rN   r(   rk   )Nr   Nrq   rw   )rx   ry   r|   r}   rF   r~   r@   r»  rz   r{   rB   rC   rN   ry   rZ   )
rÞ   r   r|   ré   r@   r»  rz   r{   rN   r   ©rº   NNN)rÞ   râ   r³   rï   rä   r~   rå   ræ   rç   ræ   rè   ræ   r|   ré   r@   r»  rz   r{   rN   r   )rÞ   râ   r³   rÅ  rä   r~   rå   ræ   rç   ræ   rè   ræ   r|   ré   r@   r»  rz   r{   rN   r#   ©rð   rº   NNN)rÞ   râ   r³   rñ   rä   r~   rå   ræ   rç   ræ   rè   ræ   r|   ré   r@   r»  rz   r{   rN   rÆ  )r@   r:   rN   rO   )r@   r:   r|   r}   rF   r}   rQ   r}   rz   ræ   r�  rÖ  rP   r€   rƒ  r   rN   rO   )r@   r:   r\   r€   r|   r}   rF   r~   r�  rÖ  rz   ræ   rƒ  r   rN   rO   )r)   )r@   r:   rQ   rC   rN   rO   )rN   r/   )rN   rÞ  )r³  rá  rN   r7   )Tr’  r   T)rz   r{   r\   r€   r|   r}   rF   r~   r�  r€   rƒ  r   rN   r:   )!rl   rm   rn   ro   rH   rI  r©  rÙ   r�   r³  r·  r  r\   rÜ   r^   ri   r—   rá   ÚtypingÚoverloadrí   rÔ  rÕ  rU   rÜ  rQ   rP   r¨  rÝ  rß  ré  r¼  rë  rL   rL   rL   rM   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)Úline_numbersÚfooÚbarÚbazÚ1Ú2Ú3z:Text may be printed while the progress bars are rendering.z(In fact, [i]any[/i] renderable will workzSuch as [magenta]tables[/]...zPretty printed structures...ÚexamplezPretty printed)Útyper  z	Syntax...zGive it a try!)Úcycle)Úrecord)r�   rƒ   z[red]DownloadingrA  r¿  z[green]Processingz[yellow]ThinkingrJ  r§   g333333Ó?g{®Gáz„?éd   )rq   Nr   TNFNrr   rs   rt   ru   rv   rw   FT)"rx   ry   rz   r{   r|   r}   rF   r~   r   r€   r�   r‚   rƒ   r€   r„   r…   r†   rC   r‡   r5   rˆ   r5   r‰   r5   rŠ   r5   rB   rC   r‹   r€   rŒ   r€   rN   ry   )rÞ   r   r|   r~   rz   r{   r   r€   r�   r‚   rƒ   r€   r„   r…   r†   rC   r‡   r5   rˆ   r5   r‰   r5   rŠ   r5   r‹   r€   rN   rß   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†   rC   r‡   r5   rˆ   r5   r‰   r5   rŠ   r5   r‹   r€   rN   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†   rC   r‡   r5   rˆ   r5   r‰   r5   rŠ   r5   r‹   r€   rN   rß   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†   rC   r‡   r5   rˆ   r5   r‰   r5   rŠ   r5   r‹   r€   rN   rò   )…Ú
__future__r   rÑ  rî  rÍ  Úabcr   r   Úcollectionsr   Ú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'   Útyping_extensionsr(   r  r*   r+   r�   r,   r-   r.   r/   r#  r0   Újupyterr1   rS   r2   Úprogress_barr3   r  r4   r‡   r5   rà  r6   r7   r  r8   r9   r~   r:   r;   rC   r  r<   r=   r—   r™   rÚ   rá   rï  rí   ró   r  r  r‘   r“   r5  r”   r•   rV  r[  r\  rà   r|  r}  r~  r–   rl   ÚrandomÚtimeÚpanelrñ  Úrulerò  Úsyntaxró  rç  Úprogress_renderablesÚ	itertoolsrþ  Úexamplesr©  r>   r¼  Útask1Útask2Útask3r  rU   ÚsleepÚrandintr­  r¨   rL   rL   rL   rM   Ú<module>   s‚   T
*ðNgòAúíúíúíV*2*H0		1	}    
Uó÷
ÿþýû

ûõ$õÒ