
     jF                       U d dl mZ d dl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mZ d dlmZ e	j                   j#                  d      Ze	j                   j#                  d      Z ej(                  d      Z	 	 d6	 	 	 	 	 	 	 	 	 	 	 d7dZd8d	Zd9d
Z G d dej2                        Z G d d      Zd:d;dZd:d;dZd<dZd<dZd=dZ d>dZ!	 	 	 	 	 	 	 	 d?dZ"	 	 d6	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d@dZ#	 d:	 	 	 	 	 	 	 	 	 dAdZ$	 d:	 	 	 	 	 	 	 	 	 dBdZ%dCdZ&dCdZ'dCdZ(dDdEdZ)dDdEdZ*dDdEdZ+	 	 	 	 	 	 	 	 	 	 dFdZ,	 	 	 	 dG	 	 	 	 	 	 	 	 	 	 	 dHd Z- G d! d"      Z.dId#Z/dJd$Z0	 dD	 	 	 	 	 dKd%Z1e	j                   j#                  d      rerd&d'l2m3Z3 dLd(Z4ndLd)Z4	 	 	 	 	 	 	 	 dMd*Z3dNd+Z5dJd,Z6	 	 	 	 	 	 dOd-Z7 e7d. e)      Z8 e7d/ e*      Z9 e7d0 e+      Z:e&e'e(d1Z;d2e<d3<   e)e*e+d1Z=d4e<d5<   y)P    )annotationsN)TracebackTypeWeakKeyDictionarycygwinwinz\033\[[0-?]*[ -/]*[@-~]c                F    |t        |       }|d}t        | ||d||      S )NreplaceT)line_bufferingforce_readableforce_writable)get_best_encoding_NonClosingTextIOWrapper)streamencodingerrorsr   r   s        Y/home/min/hermes_workspace/demo_review/venv/lib/python3.12/site-packages/click/_compat.py_make_text_streamr      s=     $V,~#%%     c                f    	 t        j                  |       j                  dk(  S # t        $ r Y yw xY w)z$Checks if a given encoding is ascii.asciiF)codecslookupnameLookupError)r   s    r   is_ascii_encodingr   +   s3    }}X&++w66 s   !$ 	00c                d    t        | dd      xs t        j                         }t        |      ry|S )z1Returns the default stream encoding if not found.r   Nzutf-8)getattrsysgetdefaultencodingr   )r   rvs     r   r   r   3   s.    	T	*	Fc.D.D.FBIr   c                  P     e Zd Z	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZddZ xZS )r   c                    t        j                  t         j                  t        |||            x| _        }t        |   |||fi | y N)tcastBinaryIO_FixupStream_streamsuper__init__)selfr   r   r   r   r   extra	__class__s          r   r+   z!_NonClosingTextIOWrapper.__init__<   sF     !"JJV^^L!
 	
v 	6;U;r   c                D    	 | j                          y # t        $ r Y y w xY wr$   )detach	Exceptionr,   s    r   __del__z _NonClosingTextIOWrapper.__del__J   s"    	KKM 		s    	c                6    | j                   j                         S r$   )r)   isattyr2   s    r   r5   z_NonClosingTextIOWrapper.isattyP   s    ||""$$r   FF)r   
t.BinaryIOr   
str | Noner   r8   r   boolr   r9   r-   t.AnyreturnNone)r;   r<   r;   r9   )__name__
__module____qualname__r+   r3   r5   __classcell__)r.   s   @r   r   r   ;   s^      %$<< < 	<
 < < < 
<%r   r   c                  P    e Zd ZdZ	 	 d		 	 	 	 	 d
dZddZddZddZddZddZ	y)r(   aQ  The new io interface needs more from streams than streams
    traditionally implement.  As such, this fix-up code is necessary in
    some circumstances.

    The forcing of readable and writable flags are there because some tools
    put badly patched objects on sys (one such offender are certain version
    of jupyter notebook).
    c                .    || _         || _        || _        y r$   )r)   _force_readable_force_writable)r,   r   r   r   s       r   r+   z_FixupStream.__init___   s     --r   c                .    t        | j                  |      S r$   )r   r)   r,   r   s     r   __getattr__z_FixupStream.__getattr__i   s    t||T**r   c                    t        | j                  dd       }| t        j                  t         ||            S | j                  j                  |      S )Nread1)r   r)   r%   r&   bytesread)r,   sizefs      r   rJ   z_FixupStream.read1l   sC    DLL'40=66%4))||  &&r   c                    | j                   ryt        | j                  dd       }|t        j                  t
         |             S 	 | j                  j                  d       y# t        $ r Y yw xY w)NTreadabler   F)rD   r   r)   r%   r&   r9   rL   r1   r,   xs     r   rP   z_FixupStream.readablet   sh    DLL*d3=66$$$	LLa    		s   A# #	A/.A/c                <   | j                   ryt        | j                  dd       }|t        j                  t
         |             S 	 | j                  j                  d       y# t        $ r/ 	 | j                  j                  d       Y y# t        $ r Y Y yw xY ww xY w)NTwritabler   F)rE   r   r)   r%   r&   r9   writer1   rQ   s     r   rT   z_FixupStream.writable   s    DLL*d3=66$$$	LLs#   	""3'   	s*   A# #	B-B

	BBBBc                    t        | j                  dd       }|t        j                  t         |             S 	 | j                  j                  | j                  j                                y# t        $ r Y yw xY w)NseekableFT)r   r)   r%   r&   r9   seektellr1   rQ   s     r   rW   z_FixupStream.seekable   si    DLL*d3=66$$$	LLdll//12   		s   3A. .	A:9A:Nr6   )r   r7   r   r9   r   r9   r   strr;   r:   )rM   intr;   rK   r=   )
r>   r?   r@   __doc__r+   rH   rJ   rP   rT   rW    r   r   r(   r(   U   sI      %$	.. . 	.+'
r   r(   c                d    	 t        | j                  d      t              S # t        $ r |cY S w xY wNr   )
isinstancerL   rK   r1   r   defaults     r   _is_binary_readerrd      s0    &++a.%00 s   ! //c                    	 | j                  d       y# t        $ r( 	 | j                  d       Y y# t        $ r Y nw xY w|cY S w xY w)Nr    FT)rU   r1   rb   s     r   _is_binary_writerrg      sT    S   	LL 		s%    	A1	=A=AAc                    t        | d      r$t        j                  t        j                  |       S t	        | dd       }|0t        |d      r$t        j                  t        j                  |      S y NFbufferT)rd   r%   r&   r'   r   r   bufs     r   _find_binary_readerrm      Z    
 'vvajj&))
&(D
)C ,S$7vvajj#&&r   c                    t        | d      r$t        j                  t        j                  |       S t	        | dd       }|0t        |d      r$t        j                  t        j                  |      S y ri   )rg   r%   r&   r'   r   rk   s     r   _find_binary_writerrp      rn   r   c                6    t        t        | dd      xs d      S )z3A stream is misconfigured if its encoding is ASCII.r   Nr   )r   r   r   s    r   _stream_is_misconfiguredrs      s     WVZ>I'JJr   c                >    t        | |d      }||k(  xs
 |du xr |duS )zA stream attribute is compatible if it is equal to the
    desired value or the desired value is unset and the attribute
    has a value.
    N)r   )r   attrvaluestream_values       r   _is_compat_stream_attrrx      s0    
 64.L5 PUd]%O|47OPr   c                :    t        | d|      xr t        | d|      S )zcCheck if a stream's encoding and errors attributes are
    compatible with the desired values.
    r   r   )rx   )r   r   r   s      r   _is_compatible_text_streamrz      s)     "
H ;
 6
:;r   c                "    || d      r%t        j                  t         j                  |       }nNt        j                  t         j                  |       } t	        | ||      r|t        |       s| S  ||       }|| S |}|d}t        |||||      S )NFr
   )r   r   )r%   r&   r'   TextIOrz   rs   r   )	text_streamr   r   	is_binaryfind_binaryr   r   binary_readerpossible_binary_readers	            r   _force_correct_text_streamr      s     e$qzz;7ffQXX{3 &k8VD!9+!F "-[!9 "). ~ %% r   c                4    t        | ||t        t        |      S )Nr   )r   rd   rm   )text_readerr   r   r   s       r   _force_correct_text_readerr     #     &% r   c                4    t        | ||t        t        |      S )Nr   )r   rg   rp   )text_writerr   r   r   s       r   _force_correct_text_writerr   /  r   r   c                 R    t        t        j                        } | t        d      | S )Nz6Was not able to determine binary stream for sys.stdin.)rm   r   stdinRuntimeError)readers    r   get_binary_stdinr   ?  s&     +F~STTMr   c                 R    t        t        j                        } | t        d      | S )Nz7Was not able to determine binary stream for sys.stdout.)rp   r   stdoutr   writers    r   get_binary_stdoutr   F  &     ,F~TUUMr   c                 R    t        t        j                        } | t        d      | S )Nz7Was not able to determine binary stream for sys.stderr.)rp   r   stderrr   r   s    r   get_binary_stderrr   M  r   r   c                z    t        t        j                  | |      }||S t        t        j                  | |d      S )NTr   )_get_windows_console_streamr   r   r   r   r   r!   s      r   get_text_stdinr   T  s4    	$SYY&	AB	~	%cii6RVWWr   c                z    t        t        j                  | |      }||S t        t        j                  | |d      S NTr   )r   r   r   r   r   s      r   get_text_stdoutr   [  4    	$SZZ6	BB	~	%cjj(FSWXXr   c                z    t        t        j                  | |      }||S t        t        j                  | |d      S r   )r   r   r   r   r   s      r   get_text_stderrr   b  r   r   c                @    d|v rt        | |      S t        | |||      S )z?Handles not passing ``encoding`` and ``errors`` in binary mode.br   r   )open)filemoder   r   s       r   _wrap_io_openr   i  s)     d{D$dXf==r   c                   dv }t        j                  |       } t        j                  |       dk(  rNt        fddD              r|rt	               dfS t        ||      dfS |rt               dfS t        ||      dfS |st        | ||      dfS dv rt        d	      d
v rt        d      dvrt        d      dd l
}dd l}	 t        j                  |       j                  }t         j                  t         j                   z  t         j"                  z  }	|r|	t%        t         dd      z  }		 t         j&                  j)                  t         j&                  j+                  |       d|j-                  d      d      }
	 t        j.                  |
|	|dn|      }	 |t        j>                  |
|       t        |||      }tA        ||
t         j&                  jC                  |             }tE        jF                  tD        jH                  tD        jJ                     |      dfS # t        $ r d }Y Kw xY w# t        $ r}|j                  |j0                  k(  st         j2                  dk(  rv|j                  |j4                  k(  r]t         j&                  j7                  |j8                        r4t        j:                  |j8                  t         j<                        rY d }~ d }~ww xY w)Nr   -c              3  &   K   | ]  }|v  
 y wr$   r^   ).0mr   s     r   	<genexpr>zopen_stream.<locals>.<genexpr>  s     2/QqDy/s   )warR   Fr   Tr   zAppending to an existing file is not supported, because that would involve an expensive `copy`-operation to a temporary file. Open the file in normal `w`-mode and copy explicitly if that's what you're after.rR   z&Use the `overwrite`-parameter instead.r   z,Atomic writes only make sense with `w`-mode.r   O_BINARYz.__atomic-writel        08xi  nt)&osfspathfsdecodeanyr   r   r   r   r   
ValueErrorerrnorandomstatst_modeOSErrorO_RDWRO_CREATO_EXCLr   pathjoindirname	randranger   EEXISTr   EACCESisdirfilenameaccessW_OKchmod_AtomicFilerealpathr%   r&   IOAny)r   r   r   r   atomicbinaryr   r   permflagstmp_filenamefderN   afs    `             r   open_streamr   v  sy    D[Fyy"H 
{{8#2/22(*E11"HVDeKK#%u,,x?FF XtXv>DD d{,
 	
 d{ABB
$GHH 778,44 II

"RYY.EZ++
ww||GGOOH%f..w7<=
	ut|eNB 
t$b$&1A	Qbgg&6&6x&@	AB66!$$quu+r"D((?     	ww%,,&4GGu||+GGMM!**-IIajj"''2	s1   	H% H7 %H43H47	K( BK#"K##K(c                  `    e Zd Zd	dZed
d       ZdddZddZddZ	 	 	 	 	 	 	 	 ddZ	d
dZ
y)r   c                <    || _         || _        || _        d| _        y NF)_f_tmp_filename_real_filenameclosed)r,   rN   r   real_filenames       r   r+   z_AtomicFile.__init__  s     )+r   c                    | j                   S r$   )r   r2   s    r   r   z_AtomicFile.name  s    """r   c                    | j                   ry | j                  j                          t        j                  | j
                  | j                         d| _         y )NT)r   r   closer   r
   r   r   )r,   deletes     r   r   z_AtomicFile.close  s:    ;;


4%%t':':;r   c                .    t        | j                  |      S r$   )r   r   rG   s     r   rH   z_AtomicFile.__getattr__  s    tww%%r   c                    | S r$   r^   r2   s    r   	__enter__z_AtomicFile.__enter__  s    r   c                ,    | j                  |d u       y )N)r   )r   )r,   exc_type	exc_valuetbs       r   __exit__z_AtomicFile.__exit__  s     	

($.
/r   c                ,    t        | j                        S r$   )reprr   r2   s    r   __repr__z_AtomicFile.__repr__  s    DGG}r   N)rN   t.IO[t.Any]r   r[   r   r[   r;   r<   r;   r[   F)r   r9   r;   r<   rZ   )r;   r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner;   r<   )r>   r?   r@   r+   propertyr   r   rH   r   r   r   r^   r   r   r   r     sZ     # #&0,0 (0 !	0
 
0r   r   c                .    t         j                  d|       S )Nrf   )_ansi_resub)rv   s    r   
strip_ansir     s    <<E""r   c                    t        | t        t        f      r#| j                  } t        | t        t        f      r#| j                  j
                  j                  d      S )Nz
ipykernel.)ra   r(   r   r)   r.   r?   
startswithrr   s    r   _is_jupyter_kernel_outputr     sL    
Vl,DE
F Vl,DE
F &&11,??r   c                    |:| t         j                  } nt        | d      ryt        |        xr t	        |        S | S )NcolorF)r   r   hasattrr5   r   )r   r   s     r   should_strip_ansir     sI     }>YYFVW% &>!K*CF*K&KK9r      )r   c                 *    dd l } | j                         S r`   )localegetpreferredencoding)r  s    r   _get_argv_encodingr    s    **,,r   c                 d    t        t        j                  dd       xs t        j                         S )Nr   )r   r   r   getfilesystemencodingr^   r   r   r  r    s#    syy*d3Rs7P7P7RRr   c                     y r$   r^   )rN   r   r   s      r   r   r     s     r   c                *    t        t        |             S r$   )lenr   )rR   s    r   term_lenr    s    z!}r   c                B    	 | j                         S # t        $ r Y yw xY wr   )r5   r1   rr   s    r   r5   r5     s%    }} s    	c                0     t               d fd}|S )Nc                             } | y 	 j                  |       }||S         }	 || <   |S # t        $ r d }Y  w xY w# t        $ r Y |S w xY wr$   )getr1   )r   r!   cachesrc_funcwrapper_funcs     r   funcz&_make_cached_stream_func.<locals>.func)  s{    >	6"B >I^	E&M 	  	B	  			s   1 A ??	AA)r;   t.TextIO | Noner   )r  r  r  r  s   `` @r   _make_cached_stream_funcr  #  s     6G5HE& Kr   c                 "    t         j                  S r$   )r   r   r^   r   r   <lambda>r  ?  s    syyr   c                 "    t         j                  S r$   )r   r   r^   r   r   r  r  @      

r   c                 "    t         j                  S r$   )r   r   r^   r   r   r  r  A  r  r   )r   r   r   z-cabc.Mapping[str, t.Callable[[], t.BinaryIO]]binary_streamszAcabc.Mapping[str, t.Callable[[str | None, str | None], t.TextIO]]text_streamsr6   )r   r7   r   r8   r   r8   r   r9   r   r9   r;   t.TextIO)r   r[   r;   r9   )r   r   r;   r[   r   )r   r   rc   r9   r;   r9   )r   r   r;   zt.BinaryIO | None)r   r  r;   r9   )r   r  ru   r[   rv   r8   r;   r9   )r   r  r   r8   r   r8   r;   r9   )r}   r   r   r8   r   r8   r~   z%t.Callable[[t.IO[t.Any], bool], bool]r   z,t.Callable[[t.IO[t.Any]], t.BinaryIO | None]r   r9   r   r9   r;   r  )
r   r   r   r8   r   r8   r   r9   r;   r  )
r   r   r   r8   r   r8   r   r9   r;   r  )r;   r7   )NN)r   r8   r   r8   r;   r  )
r   zstr | os.PathLike[str] | intr   r[   r   r8   r   r8   r;   r   )rNstrictF)r   zstr | os.PathLike[str]r   r[   r   r8   r   r8   r   r9   r;   ztuple[t.IO[t.Any], bool])rv   r[   r;   r[   )r   r   r;   r9   )r   zt.IO[t.Any] | Noner   zbool | Noner;   r9   r   )rN   r  r   r8   r   r8   r;   r  )rR   r[   r;   r\   )r  t.Callable[[], t.TextIO | None]r  zt.Callable[[], t.TextIO]r;   r   )>
__future__r   r   collections.abcabccabcior   rer   typingr%   typesr   weakrefr   platformr   CYGWINWINcompiler   r   r   r   TextIOWrapperr   r(   rd   rg   rm   rp   rs   rx   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _winconsoler   r  r  r5   r  _default_text_stdin_default_text_stdout_default_text_stderrr  __annotations__r  r^   r   r   <module>r4     s   "   	 	 	 
   %		 	 	*	lle$
 2::01 !   	
  *%r// %4B BJ
$$KQ;; *;4>;	;" ! +++ + 5	+
 >+ + + +d !	  	
 ( !	  	
  XYY
>
&
>

> 
> 	
>
 
> !N)$N)
N) N) 	N)
 N) N)b! !H#@ =A.9	 <<5!c8-S)3=	-* %8 //@.Q /0BOT /0BOT  A=  SO r   