
    e!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jJ                  d      Z&ejN                  dk(  rdZ(dZ)ndZ(dZ) G d dejT                  e&         Z+d)d*dZ,	 	 	 	 	 	 	 	 d+dZ-	 	 	 	 	 	 	 	 d+dZ.	 	 	 	 	 	 	 	 d,dZ/ G d  d!      Z0d-d.d"Z1d/d#Z2e
jf                  d$k(  rddl4Z4ejj                  d0d%       Z6d1d&Z7yddl8Z8ddl9Z9ejj                  d0d'       Z6d1d(Z7y)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.
    )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                  6   e Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 ddZddZddZddZe	dd       Z
e	dd	       Ze	dd
       ZddZddZddZddZddZddZddZdd dZddZddZy)!ProgressBarNc                   || _         || _        || _        || _        || _        || _        |	| _        |
| _        || _        |xs d| _	        |t               }|
t               }|| _        || _        || _        d| _        || _        |dk(  | _        |ddlm}  ||d      }|dk(  rd }|,|t)        d      t+        j,                  dt/        |            }t1        |      | _        || _        d| _        g | _        |  |  t9        j8                         x| _        | _        d| _        d| _         d | _!        d| _"        d | _#        tI        | j                        | _%        d | _&        y )N r   )length_hintziterable or length is requiredzcabc.Iterable[V]F)'	fill_char
empty_charbar_templateinfo_sephiddenshow_etashow_percentshow_positem_show_funclabelr
   r   filecolorupdate_min_steps_completed_intervalswidth	autowidthoperatorr   	TypeErrortcastrangeiterlengthposavgtimestartlast_eta	eta_knownfinished	max_widthenteredcurrent_itemr   _is_atty
_last_line)selfiterabler4   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r,   r   s                     Z/var/www/html/diagnosisapp-backend/venv/lib/python3.12/site-packages/click/_termui_impl.py__init__zProgressBar.__init__-   s]   & #$(  ( ,+2
<')D |z	
 0$%!
$z>, 2.F|~ @AAvv0%-@H&*8n	 "%)YY[0
T]$#%)"&*tyy)&*    c                4    d| _         | j                          | S )NT)r=   render_progressrA   s    rC   	__enter__zProgressBar.__enter__t   s    rE   c                $    | j                          y N)render_finish)rA   exc_type	exc_valuetbs       rC   __exit__zProgressBar.__exit__y   s     	rE   c                p    | j                   st        d      | j                          | j                         S )N.You need to use progress bars in a with block.)r=   RuntimeErrorrG   	generatorrH   s    rC   __iter__zProgressBar.__iter__   s.    ||OPP~~rE   c                *    t        t        |             S rK   )nextr3   rH   s    rC   __next__zProgressBar.__next__   s     DJrE   c                    | j                   s| j                  sy | j                  j                  t               | j                  j                          y rK   )r"   r?   r(   write	AFTER_BARflushrH   s    rC   rL   zProgressBar.render_finish   s0    ;;dmm			"		rE   c                    | j                   ryt        | j                  t        | j                  xs d      xs dz  d      S )N      ?r	   )r;   minr5   floatr4   rH   s    rC   pctzProgressBar.pct   s5    ==488uT[[%5A6;!<cBBrE   c                    | j                   syt        | j                         t        t        | j                               z  S Ng        )r6   sumr`   lenrH   s    rC   time_per_iterationzProgressBar.time_per_iteration   s,    xx488}uS]333rE   c                    | j                   2| j                  s&| j                  | j                   | j                  z
  z  S yrc   )r4   r;   rf   r5   rH   s    rC   etazProgressBar.eta   s3    ;;"4==**dkkDHH.DEErE   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:   intrh   )rA   r0   secondsminuteshourss        rC   
format_etazProgressBar.format_eta   s    >>DHHA"fG"HA"fG"HAFE"HA1uBuRj'"QwrlCC1WRL'">>rE   c                l    t        | j                        }| j                  |d| j                   z  }|S )N/)strr5   r4   )rA   r5   s     rC   
format_poszProgressBar.format_pos   s3    $((m;;"Qt{{m$$C
rE   c                @    t        | j                  dz        dddd  S )Nd   z 4%r	   )rn   ra   rH   s    rC   
format_pctzProgressBar.format_pct   s&    dhhn%b)+AB//rE   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   )r4   rn   ra   r,   r   r   r;   listrf   mathcosr5   join)rA   
bar_lengthbarcharss       rC   
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
rE   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$   r4   r%   appendrv   rz   r#   r:   r;   rr   r&   r>   r    r'   r   r!   r   rstrip)rA   r$   	info_bits	item_infos       rC   format_progress_linez ProgressBar.format_progress_line   s   ((	;;"|';#}},L==T__./T__./==T^^DMMT__./*++D,=,=>I$  + (**95 &(	rE   c                X   dd l }| j                  ry | j                  sW| j                  | j                  k7  r=| j                  | _        t        | j                  | j                  | j                         y g }| j                  r| j                  }d| _	        t        | j                               }t        d|j                         j                  |z
        }||k  rF| j                  :|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   r   maxget_terminal_sizecolumnsr<   r   
BEFORE_BARr   r\   )	rA   r   buf	old_widthclutter_length	new_widthclear_widthlineline_lens	            rC   rG   zProgressBar.render_progress   s   ;;}}$**,"&**TZZdiitzzB>>

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

:&

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

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

4

3+012wws| 4??""DODIITZZEBIIOO #rE   c                   | 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   r4   r;   r7   r9   r8   r6   r:   )rA   n_stepssteps      rC   	make_stepzProgressBar.make_step  s    G;;"txx4;;'> DMIIK$--'3.		
 88IIK$**,8D99;+D88BC=D6)D0rE   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   rG   )rA   r   r>   s      rC   updatezProgressBar.update1  sb      # ,D!!W,!$$(=(==NN4445  "()D% >rE   c                .    d| _         d | _        d| _        y )NFT)r:   r>   r;   rH   s    rC   finishzProgressBar.finishK  s     rE   c              #  X  K   | j                   st        d      | j                  s| 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.
        rR   Nr   r	   )	r=   rS   r?   r3   r>   r+   rG   r   r   )rA   rvs     rC   rT   zProgressBar.generatorP  s      ||OPP}}yy  ii 
$&!
 ,,1((*A
 KKM  " !s   3B*B(A3B*)N#r   z%(bar)sz  FTNFNNNNr	      )"rB   zcabc.Iterable[V] | Noner4   z
int | Noner   ru   r   ru   r    ru   r!   ru   r"   boolr#   r   r$   bool | Noner%   r   r&   z)t.Callable[[V | None], str | None] | Noner'   
str | Noner(   zt.TextIO | Noner)   r   r*   rn   r,   rn   returnNone)r   zProgressBar[V])rM   ztype[BaseException] | NonerN   zBaseException | NonerO   zTracebackType | Noner   r   )r   zcabc.Iterator[V])r   r   )r   r   )r   r`   r   ru   )r   rn   r   r   rK   )r   rn   r>   zV | Noner   r   )__name__
__module____qualname__rD   rI   rP   rU   rX   rL   propertyra   rf   rh   rr   rv   rz   r   r   rG   r   r   r   rT    rE   rC   r   r   ,   s    "%$(DH  $! !#E+)E+ E+ 	E+
 E+ E+ E+ E+ E+ "E+ E+ BE+ E+ E+ E+  !E+" #E+$ 
%E+N
, ( !	
 
   C C
 4 4
  
0&6,\1,*4
#rE   r   c                @   t               }|
t               }t        t        j                        rt        |      st        || |      S t        j                  t        j                  j                  dd      d      }|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	g|      ryt        | d
g|      ryddl}|j#                         \  }}t        j$                  |       	 t        | d	g|      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   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)rT   r)   stdoutpager_cmd_partsr   fdfilenames          rC   pagerr   r  sH   !#F ~#))F6N&)U33 kk"**..""=UKOi%@	?E:	zz~~f!22&)U33s||&&u->F8U4 	)fXu-##%LBHHRLi&51 			( &)U3
		(		(s   ?F $F Fc                   |sy|d   }|dd }t        |      }|syt        |      j                         }|j                  }ddl}t        t        j                        }	|L|dk(  rGt        j                  j                  dd       dj                  |       }
|
sd	|	d<   d
}n
d|
v sd|
v rd
}|j                  t        |      g|z   d
|j                  |	dd
      }|j                  J 	 | D ]*  }|st        |      }|j                  j                  |       , 	 	 |j                  j'                          	 	 |j)                          	 y
# t         $ r Y :t"        $ r}|j%                          |d}~ww xY w# t         $ r Y Lw xY w# t*        $ r Y nw xY w_# 	 |j                  j'                          n# t         $ r Y nw xY w	 	 |j)                          w # t*        $ r Y nw xY w"xY w)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   Popenru   PIPEr   r   rZ   BrokenPipeError	Exception	terminater   waitKeyboardInterrupt)rT   	cmd_partsr)   cmd
cmd_paramscmd_filepathcmd_pathcmd_namer   r   
less_flagscr   es                 rC   r   r     s    
A,C12J:LL!))+H}}H rzz
C }V+

vr23CHHZ4H3IJ
CKEJ#"3E	X*$oo 	 	A 77' 	 D!$'GGMM$		 "	GGMMO  G   
 	
  		 %  	GGMMO  		   %  s   )/E F E5 6F 	E2F E2E--E22F 5	F F	FFG#F10G#1	F=:G#<F==G#GG#	GG#GG#c                   |sy|d   }t        |      }|syt        |      j                         }ddl}ddl}|j                         \  }}	dj                  |       }
|st        |
      }
t        t        j                        }t        |	d      d   5 }|j                  |
j                  |             ddd       	 |j                  t        |      |	g       t#        j$                  |       t#        j&                  |	       y# 1 sw Y   Qx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.
    Fr   Nr   wbT)r   r   r   r   r   r   r   r   r   r   r   r   rZ   encodecallru   OSErrorr   r   r   )rT   r   r)   r   r   r   r   r   r   r   r   encodingfs                rC   r   r     s    
A,C:LL!))+H##%LB779D$ ,H	Xt	$Q	' '1	H%&'X12
 	
		(' '   	
		(s0   !D;D D	DD DD ,E	c                N    |D ]   }|st        |      }| j                  |       " y)z>Simply print unformatted text.  This is the ultimate fallback.N)r   rZ   )streamrT   r)   r   s       rC   r   r      s,      d#DTrE   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y)EditorNc                <    || _         || _        || _        || _        y rK   )editorr   require_save	extension)rA   r   r   r   r   s        rC   rD   zEditor.__init__+  s!     ("rE   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       rC   
get_editorzEditor.get_editor7  sj    ;;";;% 	C$B		 6 	FV}(	 rE   c                   dd l }| j                         }d }| j                  r9t        j                  j                         }|j                  | j                         dj                  d |D              }	 |j                  | d| |d      }|j                         }|dk7  r$t        t        d      j                  |            y # t        $ r+}t        t        d      j                  ||	            |d }~ww xY w)
Nr   r   c              3  (   K   | ]
  }d | d   yw)"Nr   ).0r   s     rC   	<genexpr>z$Editor.edit_files.<locals>.<genexpr>O  s     JH!H:QJs   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   )	rA   	filenamesr   r   r   exc_filenamer   	exit_coder   s	            rC   
edit_fileszEditor.edit_filesE  s    ")-88jjoo'GNN488$xxJ	JJ	  xq/WD ! A IA~$01888G    	 129919M	s   5AC 	C<&C77C<c                     y rK   r   rA   r   s     rC   editzEditor.edit_  s    =@rE   c                     y rK   r   r  s     rC   r  zEditor.editd  s    47rE   c                   dd l }|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#                  |f       | 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   rE   r   z
z	utf-8-sigzutf-8zeditor-)prefixsuffixr      rb)r   
isinstancebytes	bytearrayendswithr   r   r   r   r   r   fdopenrZ   utimepathgetatimegetmtimer  r   r   openreaddecode)	rA   r   r   datar   r   r   	timestampr   s	            rC   r  zEditor.editg  s   <Dui01DDMM$/||D&188E{{7+##9T^^#LD	2t$  HHTBGG,,T2BGG4D4DT4JQ4NOP ((.IOOTG$  RWW%5%5d%;y%H IIdO dD! QVVX $	 23 IIdO 99[)11&$?IIdO3 "  IIdOsI   H1 +H=B<H1 H1 H%-H1 " H1 H"H1 %H.*H1 1I)NNTz.txt)
r   r   r   zcabc.Mapping[str, str] | Noner   r   r   ru   r   r   r   )r  cabc.Iterable[str]r   r   )r   zbytes | bytearrayr   zbytes | None)r   r   r   r   )r   zstr | bytes | bytearray | Noner   zstr | bytes | None)	r   r   r   rD   r  r  r0   overloadr  r   rE   rC   r   r   *  s|     "-1!
#
# +
# 	
#
 
# 

#4 ZZ@ @ ZZ7 7-rE   r   c                `   dd l }d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   c                J    ddl m} | j                  d      r || dd        } | S )Nr   )unquotezfile://   )urllib.parser-  r   )urlr-  s     rC   _unquote_filezopen_url.<locals>._unquote_file  s&    (>>)$#ab'"C
rE   darwinr$  z-Wr   z	/dev/nullw)stderrexplorerz/select,r8   z/WAITr      cygstartz-w.zxdg-open)zhttp://zhttps://r	   )r0  ru   r   ru   )r   r   r   r   r$  r   r   r   r   r   r   r   r   r!  dirnamer   
webbrowser)	r0  r   locater   r1  r
  nullr   r:  s	            rC   open_urlr=    s    ||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   ) G +G G& (AG5 G	G#"G#&	G21G253H-,H-c                v    | dk(  r
t               | dk(  rt        s
t               | dk(  rt        r
t               y )N)r   r   EOFError)chs    rC   _translate_ch_to_excrD    s7    	V|!!	V|Cj	V|jrE   win32c               #     K   d y w)Nr   r   r   rE   rC   raw_terminalrG    s     s   c                8   | r<t        j                  t         j                  g t        f   t        j
                        }n;t        j                  t         j                  g t        f   t        j                        } |       }|dv r
| |       z  }t        |       |S )N)    à)r0   r1   Callableru   msvcrtgetwchegetwchrD  )r   funcr   s      rC   getcharrP    ss    > 66!**RW-v~~>D66!**RW-v}}=DV!! $&LBR 	rE   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      rC   rG  rG  $  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   )rG  r   r%  r&  r   r   r   r   r   rZ   rD  )r   r   rC  s      rC   rP  rP  ?  so    ^ 	rR''(9#))(DiPBszz*

  $ $	 	 	s   BBB"rK   )rT   r)  r)   r   r   r   )rT   r)  r   z	list[str]r)   r   r   r   )r   zt.TextIOrT   r)  r)   r   r   r   )FF)r0  ru   r   r   r;  r   r   rn   )rC  ru   r   r   )r   zcabc.Iterator[int])r   r   r   ru   ):__doc__
__future__r   collections.abcabccabc
contextlibr}   r   r   r   r7   typingr0   r   r  ior   pathlibr   r   r   typesr   _compatr
   r   r   r   r   r   r   r   
exceptionsr   utilsr   TypeVarr   r   r   r[   Genericr   r   r   r   r   r   r=  rD  r   rL  contextmanagerrG  rP  rS  rU  r   rE   rC   <module>rm     s   #    	  
         )  &       & AIIcN77d?JIJIC#!))A, C#L
'TW!W.7W@KW	Wt'!'.7'@K'	'T!3<G	j jZDN
 <<7 ,^  4rE   