
    +h`              	          d 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jD                  e         Z#d0dejH                  e%   dejL                  e'   ddfdZ(dejH                  e%   de%dejL                  e'   de'fdZ)dejH                  e%   de%dejL                  e'   de'fd Z*d!ejV                  dejH                  e%   dejL                  e'   ddfd"Z, G d# d$      Z-d1d%e%d&e'd'e'de.fd(Z/d)e%dejL                  e0   fd*Z1er/ddl2Z2ejf                  dejh                  e.   fd+       Z5d,e'de%fd-Z6yddl7Z7ddl8Z8ejf                  dejh                  e.   fd.       Z5d,e'de%fd/Z6y)2z
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.
    N)gettext)StringIO)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	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dej                  ej
                  e      dej                  e   dedededede	d	ej                  e	   d
e	dej                  ej                  ej                  e   gej                  e   f      dej                  e   dej                  ej                     dej                  e	   dededdf dZd+dZdej                  ej                  e      dej                  e   dej                  e   ddfdZdej$                  e   fdZdefdZd,dZedefd       Zedefd       Zedefd       ZdefdZdefdZdefd Zdefd!Zdefd"Zd,d#Z d$eddfd%Z!d-d$ed&ej                  e   ddfd'Z"d,d(Z#dej$                  e   fd)Z$y).ProgressBarNiterablelength	fill_char
empty_charbar_templateinfo_sepshow_etashow_percentshow_positem_show_funclabelfilecolorupdate_min_stepswidthreturnc                    || _         || _        || _        || _        || _        || _        |	| _        |
| _        |xs d| _        |t               }|
t               }|| _        || _        || _        d| _        || _        |dk(  | _        |ddlm}  ||d      }|dk(  rd }|A|t'        d      t)        j*                  t(        j,                  t.           t1        |            }t3        |      | _        || _        d| _        g | _        |  |  t;        j:                         x| _        | _        d| _         d| _!        d | _"        d| _#        d | _$        tK        | j                         | _&        d | _'        y )N r   )length_hintziterable or length is requiredF)(r   r   r   r   r   r   r    r!   r"   r   r   r#   r$   r%   _completed_intervalsr&   	autowidthoperatorr*   	TypeErrortcastIterabler   rangeiterr   posavgtimestartlast_eta	eta_knownfinished	max_widthenteredcurrent_itemr   	is_hidden
_last_line)selfr   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r*   s                    E/var/www/html/venv/lib/python3.12/site-packages/click/_termui_impl.py__init__zProgressBar.__init__(   s`   $ #$(  ( ,+2
<')D |z	
 0$%!
$z>, 2.F|~ @AAvvajjmU6];H#'>	"$%)YY[0
T]$#*."+/#)$))#44+/    c                 4    d| _         | j                          | S )NT)r=   render_progressrA   s    rB   	__enter__zProgressBar.__enter__m   s    rD   exc_type	exc_valuetbc                 $    | j                          y N)render_finish)rA   rI   rJ   rK   s       rB   __exit__zProgressBar.__exit__r   s     	rD   c                 p    | j                   st        d      | j                          | j                         S )N.You need to use progress bars in a with block.)r=   RuntimeErrorrF   	generatorrG   s    rB   __iter__zProgressBar.__iter__z   s.    ||OPP~~rD   c                 *    t        t        |             S rM   )nextr4   rG   s    rB   __next__zProgressBar.__next__   s     DJrD   c                     | j                   ry | j                  j                  t               | j                  j	                          y rM   )r?   r#   write	AFTER_BARflushrG   s    rB   rN   zProgressBar.render_finish   s*    >>			"		rD   c                     | j                   ryt        | j                  t        | j                  xs d      xs dz  d      S )N      ?r   )r;   minr5   floatr   rG   s    rB   pctzProgressBar.pct   s5    ==488uT[[%5A6;!<cBBrD   c                     | j                   syt        | j                         t        t        | j                               z  S Ng        )r6   sumr_   lenrG   s    rB   time_per_iterationzProgressBar.time_per_iteration   s,    xx488}uS]333rD   c                     | j                   2| j                  s&| j                  | j                   | j                  z
  z  S yrb   )r   r;   re   r5   rG   s    rB   etazProgressBar.eta   s3    ;;"4==**dkkDHH.DEErD   c                     | j                   rUt        | j                        }|dz  }|dz  }|dz  }|dz  }|dz  }|dz  }|dkD  r| d|dd|dd|dS |dd|dd|dS y)N<      r   zd 02:r)   )r:   intrg   )rA   r0   secondsminuteshourss        rB   
format_etazProgressBar.format_eta   s    >>DHHA"fG"HA"fG"HAFE"HA1uBuRj'"QwrlCC1WRL'">>rD   c                 l    t        | j                        }| j                  |d| j                   z  }|S )N/)strr5   r   )rA   r5   s     rB   
format_poszProgressBar.format_pos   s3    $((m;;"Qt{{m$$C
rD   c                 @    t        | j                  dz        dddd  S )Nd   z 4%r   )rm   r`   rG   s    rB   
format_pctzProgressBar.format_pct   s&    dhhn%b)+AB//rD   c                 F   | j                   Rt        | j                  | j                  z        }| j                  |z  }|| j
                  | j                  |z
  z  z  }|S | j                  r| j                  | j                  z  }|S t        | j
                  | j                  xs dz        }| j                  dk7  rU| j                  |t        t        j                  | j                  | j                  z        dz  dz   | j                  z        <   dj                  |      }|S )Nr   r   g       @g      ?r)   )r   rm   r`   r&   r   r   r;   listre   mathcosr5   join)rA   
bar_lengthbarcharss       rB   
format_barzProgressBar.format_bar   s   ;;"TXX

23J..:-C4??djj:&=>>C 
 ]]..4::-C 
 DJJO!<=E&&!+ NN $((T-D-D"DEKcQ**% ''%.C
rD   c                    | j                   }g }| j                  || j                   }| j                  r|j                  | j	                                |r|j                  | j                                | j                  r7| j                  r+| j                  s|j                  | j                                | j                  .| j                  | j                        }||j                  |       | j                  | j                  | j                         | j                  j!                  |      dz  j#                         S )N)r"   r   info)r   r   r    appendru   ry   r   r:   r;   rq   r!   r>   r   r"   r   r   r~   rstrip)rA   r   	info_bits	item_infos       rB   format_progress_linez ProgressBar.format_progress_line   s   ((	;;"|';#}},L==T__./T__./==T^^DMMT__./*++D,=,=>I$  + (**95 &(	rD   c                 &   dd l }| j                  rW| j                  | j                  k7  r=| j                  | _        t	        | j                  | j
                  | j                         y g }| j                  r| j                  }d| _        t        | j                               }t        d|j                         j                  |z
        }||k  r:|j                  t               |j                  d| j                   z         || _        || _        | j                  }| j                   | j                   }|j                  t               | j                         }t        |      }| j                   | j                   |k  r|| _        |j                  |       |j                  d||z
  z         dj#                  |      }|| j                  k7  rE|| _        t	        || j
                  | j                  d       | j
                  j%                          y y )Nr   )r#   r$    r)   F)r#   r$   nl)shutilr?   r@   r"   r   r#   r$   r-   r&   r   r   maxget_terminal_sizecolumnsr   
BEFORE_BARr<   r~   r[   )	rA   r   buf	old_widthclutter_length	new_widthclear_widthlineline_lens	            rB   rF   zProgressBar.render_progress   s   >> $**,"&**TZZdiitzzB>>

IDJ%d&?&?&ABNAv779AANRSI9$

:&

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

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

4

3+012wws| 4??""DODIITZZEBIIOO #rD   n_stepsc                    | xj                   |z  c_         | j                   | j                   | j                  k\  rd| _        t        j                         | j                  z
  dk  ry t        j                         | _        | j                   r/t        j                         | j
                  z
  | j                   z  }n!t        j                         | j
                  z
  }| j                  dd  |gz   | _        | j                  d u| _        y )NTr]   i)r5   r   r;   r7   r9   r8   r6   r:   )rA   r   steps      rB   	make_stepzProgressBar.make_step  s    G;;"txx4;;'> DMIIK$--'3.		
 88IIK$**,8D99;+D88BC=D6)D0rD   r>   c                     ||| _         | xj                  |z  c_        | j                  | j                  k\  r3| j                  | j                         | j	                          d| _        yy)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   )r>   r,   r%   r   rF   )rA   r   r>   s      rB   updatezProgressBar.update)  sb      # ,D!!W,!$$(=(==NN4445  "()D% >rD   c                 .    d| _         d | _        d| _        y )NFT)r:   r>   r;   rG   s    rB   finishzProgressBar.finishC  s     rD   c              #   X  K   | j                   st        d      | j                  r| j                  E d{    y| j                  D ]=  }|| _        | j
                  dk(  r| j                          | | j                  d       ? | j                          | j                          y7 rw)zReturn a generator which yields the items added to the bar
        during construction, and updates the progress bar *after* the
        yielded block returns.
        rQ   Nr   r   )	r=   rR   r?   r4   r>   r,   rF   r   r   )rA   rvs     rB   rS   zProgressBar.generatorH  s      ||OPP>>yy  ii 
$&!
 ,,1((*A
 KKM  " !s   3B*B(A3B*)N#r   z%(bar)sz  TNFNNNNr      )r'   zProgressBar[V])r'   NrM   )%__name__
__module____qualname__r0   Optionalr2   r   rm   rt   boolCallableTextIOrC   rH   TypeBaseExceptionr   rO   IteratorrT   rW   rN   propertyr_   r`   re   rg   rq   ru   ry   r   r   rF   r   r   r   rS    rD   rB   r   r   '   s    #'%)-SW!%%)"& !!C0**QZZ]+C0 

3C0 	C0
 C0 C0 C0 C0 jj&C0 C0 

1::qzz!}oqzz#.N#OPC0 zz#C0 jj"C0 zz$C0 C0  !C0" 
#C0J
**QVVM23 ::m, JJ}%	
 
 !**Q-   !   CU C C
 4E 4 4
 U  
C C 0C 0C &c 6+Z1 1 1,*c *A *$ *4
#1::a= #rD   r   rS   r$   r'   c                 4   t               }|
t               }t        t        j                        rt        |      st        || |      S t        j                  j                  dd      xs dj                         }|r"t        rt        | ||      ryt        | ||      ryt        j                  j                  d      dv rt        || |      S t        st        j                  j                  d      rt        | d|      ryt        | d|      ryd	dl}|j!                         \  }}t        j"                  |       	 t        | d|      r	 t        j$                  |       yt        || |      t        j$                  |       S # t        j$                  |       w xY w)
z2Decide what method to use for paging through text.NPAGERr)   TERM)dumbemacsos2morelessr   )r   r   r   sysstdin
_nullpagerosenvirongetstripr   _tempfilepager
_pipepagerplatform
startswithtempfilemkstempcloseunlink)rS   r$   stdout	pager_cmdr   fdfilenames          rB   pagerr   j  sC   !#F ~#))F6N&)U33.4";;=IiE:	9e4	zz~~f!22&)U33s||&&u->654 	)VU+##%LBHHRLi/ 			( &)U3
		(		(s   :F  F   Fcmdc                    t        |      }|yddl}t        t        j                        }|j                  dd      d   j                         }|R|d   dk(  rJt        j                  j                  dd	       d
j                  |dd        }|sd|d<   d}n
d|v sd|v rd}|j                  |gd|j                  |dd      }|j                  J 	 | D ]*  }	|st        |	      }	|j                  j                  |	       , 	 |j                  j                          	 	 |j#                          	 y# t        t         f$ r Y %w xY w# t         $ r Y nw xY w8)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.
    NFr   rs   r   r+   r   LESSr)   r   -RTrRreplace)shellr   enverrorstext)r   
subprocessdictr   r   rsplitsplitr   r~   PopenPIPEr   r   rY   r   OSErrorKeyboardInterruptwait)
rS   r   r$   cmd_absoluter   r   
cmd_detail
less_flagscr   s
             rB   r   r     sv    :L
rzz
C C#B'--/J}A&0

vr23CHHZ^4L3MN
CKEJ#"3E	oo 	 	A 77	 	 D!$'GGMM$		  	
 	FFH + &'   ! 		 s$   /D2  E 2EE	EEc                 D   t        |      }|yddl}ddl}|j                         \  }}dj	                  |       }|st        |      }t        t        j                        }	t        |d      d   5 }
|
j                  |j                  |	             ddd       	 |j                  ||g       t        j                  |       t        j                   |       y# 1 sw Y   HxY w# t        $ r Y Bw xY w# t        j                  |       t        j                   |       w xY w)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.
    NFr   r)   wbT)r   r   r   r   r~   r   r
   r   r   r   rY   encodecallr   r   r   r   )rS   r   r$   r   r   r   r   r   r   encodingfs              rB   r   r     s     :L##%LB779D$ ,H	Xt	$Q	' '1	H%&'x01
 	
		(' '   	
		(s0   0!CC$ C!$	C0-C3 /C00C3 3,Dstreamc                 N    |D ]   }|st        |      }| j                  |       " y)z>Simply print unformatted text.  This is the ultimate fallback.N)r   rY   )r   rS   r$   r   s       rB   r   r     s,      d#DTrD   c                      e Zd Z	 	 	 	 ddej                  e   dej                  ej                  eef      dededdf
dZdefdZ	d	eddfd
Z
dej                  ej                     dej                  ej                     fdZy)EditorNeditorr   require_save	extensionr'   c                 <    || _         || _        || _        || _        y rM   )r   r   r   r   )rA   r   r   r   r   s        rB   rC   zEditor.__init__  s!     ("rD   c                     | j                   | j                   S dD ]'  }t        j                  j                  |      }|s%|c S  t        rydD ]  }t        |      |c S  y)N)VISUALEDITORnotepad)zsensible-editorvimnanovi)r   r   r   r   r   r   )rA   keyr   r   s       rB   
get_editorzEditor.get_editor  sj    ;;";;% 	C$B		 6 	FV}(	 rD   r   c                    dd l }| j                         }d }| j                  r9t        j                  j                         }|j                  | j                         	 |j                  | d| d|d      }|j                         }|dk7  r$t        t        d      j                  |            y # t        $ r+}t        t        d      j                  ||	            |d }~ww xY w)
Nr   z ""T)r   r   z{editor}: Editing failed)r   z{editor}: Editing failed: {e})r   e)r   r   r   r   r   copyr   r   r   r   _formatr   )rA   r   r   r   r   r   	exit_coder   s           rB   	edit_filezEditor.edit_file  s    "0488jjoo'GNN488$
	  F82hZq!9wd SAIA~$01888G    	 129919M	s   AB1 1	C%:&C  C%r   c                    dd l }|sd}njt        |t        t        f      r|}nQ|r|j	                  d      s|dz  }t
        r"|j                  dd      j                  d      }n|j                  d      }|j                  d| j                        \  }}	 t        j                  |d	      5 }|j                  |       d d d        t        j                  |t        j                  j                  |      t        j                  j!                  |      d
z
  f       t        j                  j!                  |      }| j#                  |       | j$                  r9t        j                  j!                  |      |k(  r	 t        j&                  |       y t)        |d      5 }|j+                         }d d d        t        |t        t        f      rt        j&                  |       S j-                  d      j                  dd      t        j&                  |       S # 1 sw Y   \xY w# 1 sw Y   yxY w# t        j&                  |       w xY w)Nr   rD   r   z
z	utf-8-sigzutf-8zeditor-)prefixsuffixr      rb)r   
isinstancebytes	bytearrayendswithr   r   r   r   r   r   fdopenrY   utimepathgetatimegetmtimer  r   r   openreaddecode)	rA   r   r   datar   namer   	timestampr   s	            rB   editzEditor.edit3  s   Dui01DDMM$/||D&188E{{7+##9T^^#LD	2t$  HHTBGG,,T2BGG4D4DT4JQ4NOP ((.INN4   RWW%5%5d%;y%H IIdO dD! QVVX $	 23 IIdO 99[)11&$?IIdO3 "  IIdOsI   H0 +H=B;H0 H0 H$,H0 ! H0 H!H0 $H-)H0 0I)NNTz.txt)r   r   r   r0   r   rt   Mappingr   rC   r   r  AnyStrr  r   rD   rB   r   r     s     #'/3!
#

3
# ZZ		#s(+,
# 	
#
 
# 

#C # $ ,-AHH- -!**QXX2F -rD   r   urlr   locatec                 x   dd l }dt        dt        fd}t        j                  dk(  r~dg}|r|j	                  d       |r|j	                  d       |j	                   ||              t        d	d
      }	 |j                  ||      j                         |j                          S t        r\|r ||       } dd|  g}n8dg}|r|j	                  d       |j	                  d       |j	                  |        	 |j                  |      S t        re|r* ||       } dt        j                  j                  |       g}n'dg}|r|j	                  d       |j	                  |        	 |j                  |      S 	 |r*t        j                  j                   ||             xs d} n ||       } |j                  d| g      }|r|j                         S y# |j                          w xY w# t        $ r Y yw xY w# t        $ r Y yw xY w# t        $ r/ | j!                  d      r|s|sdd l}|j                  |        Y yY yw xY w)Nr   r  r'   c                 J    ddl m} | j                  d      r || dd        } | S )Nr   )unquotezfile://   )urllib.parser  r   )r  r  s     rB   _unquote_filezopen_url.<locals>._unquote_filef  s&    (>>)$#ab'"C
rD   darwinr  z-Wr   z	/dev/nullw)stderrexplorerz/select,r8   z/WAITr)      cygstartz-w.zxdg-open)zhttp://zhttps://r   )r   rt   r   r   r   r  r   r   r   r   r   r   r	   r   r  dirnamer   
webbrowser)	r  r   r  r   r"  argsnullr   r+  s	            rB   open_urlr.  c  s   3 3  ||xxKKKKM#&'K%	##D#6;;=JJL	$C(3% 01D9DG$KKOKK	??4(( 
$C 45D<DD!KK	??4((
''//-"45<C$Cj#./668OO JJL  		  		  >>126$OOC sC   5 G 7G# "G2 4AH G #	G/.G/2	G>=G>3H98H9chc                 v    | dk(  r
t               | dk(  rt        s
t               | dk(  rt        r
t               y )N)r   r   EOFError)r/  s    rB   _translate_ch_to_excr5    s7    	V|!!	V|Cj	V|jrD   c               #      K   d y w)Nr+   r   r   rD   rB   raw_terminalr7    s     s   r   c                     | rt         j                  }nt         j                  } |       }|dv r
| |       z  }t        |       |S )N)    à)msvcrtgetwchegetwchr5  )r   funcr   s      rB   getcharr?    sD    @ >>D==DV!! $&LBR 	rD   c               #     K   t        t        j                        st        d      } | j	                         }n t        j                  j	                         }d } 	 t        j                  |      }	 t        j                  |       | t        j                  |t
        j                  |       t        j                  j                          | | j                          y y # t        j                  |t
        j                  |       t        j                  j                          | | j                          w w xY w# t
        j                  $ r Y y w xY ww)Nz/dev/tty)r   r   r   r  filenotermios	tcgetattrttysetraw	tcsetattr	TCSADRAINr   r[   r   error)r   r   old_settingss      rB   r7  r7    s     
 cii Z AB!!#BA	",,R0L

2!!"g&7&7F

  "=GGI ! !!"g&7&7F

  "=GGI !}} 		sD   AED: /C AD: EAD77D: :EEEEc                 J   t               5 }t        j                  |d      j                  t	        t
        j                        d      }| r8t        t
        j                        rt
        j                  j                  |       t        |       |cd d d        S # 1 sw Y   y xY w)N    r   )r7  r   r  r  r
   r   r   r   r   rY   r5  )r   r   r/  s      rB   r?  r?    so    ^ 	rR''(9#))(DiPBszz*

  $ $	 	 	s   BBB"rM   )FF)9__doc__
contextlibr|   r   r   r7   typingr0   r   r   ior   r   r   typesr   _compatr   r	   r
   r   r   r   r   r   
exceptionsr   utilsr   TypeVarr   r  r   rZ   Genericr   r2   rt   r   r   r   r   r   r   r   r   rm   r.  r   r5  r;  contextmanagerr   r7  r?  rB  rD  r   rD   rB   <module>rW     s7     	 
        )  &       & AIIcN77d?JIJI@#!))A, @#F
$QZZ_ $QZZ-= $ $N>!**S/ > >AJJt<L >QU >B#zz##	# ::d# 
	#LHH!"C9:D9I	^ ^BD# DT D4 DC DN
S 
QZZ%> 
 !**S/  -d -s -` !**S/  4d s rD   