
    hh                       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jF                  d      Z$ejJ                  dk(  rdZ&dZ'ndZ&dZ' G d dejP                  e$         Z)d(d)dZ*	 	 	 	 	 	 	 	 d*dZ+	 	 	 	 	 	 	 	 d*dZ,	 	 	 	 	 	 	 	 d+dZ- G d d       Z.d,d-d!Z/d.d"Z0e
jb                  d#k(  rddl2Z2ejf                  d/d$       Z4d0d%Z5yddl6Z6ddl7Z7ejf                  d/d&       Z4d0d'Z5y)1z
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                  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iterabler3   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r+   r   s                     P/var/www/html/eduruby.in/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r@   s    rB   	__enter__zProgressBar.__enter__s   s    rD   c                $    | j                          y N)render_finish)r@   exc_type	exc_valuetbs       rB   __exit__zProgressBar.__exit__x   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__   s.    ||OPP~~rD   c                *    t        t        |             S rJ   )nextr2   rG   s    rB   __next__zProgressBar.__next__   s     DJrD   c                    | j                   s| j                  sy | j                  j                  t               | j                  j                          y rJ   )r!   r>   r'   write	AFTER_BARflushrG   s    rB   rK   zProgressBar.render_finish   s0    ;;dmm			"		rD   c                    | j                   ryt        | j                  t        | j                  xs d      xs dz  d      S )N      ?r   )r:   minr4   floatr3   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        )r5   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   )r3   r:   re   r4   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   )r9   intrg   )r@   r/   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/)strr4   r3   )r@   r4   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   )r3   rm   r`   r+   r   r   r:   listre   mathcosr4   join)r@   
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#   r3   r$   appendru   ry   r"   r9   r:   rq   r%   r=   r   r&   r   r    r~   rstrip)r@   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                X   | j                   ry | j                  sW| j                  | j                  k7  r=| j                  | _        t	        | j                  | j
                  | j                         y g }| j                  rdd l}| 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 )N)r'   r(   r    r   F)r'   r(   nl)r!   r>   r?   r&   r   r'   r(   r,   shutilr+   r   r   maxget_terminal_sizecolumnsr;   r   
BEFORE_BARr~   r[   )	r@   bufr   	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$)C

:&

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

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

4

3+012wws| 4??""DODIITZZEBIIOO #rD   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)r4   r3   r:   r6   r8   r7   r5   r9   )r@   n_stepssteps      rB   	make_stepzProgressBar.make_step  s    G;;"txx4;;'> DMIIK$--'3.		
 88IIK$**,8D99;+D88BC=D6)D0rD   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   )r@   r   r=   s      rB   updatezProgressBar.update0  sb      # ,D!!W,!$$(=(==NN4445  "()D% >rD   c                .    d| _         d | _        d| _        y )NFT)r9   r=   r:   rG   s    rB   finishzProgressBar.finishJ  s     rD   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.
        rQ   Nr   r   )	r<   rR   r>   r2   r=   r*   rF   r   r   )r@   rvs     rB   rS   zProgressBar.generatorO  s      ||OPP}}yy  ii 
$&!
 ,,1((*A
 KKM  " !s   3B*B(A3B*)N#r   z%(bar)sz  FTNFNNNNr      )"rA   zcabc.Iterable[V] | Noner3   z
int | Noner   rt   r   rt   r   rt   r    rt   r!   boolr"   r   r#   bool | Noner$   r   r%   z)t.Callable[[V | None], str | None] | Noner&   
str | Noner'   zt.TextIO | Noner(   r   r)   rm   r+   rm   returnNone)r   zProgressBar[V])rL   ztype[BaseException] | NonerM   zBaseException | NonerN   zTracebackType | Noner   r   )r   zcabc.Iterator[V])r   r   )r   r   )r   r_   r   rt   )r   rm   r   r   rJ   )r   rm   r=   zV | Noner   r   )__name__
__module____qualname__rC   rH   rO   rT   rW   rK   propertyr`   re   rg   rq   ru   ry   r   r   rF   r   r   r   rS    rD   rB   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
#rD   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)rS   r(   stdoutpager_cmd_partsr   fdfilenames          rB   pagerr   q  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l }|d   }|dd }|j                  |      }|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   Nr   r   LESSr   r   -RTrRreplace)shellr   enverrorstext)r   whichr   resolvename
subprocessdictr   r   r   r~   Popenrt   PIPEr   r   rY   BrokenPipeError	Exception	terminater   waitKeyboardInterrupt)rS   	cmd_partsr(   r   cmd
cmd_paramscmd_filepathcmd_pathcmd_namer   r   
less_flagscr   es                  rB   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   3/E "F $E?  F 	E<F E<%E77E<<F ?	F
F	FFG- F;:G-;	GG-GG-GG-	G)&G-(G))G-c                   |syddl }|d   }|j                  |      }|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   r   rY   encodecallrt   OSErrorr   r   r   )rS   r   r(   r   r   r   r   r   r   r   r   r   encodingfs                 rB   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   rY   )streamrS   r(   r   s       rB   r   r   %  s,      d#DTrD   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 rJ   )editorr   require_save	extension)r@   r   r   r   r   s        rB   rC   zEditor.__init__0  s!     ("rD   c                    | j                   | j                   S dD ]'  }t        j                  j                  |      }|s%|c S  t        ryddlm} dD ]  } ||      |c S  y)N)VISUALEDITORnotepadr   )r   )zsensible-editorvimnanovi)r   r   r   r   r   r   r   )r@   keyr   r   r   s        rB   
get_editorzEditor.get_editor<  sm    ;;";;% 	C$B		  6 	FV}(	 rD   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     rB   	<genexpr>z$Editor.edit_files.<locals>.<genexpr>W  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   )	r@   	filenamesr   r   r   exc_filenamer   	exit_coder   s	            rB   
edit_fileszEditor.edit_filesM  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 rJ   r   r@   r   s     rB   editzEditor.editg  s    =@rD   c                     y rJ   r   r  s     rB   r  zEditor.editl  s    47rD   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   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)	r@   r   r   datar   r   r   	timestampr   s	            rB   r  zEditor.edito  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   rt   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   rC   r  r  r/   overloadr  r   rD   rB   r   r   /  s|     "-1!
#
# +
# 	
#
 
# 

#"4 ZZ@ @ ZZ7 7-rD   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     rB   _unquote_filezopen_url.<locals>._unquote_file  s&    (>>)$#ab'"C
rD   darwinr$  z-Wr   z	/dev/nullw)stderrexplorerz/select,r7   z/WAITr      cygstartz-w.zxdg-open)zhttp://zhttps://r   )r0  rt   r   rt   )r   r   r   r   r$  r   r   r   r   r   r   r
   r   r!  dirnamer   
webbrowser)	r0  r   locater   r1  r
  nullr   r:  s	            rB   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    rB   _translate_ch_to_excrD    s7    	V|!!	V|Cj	V|jrD   win32c               #     K   d y w)Nr   r   r   rD   rB   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)    à)r/   r0   Callablert   msvcrtgetwchegetwchrD  )r   funcr   s      rB   getcharrP    ss    > 66!**RW-v~~>D66!**RW-v}}=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   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   rY   rD  )r   r   rC  s      rB   rP  rP  G  so    ^ 	rR''(9#))(DiPBszz*

  $ $	 	 	s   BBB"rJ   )rS   r)  r(   r   r   r   )rS   r)  r   z	list[str]r(   r   r   r   )r   zt.TextIOrS   r)  r(   r   r   r   )FF)r0  rt   r   r   r;  r   r   rm   )rC  rt   r   r   )r   zcabc.Iterator[int])r   r   r   rt   )8__doc__
__future__r   collections.abcabccabc
contextlibr|   r   r   r   r6   typingr/   r   r  ior   pathlibr   typesr   _compatr	   r
   r   r   r   r   r   r   
exceptionsr   utilsr   TypeVarr   r   r   rZ   Genericr   r   r   r   r   r   r=  rD  r   rL  contextmanagerrG  rP  rS  rU  r   rD   rB   <module>rm     s   #    	  
        )  &       & AIIcN77d?JIJIC#!))A, C#L
'TZ!Z.7Z@KZ	Zz*!*.7*@K*	*Z!3<G	m m`DN
 <<7 ,^  4rD   