
    /hXh                    \   d Z ddlm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 ddlmZ ddlmZ ddlmZ ddlmZ d	d
lmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlm Z  d	dl!m"Z" d	dl#m$Z$  ej%        d          Z&ej'        dk    rdZ(dZ)ndZ(dZ) G d dej*        e&                   Z+d=d>d"Z,d?d&Z-d?d'Z.d@d*Z/ G d+ d,          Z0dAdBd3Z1dCd5Z2e
j3        d6k    rddl4Z4ej5        dDd8            Z6dEd:Z7dS ddl8Z8ddl9Z9ej5        dDd;            Z6dEd<Z7dS )Fz
This module contains implementations for the termui module. To keep the
import time of Click down, some infrequently used functionality is
placed in this module and only imported as needed.
    )annotationsN)gettext)StringIO)Path)which)TracebackType   )_default_text_stdout)CYGWIN)get_best_encoding)isatty)open_stream)
strip_ansi)term_len)WIN)ClickException)echoVnt
z[?25lz[?25h
c                      e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dEdFd%ZdGd'ZdHd.ZdId0ZdJd2ZdKd3Ze	dLd5            Z
e	dLd6            Ze	dLd7            ZdMd8ZdMd9ZdMd:ZdMd;ZdMd<ZdKd=ZdNd?ZdOdPdBZdKdCZdIdDZdS )QProgressBarN# %(bar)s  FTr	      iterablecabc.Iterable[V] | Nonelength
int | None	fill_charstr
empty_charbar_templateinfo_sephiddenboolshow_etashow_percentbool | Noneshow_positem_show_func)t.Callable[[V | None], str | None] | Nonelabel
str | Nonefilet.TextIO | Nonecolorupdate_min_stepsintwidthreturnNonec                   || _         || _        || _        || _        || _        || _        |	| _        |
| _        || _        |pd| _	        |t                      }|t                      }|| _        || _        || _        d| _        || _        |dk    | _        |ddlm}  ||d          }|dk    rd }|3|t)          d          t+          j        dt/          |                    }t1          |          | _        || _        d| _        g | _        |  |  t9          j                    x| _        | _        d| _        d| _         d | _!        d| _"        d | _#        tI          | j                  | _%        d | _&        d S )N r   )length_hintziterable or length is requiredzcabc.Iterable[V]F)'r#   r%   r&   r'   r(   r*   r+   r-   r.   r0   r
   r   r2   r4   r5   _completed_intervalsr7   	autowidthoperatorr<   	TypeErrortcastrangeiterr!   posavgtimestartlast_eta	eta_knownfinished	max_widthenteredcurrent_itemr   _is_atty
_last_line)selfr   r!   r#   r%   r&   r'   r(   r*   r+   r-   r.   r0   r2   r4   r5   r7   r<   s                     E/var/www/html/venv/lib/python3.11/site-packages/click/_termui_impl.py__init__zProgressBar.__init__-   s   & #$(  ( ,+2
<'))D |zz	
 0$%!
$z>,,,,,, [2..F||~ @AAAv0%--@@H&*8nn	 "%)Y[[0
T]$#%)"&*ty))&*    ProgressBar[V]c                <    d| _         |                                  | S )NT)rN   render_progressrR   s    rS   	__enter__zProgressBar.__enter__t   s     rU   exc_typetype[BaseException] | None	exc_valueBaseException | NonetbTracebackType | Nonec                .    |                                   d S N)render_finish)rR   r[   r]   r_   s       rS   __exit__zProgressBar.__exit__y   s     	rU   cabc.Iterator[V]c                ~    | j         st          d          |                                  |                                 S )N.You need to use progress bars in a with block.)rN   RuntimeErrorrX   	generatorrY   s    rS   __iter__zProgressBar.__iter__   s>    | 	QOPPP~~rU   r   c                :    t          t          |                     S rb   )nextrE   rY   s    rS   __next__zProgressBar.__next__   s     DJJrU   c                    | j         s| j        sd S | j                            t                     | j                                         d S rb   )r(   rP   r2   write	AFTER_BARflushrY   s    rS   rc   zProgressBar.render_finish   sF    ; 	dm 	F		"""	rU   floatc                p    | j         rdS t          | j        t          | j        pd          pdz  d          S )N      ?r	   )rL   minrF   rr   r!   rY   s    rS   pctzProgressBar.pct   s<    = 	348uT[%5A66;!<cBBBrU   c                    | j         sdS t          | j                   t          t          | j                             z  S Ng        )rG   sumrr   lenrY   s    rS   time_per_iterationzProgressBar.time_per_iteration   s4    x 	348}}uS]]3333rU   c                P    | j         | j        s| j        | j         | j        z
  z  S dS rx   )r!   rL   r{   rF   rY   s    rS   etazProgressBar.eta   s-    ;"4="*dkDH.DEEsrU   c                    | j         rUt          | j                  }|dz  }|dz  }|dz  }|dz  }|dz  }|dz  }|dk    r| d|dd|dd|dS |dd|dd|dS dS )N<      r   zd 02:r;   )rK   r6   r}   )rR   rB   secondsminuteshourss        rS   
format_etazProgressBar.format_eta   s    > 	?DHA"fG"HA"fG"HAFE"HA1uuCCuCCC'CCCwCCCC>>>W>>>'>>>>rrU   c                V    t          | j                  }| j        |d| j         z  }|S )N/)r$   rF   r!   )rR   rF   s     rS   
format_poszProgressBar.format_pos   s1    $(mm;"$t{$$$C
rU   c                H    t          | j        dz            dddd          S )Nd   z 4%r	   )r6   rv   rY   s    rS   
format_pctzProgressBar.format_pct   s+    dhn%%++++ABB//rU   c                   | j         <t          | j        | j        z            }| j        |z  }|| j        | j        |z
  z  z  }n| j        r| j        | j        z  }nt          | j        | j        pdz            }| j        dk    rD| j        |t          t          j
        | j        | j        z            dz  dz   | j        z            <   d                    |          }|S )Nr	   r   g       @g      ?r;   )r!   r6   rv   r7   r#   r%   rL   listr{   mathcosrF   join)rR   
bar_lengthbarcharss       rS   
format_barzProgressBar.format_bar   s    ;"TX
233J.:-C4?dj:&=>>CC] 	!.4:-CCDJO!<==E&!++ N $(T-D"DEEKcQ*%  ''%..C
rU   c                j   | j         }g }| j        
|| j         }| j        r'|                    |                                            |r'|                    |                                            | j        r5| j        r.| j        s'|                    | 	                                           | j
        1| 
                    | j                  }||                    |           | j        | j        |                                 | j                            |          dz                                  S )N)r0   r   info)r+   r!   r-   appendr   r   r*   rK   rL   r   r.   rO   r&   r0   r   r'   r   rstrip)rR   r+   	info_bits	item_infos       rS   format_progress_linez ProgressBar.format_progress_line   s3   (	;"|';#},L= 	0T__../// 	0T__..///= 	0T^ 	0DM 	0T__..///*++D,=>>I$  +++ ((**955  &((	rU   c                   dd l }| j        rd S | j        s?| j        | j        k    r-| j        | _        t          | j        | j        | j                   d S g }| j        r| j	        }d| _	        t          |                                           }t          d|                                j        |z
            }||k     rE| j        >|                    t"                     |                    d| j        z             || _        || _	        | j	        }| j        | j        }|                    t"                     |                                 }t          |          }| j        | j        |k     r|| _        |                    |           |                    d||z
  z             d                    |          }|| j        k    r?|| _        t          || j        | j        d           | j                                         d S d S )Nr   )r2   r4   r   r;   F)r2   r4   nl)shutilr(   rP   rQ   r0   r   r2   r4   r?   r7   r   r   maxget_terminal_sizecolumnsrM   r   
BEFORE_BARr   rq   )	rR   r   buf	old_widthclutter_length	new_widthclear_widthlineline_lens	            rS   rX   zProgressBar.render_progress   s   ; 	F} 	$*,,"&*TZditzBBBBF> 		#
IDJ%d&?&?&A&ABBNAv7799ANRSSI9$$)C

:&&&

3/000!*"DJj>%.K

:((**D>>>!T^h%>%>%DN

4

3+01222wws|| 4?"""DODITZEBBBBIOO #"rU   n_stepsc                   | xj         |z  c_         | j        | j         | j        k    rd| _        t          j                    | j        z
  dk     rd S t          j                    | _        | j         r$t          j                    | j        z
  | j         z  }nt          j                    | j        z
  }| j        dd          |gz   | _        | j        d u| _        d S )NTrt   i)rF   r!   rL   rH   rJ   rI   rG   rK   )rR   r   steps      rS   	make_stepzProgressBar.make_step  s    G;"tx4;'>'> DMIKK$-'3..F	
 8 	,IKK$*,8DD9;;+D8BCC=D6)D0rU   rO   V | Nonec                    ||| _         | xj        |z  c_        | j        | j        k    r7|                     | j                   |                                  d| _        dS dS )a  Update the progress bar by advancing a specified number of
        steps, and optionally set the ``current_item`` for this new
        position.

        :param n_steps: Number of steps to advance.
        :param current_item: Optional item to set as ``current_item``
            for the updated position.

        .. versionchanged:: 8.0
            Added the ``current_item`` optional parameter.

        .. versionchanged:: 8.0
            Only render when the number of steps meets the
            ``update_min_steps`` threshold.
        Nr   )rO   r>   r5   r   rX   )rR   r   rO   s      rS   updatezProgressBar.update1  st      # ,D!!W,!!$(===NN44555  """()D%%% >=rU   c                0    d| _         d | _        d| _        d S )NFT)rK   rO   rL   rY   s    rS   finishzProgressBar.finishK  s     rU   c              #  D  K   | j         st          d          | j        s| j        E d{V  dS | j        D ]A}|| _        | j        dk    r|                                  |V  |                     d           B|                                  |                                  dS )zReturn a generator which yields the items added to the bar
        during construction, and updates the progress bar *after* the
        yielded block returns.
        rg   Nr   r	   )	rN   rh   rP   rE   rO   r>   rX   r   r   )rR   rvs     rS   ri   zProgressBar.generatorP  s       | 	QOPPP} 	#y         i 
 
$&!
 ,11((***AKKMMM  """""rU   )Nr   r   r   r   FTNFNNNNr	   r   )"r   r    r!   r"   r#   r$   r%   r$   r&   r$   r'   r$   r(   r)   r*   r)   r+   r,   r-   r)   r.   r/   r0   r1   r2   r3   r4   r,   r5   r6   r7   r6   r8   r9   )r8   rV   )r[   r\   r]   r^   r_   r`   r8   r9   )r8   re   )r8   r   )r8   r9   )r8   rr   r8   r$   )r   r6   r8   r9   rb   )r   r6   rO   r   r8   r9   )__name__
__module____qualname__rT   rZ   rd   rj   rm   rc   propertyrv   r{   r}   r   r   r   r   r   rX   r   r   r   ri    rU   rS   r   r   ,   s        "%$(DH  $! !#E+ E+ E+ E+ E+N   
                     C C C XC
 4 4 4 X4
    X
      0 0 0 0   &   6, , , ,\1 1 1 1,* * * * *4   
# # # # # #rU   r   ri   cabc.Iterable[str]r4   r,   r8   r9   c                   t                      }|t                      }t          t          j                  rt          |          st          || |          S t          j        t          j	        
                    dd          d          }|r.t          rt          | ||          rdS nt          | ||          rdS t          j	        
                    d          dv rt          || |          S t          st          j                            d          rt          | d	g|          rdS t          | d
g|          rdS ddl}|                                \  }}t          j        |           	 t          | d	g|          r	 t          j        |           dS t          || |          t          j        |           S # t          j        |           w xY w)z2Decide what method to use for paging through text.NPAGERr;   F)posixTERM)dumbemacsos2morelessr   )r
   r   r   sysstdin
_nullpagershlexsplitosenvirongetr   _tempfilepager
_pipepagerplatform
startswithtempfilemkstempcloseunlink)ri   r4   stdoutpager_cmd_partsr   fdfilenames          rS   pagerr   r  s   !##F ~#) 4F6NN 4&)U333 k"*..""="=UKKKO  	i%@@ 	?E:: 	F	z~~f!222&)U333 s|&&u-- >F8U4 4  	)fXu-- OOO##%%LBHRLLLi&511 	 		( &)U33
	(	(s   ,F: F: :G	cmd_parts	list[str]r)   c                   |sdS |d         }|dd         }t          |          }|sdS t          |                                          }|j        }ddl}t          t          j                  }	|Q|dk    rKt          j                            dd           d	                    |           }
|
sd	|	d<   d
}n
d|
v sd|
v rd
}|
                    t          |          g|z   d
|j        |	dd
          }|j        J 	 | D ]-}|st          |          }|j                            |           .n3# t           $ r Y n't"          $ r}|                                 |d}~ww xY w	 |j                                         n# t           $ r Y nw xY w	 	 |                                 n# t*          $ r Y nw xY w'nX# 	 |j                                         n# t           $ r Y nw xY w	 	 |                                 n# t*          $ r Y nw xY w'w xY wd
S )zPage through text by feeding it to another program. Invoking a
    pager through this might support colors.

    Returns `True` if the command was found, `False` otherwise and thus another
    pager should be attempted.
    Fr   r	   Nr   LESSr;   r   -RTrRreplace)shellr   enverrorstext)r   r   resolvename
subprocessdictr   r   r   r   Popenr$   PIPEr   r   ro   BrokenPipeError	Exception	terminater   waitKeyboardInterrupt)ri   r   r4   cmd
cmd_paramscmd_filepathcmd_pathcmd_namer   r   
less_flagscr   es                 rS   r   r     s     u
A,C122J::L uL!!))++H}H rz

C }V++
vr22JCHHZ4H4HJJ
 	CKEEJ#"3"3E	X*$o 	 	 	A 7' 	  	 D (!$''GMM$		 
       
 	
	GMMOOOO  	 	 	D		  %   	 +	GMMOOOO  	 	 	D		  %   	 	 	 	 	 4s   =0D. -F5 .
E8F5 :	EEEF5 "E< <
F	F	F# #
F0/F05H
7GH

GH
GH
#G87H
8
HH
HH
c                   |sdS |d         }t          |          }|sdS t          |                                          }ddl}ddl}|                                \  }}	d                    |           }
|st          |
          }
t          t          j
                  }t          |	d          d         5 }|                    |
                    |                     ddd           n# 1 swxY w Y   	 |                    t          |          |	g           n# t           $ r Y nw xY wt#          j        |           t#          j        |	           n-# t#          j        |           t#          j        |	           w xY wdS )zPage through text by invoking a program on a temporary file.

    Returns `True` if the command was found, `False` otherwise and thus another
    pager should be attempted.
    Fr   Nr;   wbT)r   r   r   r   r   r   r   r   r   r   r   r   ro   encodecallr$   OSErrorr   r   r   )ri   r   r4   r   r   r   r   r   r   r   r   encodingfs                rS   r   r     s     u
A,C::L uL!!))++HOOO##%%LB779D  $ ,,H	Xt	$	$Q	' '1	H%%&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' 'X12222    	
	( 	
	(4s<   5)C**C.1C.6$D E 
D(%E 'D((E *E>streamt.TextIOc                \    |D ](}|st          |          }|                     |           )dS )z>Simply print unformatted text.  This is the ultimate fallback.N)r   ro   )r  ri   r4   r   s       rS   r   r      sG        	$d##DT rU   c                  |    e Zd Z	 	 	 	 dddZddZddZej        dd            Zej        d d            Zd!dZdS )"EditorNT.txteditorr1   r   cabc.Mapping[str, str] | Nonerequire_saver)   	extensionr$   r8   r9   c                >    || _         || _        || _        || _        d S rb   )r  r   r
  r  )rR   r  r   r
  r  s        rS   rT   zEditor.__init__+  s%     ("rU   c                    | j         | j         S dD ]'}t          j                            |          }|r|c S (t          rdS dD ]}t          |          |c S dS )N)VISUALEDITORnotepad)zsensible-editorvimnanovi)r  r   r   r   r   r   )rR   keyr   r  s       rS   
get_editorzEditor.get_editor7  s    ;";% 	 	C$$B 			 	96 	 	FV}}( )trU   	filenamesr   c                N   dd l }|                                 }d }| j        r8t          j                                        }|                    | j                   d                    d |D                       }	 |                    | d| |d          }|	                                }|dk    r0t          t          d                              |                    d S # t          $ r7}t          t          d                              ||	                    |d }~ww xY w)
Nr   r   c              3  "   K   | ]
}d | d V  dS )"Nr   ).0r   s     rS   	<genexpr>z$Editor.edit_files.<locals>.<genexpr>O  s*      JJHHJJJJJJrU   T)argsr   r   z{editor}: Editing failed)r  z{editor}: Editing failed: {e})r  r   )r   r  r   r   r   copyr   r   r   r   r   _formatr   )	rR   r  r   r  r   exc_filenamer   	exit_coder   s	            rS   
edit_fileszEditor.edit_filesE  sH   "")-8 	%joo''GNN48$$$xxJJ	JJJJJ	  ////WD !  A IA~~$011888GG   ~  	 	 	 1229919MM 	s   :A'C# #
D$-2DD$r   bytes | bytearraybytes | Nonec                    d S rb   r   rR   r   s     rS   editzEditor.edit_  s    =@SrU   c                    d S rb   r   r&  s     rS   r'  zEditor.editd  s    47CrU   str | bytes | bytearray | Nonestr | bytes | Nonec                   dd l }|d}nt          |t          t          f          r|}nb|r|                    d          s|dz  }t
          r*|                    dd                              d          }n|                    d          }|                    d| j	                  \  }}	 t          j        |d	          5 }|                    |           d d d            n# 1 swxY w Y   t          j        |t          j                            |          t          j                            |          d
z
  f           t          j                            |          }|                     |f           | j        r:t          j                            |          |k    r	 t          j        |           d S t)          |d          5 }|                                }d d d            n# 1 swxY w Y   t          |t          t          f          r|t          j        |           S |                    d                              dd          t          j        |           S # t          j        |           w xY w)Nr   rU   r   z
z	utf-8-sigzutf-8zeditor-)prefixsuffixr      rb)r   
isinstancebytes	bytearrayendswithr   r   r   r   r  r   fdopenro   utimepathgetatimegetmtimer"  r
  r   openreaddecode)	rR   r   r   datar   r   r  	timestampr   s	            rS   r'  zEditor.editg  s   <DDui011 		,DD DMM$//  ,||D&1188EE{{7++##9T^#LLD	2t$$                HTBG,,T22BG4D4DT4J4JQ4NOPPP ((..IOOTG$$$  RW%5%5d%;%;y%H%H IdOOOOO dD!! QVVXX               $	 233  IdOOOO 99[))11&$??IdOOOOBIdOOOOsa   +I"  C"I" "C&&I" )C&*B6I" 7I" G(I" (G,,I" /G,0 I" %(I" "I8)NNTr  )
r  r1   r   r	  r
  r)   r  r$   r8   r9   r   )r  r   r8   r9   )r   r#  r8   r$  )r   r1   r8   r1   )r   r)  r8   r*  )	r   r   r   rT   r  r"  rB   overloadr'  r   rU   rS   r  r  *  s         "-1!
# 
# 
# 
# 
#      4 Z@@@ Z@ Z777 Z7- - - - - -rU   r  Furlr$   r   locater6   c                    dd l }dd}t          j        dk    rdg}|r|                    d           |r|                    d	           |                     ||                      t	          d
d          }	 |                    ||                                          |                                 S # |                                 w xY wt          r|r ||           } dd|  g}nDdg}|r|                    d           |                    d           |                    |            	 |	                    |          S # t          $ r Y dS w xY wt          r|r- ||           } dt          j                            |           g}n/dg}|r|                    d           |                    |            	 |	                    |          S # t          $ r Y dS w xY w	 |r+t          j                             ||                     pd} n ||           } |                    d| g          }|r|                                S dS # t          $ r9 |                     d          r |s|sdd l}|                    |            Y dS Y dS w xY w)Nr   r?  r$   r8   c                b    ddl m} |                     d          r || dd                    } | S )Nr   )unquotezfile://   )urllib.parserC  r   )r?  rC  s     rS   _unquote_filezopen_url.<locals>._unquote_file  sD    ((((((>>)$$ 	#'#abb'""C
rU   darwinr9  z-Wr   z	/dev/nullw)stderrexplorerz/select,rI   z/WAITr;      cygstartz-w.zxdg-open)zhttp://zhttps://r	   )r?  r$   r8   r$   )r   r   r   r   r9  r   r   r   r   r   r   r   r   r6  dirnamer   
webbrowser)	r?  r   r@  r   rF  r  nullr   rO  s	            rS   open_urlrQ    s       |xx 	KK 	KKMM#&&'''K%%	##D#66;;==JJLLLLDJJLLLL	  	-$$C 03 0 01DD9D %G$$$KKOOOKK	??4((( 	 	 	33	 
  	-$$C 4 45DD<D "D!!!KK	??4((( 	 	 	33	 	%'//--"4"455<CC-$$Cj#.// 	6688Oq   >>122 	6 	$ 	OOC   11qqsC   9(B6 6C0E 
EE<G 
GG#A$I
 
<JJchc                    | dk    rt                      | dk    rt          st                      | dk    rt          rt                      d S )N)r   r   EOFError)rR  s    rS   _translate_ch_to_excrX    sJ    	V||!!!	V||C|jj	V|||jj4rU   win32cabc.Iterator[int]c               #     K   dV  d S )Nr=   r   r   rU   rS   raw_terminalr\    s      rU   r   c                8   | r7t          j        t           j        g t          f         t          j                  }n6t          j        t           j        g t          f         t          j                  } |            }|dv r| |            z  }t          |           |S )N)    à)rB   rC   Callabler$   msvcrtgetwchegetwchrX  )r   funcr   s      rS   getcharre    s    >  	>6!*RW-v~>>DD6!*RW-v}==DTVV!!! $$&&LBR   	rU   c               #    K   t          t          j                  s$t          d          } |                                 }n t          j                                        }d } 	 t          j        |          }	 t          j        |           |V  t          j	        |t
          j
        |           t          j                                         | |                                  d S d S # t          j	        |t
          j
        |           t          j                                         | |                                  w w xY w# t
          j        $ r Y d S w xY w)Nz/dev/tty)r   r   r   r9  filenotermios	tcgetattrttysetraw	tcsetattr	TCSADRAINr   rq   r   error)r  r   old_settingss      rS   r\  r\  $  s6     
 ci   	Z  ABB!!##BA	",R00L
2!"g&7FFF
  """=GGIIIII != !"g&7FFF
  """=GGIIII !} 	 	 	DD	s,   !E  6C& AE  &AD==E   EEc                h   t                      5 }t          j        |d                              t	          t
          j                  d          }| r8t          t
          j                  rt
          j        	                    |           t          |           |cd d d            S # 1 swxY w Y   d S )N    r   )r\  r   r:  r;  r   r   r   r   r   ro   rX  )r   r   rR  s      rS   re  re  ?  s    ^^ 	rR''(9#)(D(DiPPB %sz** %
  $$$ $$$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB''B+.B+rb   )ri   r   r4   r,   r8   r9   )ri   r   r   r   r4   r,   r8   r)   )r  r  ri   r   r4   r,   r8   r9   )FF)r?  r$   r   r)   r@  r)   r8   r6   )rR  r$   r8   r9   )r8   rZ  )r   r)   r8   r$   ):__doc__
__future__r   collections.abcabccabc
contextlibr   r   r   r   rH   typingrB   r   r  ior   pathlibr   r   r   typesr   _compatr
   r   r   r   r   r   r   r   
exceptionsr   utilsr   TypeVarr   r   r   rp   Genericr   r   r   r   r   r  rQ  rX  r   ra  contextmanagerr\  re  rh  rj  r   rU   rS   <module>r     s^    # " " " " "            				  



                                          ) ) ) ) ) )       & & & & & &                                     & & & & & &      AIcNN7d??JIIJIC# C# C# C# C#!)A, C# C# C#L
' ' ' ' 'TW W W Wt' ' ' 'T   j j j j j j j jZD D D D DN
 
 
 
 <7MMM   , , , , , ,^ NNNJJJ   4     rU   