
    QfB8                       d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZ ddlmZ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(m)Z)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z< dgZ=e%Z> e?edd          Z@d$dZA ed          ZB G d d          ZC G d de/          ZD edd !          ZE G d" d#eeE                   ZFdS )%z
Progress bar implementation on top of prompt_toolkit.

::

    with ProgressBar(...) as pb:
        for item in pb(data):
            ...
    )annotationsN)	CallableGenericIterableIteratorSequenceSizedTextIOTypeVarcast)Application)get_app_session)	Conditionis_donerenderer_height_is_known)AnyFormattedTextStyleAndTextTuplesto_formatted_text)Input)KeyBindings)KeyPressEvent)ConditionalContainerFormattedTextControlHSplitLayoutVSplitWindow)	UIContent	UIControl)AnyDimensionD)
ColorDepthOutput)	BaseStyle)in_main_thread   )	Formattercreate_default_formattersProgressBarSIGWINCHcancel_callbackCallable[[], None] | Nonereturnr   c                     t                      }|                    d          d
d            } !|                    d          d
 fd	            }|S )zu
    Key bindings handled by the progress bar.
    (The main thread is not supposed to handle any key bindings.)
    zc-leventEr-   Nonec                B    | j         j                                         d S N)apprendererclear)r/   s    \/var/www/html/env/lib/python3.11/site-packages/prompt_toolkit/shortcuts/progress_bar/base.py_clearz#create_key_bindings.<locals>._clearI   s    	  """""    Nzc-cc                $    J               dS )zMKill the 'body' of the progress bar, but only if we run from the main thread.N )r/   r+   s    r7   
_interruptz'create_key_bindings.<locals>._interruptO   s%     #...Or9   )r/   r0   r-   r1   )r   add)r+   kbr8   r<   s   `   r7   create_key_bindingsr?   B   sw    
 
BVVE]]# # # ]# "		 	 	 	 	 
	
 Ir9   _Tc                  Z    e Zd ZdZ	 	 	 	 	 	 	 	 	 	 d)d*dZd+dZd,dZ	 	 	 	 d-d.d'Zd/d(ZdS )0r)   a.  
    Progress bar context manager.

    Usage ::

        with ProgressBar(...) as pb:
            for item in pb(data):
                ...

    :param title: Text to be displayed above the progress bars. This can be a
        callable or formatted text as well.
    :param formatters: List of :class:`.Formatter` instances.
    :param bottom_toolbar: Text to be displayed in the bottom toolbar. This
        can be a callable or formatted text.
    :param style: :class:`prompt_toolkit.styles.BaseStyle` instance.
    :param key_bindings: :class:`.KeyBindings` instance.
    :param cancel_callback: Callback function that's called when control-c is
        pressed by the user. This can be used for instance to start "proper"
        cancellation if the wrapped code supports it.
    :param file: The file object used for rendering, by default `sys.stderr` is used.

    :param color_depth: `prompt_toolkit` `ColorDepth` instance.
    :param output: :class:`~prompt_toolkit.output.Output` instance.
    :param input: :class:`~prompt_toolkit.input.Input` instance.
    Ntitler   
formattersSequence[Formatter] | Nonebottom_toolbarstyleBaseStyle | Nonekey_bindingsKeyBindings | Noner+   r,   fileTextIO | Nonecolor_depthColorDepth | NoneoutputOutput | NoneinputInput | Noner-   r1   c                   || _         |pt                      | _        || _        g | _        || _        || _        || _        | j        t                      rdd}|| _        || _	        |	pt                      j        | _        |
pt                      j        | _        d | _        d| _        t          j                    | _        d S )Nr-   r1   c                 f    t          j        t          j                    t          j                   d S r3   )oskillgetpidsignalSIGINTr;   r9   r7   !keyboard_interrupt_to_main_threadz?ProgressBar.__init__.<locals>.keyboard_interrupt_to_main_thread   s"    	V]33333r9   Fr-   r1   )rB   r(   rC   rE   countersrF   rH   r+   r%   rL   r   rN   rP   _thread_has_sigwinch	threadingEvent_app_started)selfrB   rC   rE   rF   rH   r+   rJ   rL   rN   rP   rY   s               r7   __init__zProgressBar.__init__v   s     
$C(A(C(C,:<
(.
 'N,<,<'4 4 4 4 $ED  '8 1 1 85o//5
04"%O--r9   c                    t          t          t           fd          dd          t           fd                    }t          t          t           fdd	          d
d          t           t
          z  t           fd          z            }d fd fd j        D             }t          dt          t          |t          | fd          t                      |g                     j         j        d j         j         j                   _        d fd}t#          j                    }t'          j        |j        |f           _         j                                          S )Nc                      j         S r3   rB   ra   s   r7   <lambda>z'ProgressBar.__enter__.<locals>.<lambda>   s	    TZ r9   r&   zclass:progressbar,title)heightrF   c                      j         d uS r3   re   rf   s   r7   rg   z'ProgressBar.__enter__.<locals>.<lambda>   s    TZt%; r9   )filterc                      j         S r3   rE   rf   s   r7   rg   z'ProgressBar.__enter__.<locals>.<lambda>   s
    D/ r9   zclass:bottom-toolbar.text)rF   zclass:bottom-toolbar)rF   rh   c                      j         d uS r3   rl   rf   s   r7   rg   z'ProgressBar.__enter__.<locals>.<lambda>   s     34 ? r9   	formatterr'   r-   r    c                0    |                                S )N)progress_bar)	get_width)rn   ra   s    r7   width_for_formatterz2ProgressBar.__enter__.<locals>.width_for_formatter   s     &&D&999r9   c           	         g | ]:}t          t          |j                  t          j        |                     ;S ))contentwidth)r   _ProgressControlr+   	functoolspartial).0fra   rr   s     r7   
<listcomp>z)ProgressBar.__enter__.<locals>.<listcomp>   s]     
 
 

 	 (q$2FGG'(;Q??  
 
 
r9   g?c                 n    t          t           j                  t           j                            S )N)	preferredmax)r!   lenr[   rf   s   r7   rg   z'ProgressBar.__enter__.<locals>.<lambda>   s/    1*-dm*<*<#dmBTBT, , , r9   )rh   g333333?)min_redraw_intervallayoutrF   rH   refresh_intervalrL   rN   rP   r1   c                     	 j                             j        j                   d S # t          $ r-} t          j                     t          |            Y d } ~ d S d } ~ ww xY w)N)pre_run)r4   runr`   setBaseException	traceback	print_excprint)era   s    r7   r   z"ProgressBar.__enter__.<locals>.run   so    T%6%:;;;;;    #%%%as   %* 
A!"AA!)targetargs)rn   r'   r-   r    rZ   )r   r   r   r   r   r   rC   r   r   r   r   rF   rH   rL   rN   rP   r4   contextvarscopy_contextr^   Threadr   r\   start)ra   title_toolbarrE   progress_controlsr   ctxrr   s   `     @r7   	__enter__zProgressBar.__enter__   s   ,$%7%7%7%788/  
 ;;;;<<
 
 
 .$////7R   -   8&'????@@A
 
 
	: 	: 	: 	: 	: 	:

 
 
 
 

 _
 
 
 '2 $%-$ $ $ $   &
   ** (;*-'
 '
 '
4	 	 	 	 	 	 $/#;#=#= 'swcVDDDr9   aobjectc                    | j                                          | j        j        r5| j        j        )| j        j                            | j        j                   | j        | j                                         d S d S r3   )	r`   waitr4   
is_runningloopcall_soon_threadsafeexitr\   join)ra   r   s     r7   __exit__zProgressBar.__exit__   sw     	    8 	>48=#<HM..tx}===<#L $#r9    FdataIterable[_T] | Nonelabelremove_when_donebooltotal
int | NoneProgressBarCounter[_T]c                b    t          | ||||          }| j                            |           |S )aL  
        Start a new counter.

        :param label: Title text or description for this progress. (This can be
            formatted text as well).
        :param remove_when_done: When `True`, hide this progress bar.
        :param total: Specify the maximum value if it can't be calculated by
            calling ``len``.
        )r   r   r   )ProgressBarCounterr[   append)ra   r   r   r   r   counters         r7   __call__zProgressBar.__call__   sA      %$e6Fe
 
 
 	W%%%r9   c                8    | j                                          d S r3   )r4   
invalidaterf   s    r7   r   zProgressBar.invalidate  s    r9   )
NNNNNNNNNN)rB   r   rC   rD   rE   r   rF   rG   rH   rI   r+   r,   rJ   rK   rL   rM   rN   rO   rP   rQ   r-   r1   )r-   r)   )r   r   r-   r1   Nr   FN)
r   r   r   r   r   r   r   r   r-   r   rZ   )	__name__
__module____qualname____doc__rb   r   r   r   r   r;   r9   r7   r)   r)   [   s         8 #'15+/"&+/59")- $"(. (. (. (. (.TK K K KZ        %)"$!&     ,     r9   c                  2    e Zd ZdZdd
ZddZddZddZdS )rv   z,
    User control for the progress bar.
    rp   r)   rn   r'   r+   r,   r-   r1   c                J    || _         || _        t          |          | _        d S r3   )rp   rn   r?   _key_bindings)ra   rp   rn   r+   s       r7   rb   z_ProgressControl.__init__  s)     )"0AAr9   ru   intrh   r   c                D   g | j         j        D ]l}	 | j                            | j         ||          }n%# t          $ r t          j                     d}Y nw xY w                    t          |                     md	fd}t          |t                    d          S )
NERRORir   r-   r   c                    |          S r3   r;   )r   itemss    r7   get_linez1_ProgressControl.create_content.<locals>.get_line/  s    8Or9   F)r   
line_countshow_cursor)r   r   r-   r   )rp   r[   rn   formatr   r   r   r   r   r   r   )ra   ru   rh   prtextr   r   s         @r7   create_contentz_ProgressControl.create_content#  s    *,#, 	2 	2B~,,T->EJJ    #%%% LL*4001111	 	 	 	 	 	 (s5zzuUUUUs   !5AAr   c                    dS )NTr;   rf   s    r7   is_focusablez_ProgressControl.is_focusable4  s    tr9   r   c                    | j         S r3   )r   rf   s    r7   get_key_bindingsz!_ProgressControl.get_key_bindings7  s    !!r9   N)rp   r)   rn   r'   r+   r,   r-   r1   )ru   r   rh   r   r-   r   r-   r   )r-   r   )r   r   r   r   rb   r   r   r   r;   r9   r7   rv   rv     sv         B B B BV V V V"   " " " " " "r9   rv   _CounterItemT)	covariantc                      e Zd ZdZ	 	 	 	 d d!dZd"dZd#dZed$d            Zej	        d%d            Zed$d            Z
e
j	        d%d            Z
ed&d            Zed'd            Zed(d            ZdS ))r   zL
    An individual counter (A progress bar can have multiple counters).
    Nr   Frp   r)   r   Iterable[_CounterItem] | Noner   r   r   r   r   r   r-   r1   c                H   t           j                                         | _        d | _        || _        || _        d| _        || _        || _        d| _	        |  |B	 t          t          t          |                    | _        d S # t          $ r d | _        Y d S w xY w|| _        d S )Nr   F)datetimenow
start_time	stop_timerp   r   items_completedr   r   _doner   r   r	   r   	TypeError)ra   rp   r   r   r   r   s         r7   rb   zProgressBarCounter.__init__C  s     #+//1137(	 
 0
=" eT!2!233


 " " "!



" DJJJs   'B BBIterator[_CounterItem]c              #     K   | j         ?	 | j         D ]}|V  |                                  d| _        d| _        d S # d| _        w xY wt	          d          )NTz No data defined to iterate over.)r   item_completeddonestoppedNotImplementedError)ra   items     r7   __iter__zProgressBarCounter.__iter__]  sz      9 
$ I * *DJJJ'')))) !	  $t####%&HIIIs	   )= 	Ac                X    | xj         dz  c_         | j                                         dS )z
        Start handling the next item.

        (Can be called manually in case we don't have a collection to loop through.)
        r&   N)r   rp   r   rf   s    r7   r   z!ProgressBarCounter.item_completedm  s3     	!$$&&&&&r9   c                    | j         S )a6  Whether a counter has been completed.

        Done counter have been stopped (see stopped) and removed depending on
        remove_when_done value.

        Contrast this with stopped. A stopped counter may be terminated before
        100% completion. A done counter has reached its 100% completion.
        )r   rf   s    r7   r   zProgressBarCounter.donev  s     zr9   valuec                z    || _         || _        |r(| j        r#| j        j                            |            d S d S d S r3   )r   r   r   rp   r[   removera   r   s     r7   r   zProgressBarCounter.done  sV    
 	4T* 	4&--d33333	4 	4 	4 	4r9   c                    | j         duS )a  Whether a counter has been stopped.

        Stopped counters no longer have increasing time_elapsed. This distinction is
        also used to prevent the Bar formatter with unknown totals from continuing to run.

        A stopped counter (but not done) can be used to signal that a given counter has
        encountered an error but allows other counters to continue
        (e.g. download X of Y failed). Given how only done counters are removed
        (see remove_when_done) this can help aggregate failures from a large number of
        successes.

        Contrast this with done. A done counter has reached its 100% completion.
        A stopped counter may be terminated before 100% completion.
        N)r   rf   s    r7   r   zProgressBarCounter.stopped  s      ~T))r9   c                t    |r.| j         s%t          j                                        | _         d S d S d | _         d S r3   )r   r   r   r   s     r7   r   zProgressBarCounter.stopped  sE     	"> 9!)!2!6!6!8!89 9 "DNNNr9   floatc                T    | j         dS | j        dz  t          | j         d          z  S )Nr   d   r&   )r   r   r~   rf   s    r7   
percentagezProgressBarCounter.percentage  s.    :1'#-DJ0B0BBBr9   datetime.timedeltac                z    | j         &t          j                                        | j        z
  S | j         | j        z
  S )zH
        Return how much time has been elapsed since the start.
        )r   r   r   r   rf   s    r7   time_elapsedzProgressBarCounter.time_elapsed  s7    
 >!$((**T_<<>DO33r9   datetime.timedelta | Nonec                    | j         | j        sdS | j        s| j        rt	          j        d          S | j        d| j        z
  z  | j        z  S )z7
        Timedelta representing the time left.
        Nr   r   )r   r   r   r   r   	timedeltar   rf   s    r7   	time_leftzProgressBarCounter.time_left  sZ    
 :T_4Y 	Q$, 	Q%a((($do(=>PPr9   r   )rp   r)   r   r   r   r   r   r   r   r   r-   r1   )r-   r   rZ   r   )r   r   r-   r1   )r-   r   )r-   r   )r-   r   )r   r   r   r   rb   r   r   propertyr   setterr   r   r   r   r;   r9   r7   r   r   >  s_         /3"$!&     4J J J J ' ' ' ' 	 	 	 X	 
[4 4 4 [4 * * * X*" ^" " " ^" C C C XC 4 4 4 X4 	Q 	Q 	Q X	Q 	Q 	Qr9   r   )r+   r,   r-   r   )Gr   
__future__r   r   r   rw   rT   rW   r^   r   typingr   r   r   r   r   r	   r
   r   r   prompt_toolkit.applicationr   "prompt_toolkit.application.currentr   prompt_toolkit.filtersr   r   r   prompt_toolkit.formatted_textr   r   r   prompt_toolkit.inputr   prompt_toolkit.key_bindingr   (prompt_toolkit.key_binding.key_processorr   prompt_toolkit.layoutr   r   r   r   r   r   prompt_toolkit.layout.controlsr   r   prompt_toolkit.layout.dimensionr    r!   prompt_toolkit.outputr"   r#   prompt_toolkit.stylesr$   prompt_toolkit.utilsr%   rC   r'   r(   __all__r0   getattr	_SIGWINCHr?   r@   r)   rv   r   r   r;   r9   r7   <module>r     sb    # " " " " "          				         
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 3 2 2 2 2 2 > > > > > > O O O O O O O O O O         
 ' & & & & & 2 2 2 2 2 2 B B B B B B                @ ? ? ? ? ? ? ? ; ; ; ; ; ; ; ; 4 4 4 4 4 4 4 4 + + + + + + / / / / / / < < < < < < < </GFJ--	   , WT]]v v v v v v v vr$" $" $" $" $"y $" $" $"N w~666CQ CQ CQ CQ CQ. CQ CQ CQ CQ CQr9   