
    l ih                    P   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"  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+          Z.d@dAd2Z/dBd4Z0e
j1        d5k    rddl2Z2ej3        dCd7            Z4dDd9Z5dS ddl6Z6ddl7Z7ej3        dCd:            Z4dDd;Z5dS )Ez
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)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-   r/   r	   r   r1   r3   r4   _completed_intervalsr6   	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-   r/   r1   r3   r4   r6   r;   s                     I/var/www/findabus/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)rM   render_progressrQ   s    rR   	__enter__zProgressBar.__enter__s   s     rT   exc_typetype[BaseException] | None	exc_valueBaseException | NonetbTracebackType | Nonec                .    |                                   d S N)render_finish)rQ   rZ   r\   r^   s       rR   __exit__zProgressBar.__exit__x   s     	rT   cabc.Iterator[V]c                ~    | j         st          d          |                                  |                                 S )N.You need to use progress bars in a with block.)rM   RuntimeErrorrW   	generatorrX   s    rR   __iter__zProgressBar.__iter__   s>    | 	QOPPP~~rT   r   c                :    t          t          |                     S ra   )nextrD   rX   s    rR   __next__zProgressBar.__next__   s     DJJrT   c                    | j         s| j        sd S | j                            t                     | j                                         d S ra   )r'   rO   r1   write	AFTER_BARflushrX   s    rR   rb   zProgressBar.render_finish   sF    ; 	dm 	F		"""	rT   floatc                p    | j         rdS t          | j        t          | j        pd          pdz  d          S )N      ?r   )rK   minrE   rq   r    rX   s    rR   pctzProgressBar.pct   s<    = 	348uT[%5A66;!<cBBBrT   c                    | j         sdS t          | j                   t          t          | j                             z  S Ng        )rF   sumrq   lenrX   s    rR   time_per_iterationzProgressBar.time_per_iteration   s4    x 	348}}uS]]3333rT   c                P    | j         | j        s| j        | j         | j        z
  z  S dS rw   )r    rK   rz   rE   rX   s    rR   etazProgressBar.eta   s-    ;"4="*dkDH.DEEsrT   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:   )rJ   r5   r|   )rQ   rA   secondsminuteshourss        rR   
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>>>'>>>>rrT   c                V    t          | j                  }| j        |d| j         z  }|S )N/)r#   rE   r    )rQ   rE   s     rR   
format_poszProgressBar.format_pos   s1    $(mm;"$t{$$$C
rT   c                H    t          | j        dz            dddd          S )Nd   z 4%r   )r5   ru   rX   s    rR   
format_pctzProgressBar.format_pct   s+    dhn%%++++ABB//rT   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    r5   ru   r6   r"   r$   rK   listrz   mathcosrE   join)rQ   
bar_lengthbarcharss       rR   
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
rT   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)r/   r   info)r*   r    r,   appendr   r   r)   rJ   rK   r   r-   rN   r%   r/   r   r&   r   rstrip)rQ   r*   	info_bits	item_infos       rR   format_progress_linez ProgressBar.format_progress_line   s3   (	;"|';#},L= 	0T__../// 	0T__..///= 	0T^ 	0DM 	0T__..///*++D,=>>I$  +++ ((**955  &((	rT   c                   | j         rd S | j        s?| j        | j        k    r-| j        | _        t	          | j        | j        | j                   d S g }| j        rdd l}| 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 )N)r1   r3   r   r   r:   F)r1   r3   nl)r'   rO   rP   r/   r   r1   r3   r>   shutilr6   r   r   maxget_terminal_sizecolumnsrL   r   
BEFORE_BARr   rp   )	rQ   bufr   	old_widthclutter_length	new_widthclear_widthlineline_lens	            rR   rW   zProgressBar.render_progress   s   ; 	F} 	$*,,"&*TZditzBBBBF> 	#MMM
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 #"rT   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 )NTrs   i)rE   r    rK   rG   rI   rH   rF   rJ   )rQ   r   steps      rR   	make_stepzProgressBar.make_step  s    G;"tx4;'>'> DMIKK$-'3..F	
 8 	,IKK$*,8DD9;;+D8BCC=D6)D0rT   rN   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   )rN   r=   r4   r   rW   )rQ   r   rN   s      rR   updatezProgressBar.update0  st      # ,D!!W,!!$(===NN44555  """()D%%% >=rT   c                0    d| _         d | _        d| _        d S )NFT)rJ   rN   rK   rX   s    rR   finishzProgressBar.finishJ  s     rT   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.
        rf   Nr   r   )	rM   rg   rO   rD   rN   r=   rW   r   r   )rQ   rvs     rR   rh   zProgressBar.generatorO  s       | 	QOPPP} 	#y         i 
 
$&!
 ,11((***AKKMMM  """""rT   )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.   r/   r0   r1   r2   r3   r+   r4   r5   r6   r5   r7   r8   )r7   rU   )rZ   r[   r\   r]   r^   r_   r7   r8   )r7   rd   )r7   r   )r7   r8   )r7   rq   r7   r#   )r   r5   r7   r8   ra   )r   r5   rN   r   r7   r8   )__name__
__module____qualname__rS   rY   rc   ri   rl   rb   propertyru   rz   r|   r   r   r   r   r   rW   r   r   r   rh    rT   rR   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   
# # # # # #rT   r   rh   cabc.Iterable[str]r3   r+   r7   r8   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)rh   r3   stdoutpager_cmd_partsr   fdfilenames          rR   pagerr   q  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                2   |sdS ddl }|d         }|dd         }|                    |          }|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   Nr   r   LESSr:   r   -RTrRreplace)shellr   enverrorstext)r   whichr   resolvename
subprocessdictr   r   r   r   Popenr#   PIPEr   r   rn   BrokenPipeError	Exception	terminater   waitKeyboardInterrupt)rh   r   r3   r   cmd
cmd_paramscmd_filepathcmd_pathcmd_namer   r   
less_flagscr   es                  rR   r   r     s     uMMM
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   0D8 7F? 8
E(F? 	E(E##E((F? ,F 
FFF- -
F:9F:?HGH
G(%H'G((H-HH
HHHHc                   |sdS ddl }|d         }|                    |          }|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   r   rn   encodecallr#   OSErrorr   r   r   )rh   r   r3   r   r   r   r   r   r   r   r   r   encodingfs                 rR   r   r     s     uMMM
A,C<<$$L uL!!))++HOOO##%%LB779D  $ ,,H	Xt	$	$Q	' '1	H%%&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' 'X12222    	
	( 	
	(4s<   ?)C44C8;C8 $D% $E %
D2/E 1D22E *Fstreamt.TextIOc                \    |D ](}|st          |          }|                     |           )dS )z>Simply print unformatted text.  This is the ultimate fallback.N)r   rn   )r  rh   r3   r   s       rR   r   r   %  sG        	$d##DT rT   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editorr0   r   cabc.Mapping[str, str] | Nonerequire_saver(   	extensionr#   r7   r8   c                >    || _         || _        || _        || _        d S ra   )r  r   r
  r  )rQ   r  r   r
  r  s        rR   rS   zEditor.__init__0  s%     ("rT   c                    | j         | j         S dD ]'}t          j                            |          }|r|c S (t          rdS ddlm} dD ]} ||          |c S dS )N)VISUALEDITORnotepadr   )r   )zsensible-editorvimnanovi)r  r   r   r   r   r   r   )rQ   keyr   r   r  s        rR   
get_editorzEditor.get_editor<  s    ;";% 	 	C$$B 			 	9      6 	 	FuV}}( )trT   	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     rR   	<genexpr>z$Editor.edit_files.<locals>.<genexpr>W  s*      JJHHJJJJJJrT   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   )	rQ   r  r   r  r   exc_filenamer   	exit_coder   s	            rR   
edit_fileszEditor.edit_filesM  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 ra   r   rQ   r   s     rR   editzEditor.editg  s    =@SrT   c                    d S ra   r   r&  s     rR   r'  zEditor.editl  s    47CrT   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   rT   r   z
z	utf-8-sigzutf-8zeditor-)prefixsuffixr      rb)r   
isinstancebytes	bytearrayendswithr   r   r   r   r  r   fdopenrn   utimepathgetatimegetmtimer"  r
  r   openreaddecode)	rQ   r   r   datar   r   r  	timestampr   s	            rR   r'  zEditor.edito  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  r0   r   r	  r
  r(   r  r#   r7   r8   r   )r  r   r7   r8   )r   r#  r7   r$  )r   r0   r7   r0   )r   r)  r7   r*  )	r   r   r   rS   r  r"  rA   overloadr'  r   rT   rR   r  r  /  s         "-1!
# 
# 
# 
# 
#   "   4 Z@@@ Z@ Z777 Z7- - - - - -rT   r  Furlr#   r   locater5   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#   r7   c                b    ddl m} |                     d          r || dd                    } | S )Nr   )unquotezfile://   )urllib.parserC  r   )r?  rC  s     rR   _unquote_filezopen_url.<locals>._unquote_file  sD    ((((((>>)$$ 	#'#abb'""C
rT   darwinr9  z-Wr   z	/dev/nullw)stderrexplorerz/select,rH   z/WAITr:      cygstartz-w.zxdg-open)zhttp://zhttps://r   )r?  r#   r7   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	            rR   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    rR   _translate_ch_to_excrX    sJ    	V||!!!	V||C|jj	V|||jj4rT   win32cabc.Iterator[int]c               #     K   dV  d S )Nr<   r   r   rT   rR   raw_terminalr\    s      rT   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)    à)rA   rB   Callabler#   msvcrtgetwchegetwchrX  )r   funcr   s      rR   getcharre    s    >  	>6!*RW-v~>>DD6!*RW-v}==DTVV!!! $$&&LBR   	rT   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   rp   r   error)r  r   old_settingss      rR   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   rn   rX  )r   r   rR  s      rR   re  re  G  s    ^^ 	rR''(9#)(D(DiPPB %sz** %
  $$$ $$$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB''B+.B+ra   )rh   r   r3   r+   r7   r8   )rh   r   r   r   r3   r+   r7   r(   )r  r  rh   r   r3   r+   r7   r8   )FF)r?  r#   r   r(   r@  r(   r7   r5   )rR  r#   r7   r8   )r7   rZ  )r   r(   r7   r#   )8__doc__
__future__r   collections.abcabccabc
contextlibr   r   r   r   rG   typingrA   r   r  ior   pathlibr   typesr   _compatr	   r
   r   r   r   r   r   r   
exceptionsr   utilsr   TypeVarr   r   r   ro   Genericr   r   r   r   r   r  rQ  rX  r   ra  contextmanagerr\  re  rh  rj  r   rT   rR   <module>r     sL    # " " " " "            				  



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