
    F d[              	       b   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  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ej        e         dej         e!         ddfdZ"dej        e         dedej         e!         ddfdZ#dej        e         dedej         e!         ddfdZ$dej%        dej        e         dej         e!         ddfdZ& G d  d!          Z'd/d#ed$e!d%e!de(fd&Z)d'edej         e*         fd(Z+er,ddl,Z,ej-        dej.        e(         fd)            Z/d*e!defd+Z0dS ddl1Z1ddl2Z2ej-        dej.        e(         fd,            Z/d*e!defd-Z0dS )0z
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   )_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d0dZd Zdej        e         fdZdefdZd1d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d1d(Zd)eddfd*Zd2d)ed+ej        e         ddfd,Zd1d-Z dej        e         fd.Z!dS )3ProgressBarN# %(bar)s  TFr      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                    || _         || _        || _        || _        || _        || _        |	| _        |
| _        |pd| _        |t                      }|| _
        || _        || _        d| _        || _        |dk    | _        |ddlm}  ||d          }|dk    rd }|H|t%          d          t'          j        t&          j        t,                   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 requiredF)'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                    [C:\Users\ChattiNader\Documents\MyHotelMatch\api\dev\Lib\site-packages\click/_termui_impl.py__init__zProgressBar.__init__$   sp   $ #$(  ( ,[b
<'))D	
 0$%!
!>,,,,,, [2..F||~ @AAAvajmU6]];;HNN	"$%)Y[[0
T]*.+/#DI...+/    c                 <    d| _         |                                  | S )NT)r?   render_progressrC   s    rD   	__enter__zProgressBar.__enter__`   s     rF   c                 .    |                                   d S N)render_finish)rC   exc_type	exc_valuetbs       rD   __exit__zProgressBar.__exit__e   s    rF   c                 ~    | j         st          d          |                                  |                                 S )N.You need to use progress bars in a with block.)r?   RuntimeErrorrH   	generatorrI   s    rD   __iter__zProgressBar.__iter__h   s>    | 	QOPPP~~rF   c                 :    t          t          |                     S rL   )nextr6   rI   s    rD   __next__zProgressBar.__next__n   s     DJJrF   c                     | j         rd S | j                            t                     | j                                         d S rL   )rA   r%   write	AFTER_BARflushrI   s    rD   rM   zProgressBar.render_finishv   s=    > 	F		"""	rF   c                 p    | j         rdS t          | j        t          | j        pd          pdz  d          S )N      ?r   )r=   minr7   floatr   rI   s    rD   pctzProgressBar.pct|   s<    = 	348uT[%5A66;!<cBBBrF   c                     | j         sdS t          | j                   t          t          | j                             z  S Ng        )r8   sumra   lenrI   s    rD   time_per_iterationzProgressBar.time_per_iteration   s4    x 	348}}uS]]3333rF   c                 P    | j         | j        s| j        | j         | j        z
  z  S dS rd   )r   r=   rg   r7   rI   s    rD   etazProgressBar.eta   s-    ;"4="*dkDH.DEEsrF   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+   )r<   intri   )rC   r2   secondsminuteshourss        rD   
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>>>'>>>>rrF   c                 V    t          | j                  }| j        |d| j         z  }|S )N/)strr7   r   )rC   r7   s     rD   
format_poszProgressBar.format_pos   s1    $(mm;"$t{$$$C
rF   c                 H    t          | j        dz            dddd          S )Nd   z 4%r   )ro   rb   rI   s    rD   
format_pctzProgressBar.format_pct   s+    dhn%%++++ABB//rF   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   ro   rb   r(   r   r   r=   listrg   mathcosr7   join)rC   
bar_lengthbarcharss       rD   
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
rF   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"   appendrw   r{   r    r<   r=   rs   r#   r@   r   r$   r   r   r   rstrip)rC   r!   	info_bits	item_infos       rD   format_progress_linez ProgressBar.format_progress_line   s3   (	;"|';#},L= 	0T__../// 	0T__..///= 	0T^ 	0DM 	0T__..///*++D,=>>I$  +++ ((**955  &((	rF   c                    dd l }| j        r?| j        | j        k    r-| j        | _        t	          | j        | j        | j                   d S g }| j        r| j        }d| _        t          | 
                                          }t          d|                                j        |z
            }||k     r>|                    t                     |                    d| j        z             || _        || _        | j        }| j        | j        }|                    t                     | 
                                }t          |          }| j        | j        |k     r|| _        |                    |           |                    d||z
  z             d                    |          }|| j        k    r?|| _        t	          || j        | j        d           | j                                         d S d S )Nr   )r%   r&   r   r+   F)r%   r&   nl)shutilrA   rB   r$   r   r%   r&   r/   r(   r   r   maxget_terminal_sizecolumnsr   
BEFORE_BARr>   r   r]   )	rC   r   buf	old_widthclutter_length	new_widthclear_widthlineline_lens	            rD   rH   zProgressBar.render_progress   s   > 	 $*,,"&*TZditzBBBBF> 		#
IDJ%d&?&?&A&ABBNAv7799ANRSSI9$$

:&&&

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 #"rF   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 )NTr_   i)r7   r   r=   r9   r;   r:   r8   r<   )rC   r   steps      rD   	make_stepzProgressBar.make_step  s    G;"tx4;'>'> DMIKK$-'3..F	
 8 	,IKK$*,8DD9;;+D8BCC=D6)D0rF   r@   c                     ||| _         | 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   )r@   r.   r'   r   rH   )rC   r   r@   s      rD   updatezProgressBar.update  st      # ,D!!W,!!$(===NN44555  """()D%%% >=rF   c                 0    d| _         d | _        d| _        d S )NFT)r<   r@   r=   rI   s    rD   finishzProgressBar.finish1  s     rF   c              #   D  K   | j         st          d          | j        r| 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.
        rS   Nr   r   )	r?   rT   rA   r6   r@   r.   rH   r   r   )rC   rvs     rD   rU   zProgressBar.generator6  s       | 	QOPPP> 	#y         i 
 
$&!
 ,11((***AKKMMM  """""rF   )Nr   r   r   r   TNFNNNNr   r   )r)   r   )r)   NrL   )"__name__
__module____qualname__r2   Optionalr4   r   ro   rv   boolCallableTextIOrE   rJ   rQ   IteratorrV   rY   rM   propertyra   rb   rg   ri   rs   rw   r{   r   r   rH   r   r   r   rU    rF   rD   r   r   #   s]        #'%)-SW!%%)"& !!:0 :0*QZ]+:0 
3:0 	:0
 :0 :0 :0 :0 j&:0 :0 
1:qz!}oqz#.N#OP:0 z#:0 j":0 z$:0 :0  !:0" 
#:0 :0 :0 :0x   
   !*Q-         !            CU C C C XC
 4E 4 4 4 X4
 U    X
C    C    0C 0 0 0 0C    &c    6+ + + +Z1 1 1 1 1 1,* *c *A *$ * * * *4   
#1:a= # # # # # #rF   r   rU   r&   r)   c                 $   t                      }t          t          j                  rt          |          st	          || |          S t
          j                            dd          pd                                }|r)t          rt          | ||          S t          | ||          S t
          j                            d          dv rt	          || |          S t          st          j                            d          rt          | d|          S t          t
          d          r)t          j        d	          d
k    rt          | d|          S d
dl}|                                \  }}t          j        |           	 t          t
          d          rAt          j        d| d          d
k    r%t          | d|          t          j        |           S t	          || |          t          j        |           S # t          j        |           w xY w)z2Decide what method to use for paging through text.PAGERNr+   TERM)dumbemacsos2zmore <systemz(less) 2>/dev/nullr   lesszmore ""more)r   r   sysstdin
_nullpagerosenvirongetstripr   _tempfilepager
_pipepagerplatform
startswithhasattrr   tempfilemkstempcloseunlink)rU   r&   stdout	pager_cmdr   fdfilenames          rD   pagerr   X  s   !##F#) 4F6NN 4&)U333..4";;==I 7 	?!)Y>>>)Y666	z~~f!222&)U333
 :cl%%e,, :i5999r8 4+?!@!@A!E!E)VU333OOO##%%LBHRLLL2x   	8RY/C/C/C/C%D%D%I%Ii77 		( &)U33
	(	(s   >AG9 G9 9Hcmdc                 (   ddl }t          t          j                  }|                    dd          d                                         }|_|d         dk    rSt          j                            dd           d	                    |dd                    }|sd
|d<   d}n
d|v sd|v rd}|                    |d|j	        |          }t          j        t          j        |j                  }t          |          }		 | D ]<}
|st          |
          }
|                    |
                    |	d                     =	 |                                 n# t&          t(          f$ r Y nw xY w	 	 |                                 dS # t(          $ r Y nw xY w()zqPage through text by feeding it to another program.  Invoking a
    pager through this might support colors.
    r   Nru   r   r-   r   LESSr+   r   -RTrR)shellr   envreplace)
subprocessdictr   r   rsplitsplitr   r   PopenPIPEr2   r3   BinaryIOr   r   r
   r[   encoder   OSErrorKeyboardInterruptwait)rU   r   r&   r   r   
cmd_detail
less_flagscr   encodingtexts              rD   r   r   u  s    
rz

C C##B'--//J}A&00
vr22NCHHZ^4L4LNN
 	CKEEJ#"3"3ED
SIIAF1:qw''E ''H	 	: 	:D (!$''KKHi889999		: 	 &'   	FFHHH E ! 	 	 	D	s$   ??E E('E(-F 
FFc                 F   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          j        | d| d           t          j        |           t          j        |           dS # t          j        |           t          j        |           w xY w)z<Page through text by invoking a program on a temporary file.r   Nr+   wb "r   )r   r   r   r
   r   r   r   r	   r[   r   r   r   r   r   )	rU   r   r&   r   r   r   r   r   fs	            rD   r   r     sK    OOO##%%LB779D  $ ,,H	Xt	$	$Q	' '1	H%%&&&' ' ' ' ' ' ' ' ' ' ' ' ' ' '
	S''H'''(((

	( 	
	(s   1)B&&B*-B*2C6 6*D streamc                 \    |D ](}|st          |          }|                     |           )dS )z>Simply print unformatted text.  This is the ultimate fallback.N)r
   r[   )r   rU   r&   r   s       rD   r   r     sG        	$d##DT rF   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dS )EditorNT.txteditorr   require_save	extensionr)   c                 >    || _         || _        || _        || _        d S rL   )r   r   r   r   )rC   r   r   r   r   s        rD   rE   zEditor.__init__  s%     ("rF   c                     | j         | j         S dD ]'}t          j                            |          }|r|c S (t          rdS dD ]"}t          j        d| d          dk    r|c S #dS )N)VISUALEDITORnotepad)zsensible-editorvimnanozwhich z >/dev/null 2>&1r   vi)r   r   r   r   r   r   )rC   keyr   r   s       rD   
get_editorzEditor.get_editor  s    ;";% 	 	C$$B 			 	96 	 	Fy:&:::;;q@@ AtrF   r   c                    dd l }|                                 }d }| j        r8t          j                                        }|                    | j                   	 |                    | d| d|d          }|                                }|dk    r0t          t          d                              |                    d S # t          $ r7}t          t          d                              ||	                    |d }~ww xY w)
Nr   r   r   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   )rC   r   r   r   r   r   	exit_coder   s           rD   	edit_filezEditor.edit_file  s"   ""048 	%joo''GNN48$$$
	  F!9!9h!9!9!9wd SSA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   c                    dd l }|s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                            |          }|                     |           | 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   rF   r   z
z	utf-8-sigzutf-8zeditor-)prefixsuffixr      rb)r   
isinstancebytes	bytearrayendswithr   r   r   r   r   r   fdopenr[   utimepathgetatimegetmtimer  r   r   openreaddecode)	rC   r   r   datar   namer   	timestampr   s	            rD   editzEditor.edit  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NN4     RW%5%5d%;%;y%H%H IdOOOOO dD!! QVVXX               $	 233  IdOOOO 99[))11&$??IdOOOOBIdOOOOsa   +I!  C"I! "C&&I! )C&*B5I! 6I! G'I! 'G++I! .G+/ I! $(I! !I7)NNTr   )r   r   r   r2   r   rv   Mappingr   rE   r   r  AnyStrr  r   rF   rD   r   r     s         #'/3!
# 
#
3
# Z	#s(+,
# 	
#
 
# 

# 
# 
# 
#C    # $    ,-AH- -!*QX2F - - - - - -rF   r   Furlr   locatec                    dd l }dt          dt          fd}t          j        dk    rdg}|r|                    d           |r|                    d           |                     ||                      t          d	d
          }	 |                    ||                                          |                                 S # |                                 w xY wt          ra|r& || 
                    dd                    } d|  d}n%| 
                    dd          } |rdnd}d| d|  d}t          j        |          S t          r~|rCt          j                             ||           
                    dd                    } d|  d}n%| 
                    dd          } |rdnd}d| d|  d}t          j        |          S 	 |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)   c                 b    ddl m} |                     d          r || dd                    } | S )Nr   )unquotezfile://   )urllib.parser  r   )r  r  s     rD   _unquote_filezopen_url.<locals>._unquote_file*  sD    ((((((>>)$$ 	#'#abb'""C
rF   darwinr  z-Wr   z	/dev/nullw)stderrr   r+   zexplorer /select,"z/WAITzstart z "" "z
cygstart "z-wz	cygstart r   .zxdg-open)zhttp://zhttps://r   )r   rv   r   r   r   r  r   r   r   r   r   r   r   r   r  dirnamer   r   
webbrowser)
r  r   r  r   r!  argsnullwait_strr   r'  s
             rD   open_urlr+  '  s   3 3     |xx 	KK 	KKMM#&&'''K%%	##D#66;;==JJLLLLDJJLLLL	  	2-C 4 455C....DD++c2&&C"&.wwBH1H113111Dy	  	2'//--"4"4"<"<S""E"EFFC&&&&DD++c2&&C#+ttH1x113111Dy 	%'//--"4"455<CC-$$Cj#.// 	6688Oq   >>122 	6 	$ 	OOC   11qqs   (C CA$H2 2<I54I5chc                     | dk    rt                      | dk    rt          st                      | dk    rt          rt                      d S )N)r   r   EOFError)r,  s    rD   _translate_ch_to_excr2  c  sJ    	V||!!!	V||C|jj	V|||jj4rF   c               #      K   dV  d S )Nr-   r   r   rF   rD   raw_terminalr4  s  s      rF   r   c                     | rt           j        }nt           j        } |            }|dv r| |            z  }t          |           |S )N)    à)msvcrtgetwchegetwchr2  )r   funcr   s      rD   getcharr<  w  sX    @  	!>DD=DTVV!!! $$&&LBR   	rF   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   r  filenotermios	tcgetattrttysetraw	tcsetattr	TCSADRAINr   r]   r   error)r   r   old_settingss      rD   r4  r4    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   )r4  r   r  r  r   r   r   r   r   r[   r2  )r   r   r,  s      rD   r<  r<    s    ^^ 	rR''(9#)(D(DiPPB %sz** %
  $$$ $$$	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BB''B+.B+rL   )FF)3__doc__
contextlibr~   r   r   r9   typingr2   r   r   _compatr   r   r   r   r	   r
   r   r   
exceptionsr   utilsr   TypeVarr   r  r   r\   Genericr   r4   rv   r   r   r   r   r   r   r   r   ro   r+  BaseExceptionr2  r8  contextmanagerr   r4  r<  rA  r?  r   rF   rD   <module>rS     s   
      				 



                  ) ) ) ) ) )       & & & & & &                                     & & & & & &      AIcNN7d??JIIJIr# r# r# r# r#!)A, r# r# r#j	 QZ_ QZ-=     :/!*S/ / /AJt<L /QU / / / /dz#%(12D1A	   *H!"C9:D9I	   ^ ^ ^ ^ ^ ^ ^ ^B9 9# 9T 94 9C 9 9 9 9x
S 
QZ%> 
 
 
 
  ]MMM!*S/    -d -s - - - - - -` JJJNNN!*S/    4d s      rF   