
    #jI                       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k(  ZdZded	<    ej.                  d
      Z	 	 d<	 	 	 	 	 	 	 	 	 	 	 d=dZd>dZd?dZ G d dej8                        Z G d d      Zd@dAdZd@dAdZ dBdZ!dBdZ"dCdZ#dDdZ$	 	 	 	 	 	 	 	 dEdZ%	 	 d<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dFdZ&	 d@	 	 	 	 	 	 	 	 	 dGdZ'	 d@	 	 	 	 	 	 	 	 	 dHdZ(dIdZ)dIdZ*dIdZ+dJdKdZ,dJdKd Z-dJdKd!Z.	 	 	 	 	 	 	 	 	 	 dLd"Z/	 	 	 	 dM	 	 	 	 	 	 	 	 	 	 	 dNd#Z0 G d$ d%      Z1dOd&Z2dPd'Z3	 dJ	 	 	 	 	 dQd(Z4e	j                   j#                  d      rerd)d*l5m6Z6 dRd+Z7 e       Z8d,ed-<   dSdTd.ZndRd/Z7	 	 	 	 	 	 	 	 dUd0Z6dVd1Z9dPd2Z:	 	 	 	 	 	 dWd3Z; e;d4 e,      Z< e;d5 e-      Z= e;d6 e.      Z>e)e*e+d7Z?d8ed9<   e,e-e.d7Z@d:ed;<   y)X    )annotationsN)TracebackTypeWeakKeyDictionarycygwinwindarwinz't.Callable[[t.TextIO], t.TextIO] | Noneauto_wrap_for_ansiz\033\[[;?0-9]*[a-zA-Z]c                F    |t        |       }|d}t        | ||d||      S )NreplaceT)line_bufferingforce_readableforce_writable)get_best_encoding_NonClosingTextIOWrapper)streamencodingerrorsr   r   s        c/home/mi/.openclaw/workspace/fridge-app/backend/.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   1   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__H   s"    	KKM 		s    	c                6    | j                   j                         S r&   )r+   isattyr4   s    r   r7   z_NonClosingTextIOWrapper.isattyN   s    ||""$$r   FF)r   
t.BinaryIOr   
str | Noner   r:   r   boolr   r;   r/   t.AnyreturnNone)r=   r>   r=   r;   )__name__
__module____qualname__r-   r5   r7   __classcell__)r0   s   @r   r   r   9   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__g   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   rL   z_FixupStream.read1j   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)rF   r    r+   r'   r(   r;   rN   r3   r.   xs     r   rR   z_FixupStream.readabler   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)rG   r    r+   r'   r(   r;   writer3   rS   s     r   rV   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(   r;   seektellr3   rS   s     r   rY   z_FixupStream.seekable   si    DLL*d3=66$$$	LLdll//12   		s   3A. .	A:9A:Nr8   )r   r9   r   r;   r   r;   r   strr=   r<   )rO   intr=   rM   r?   )
r@   rA   rB   __doc__r-   rJ   rL   rR   rV   rY    r   r   r*   r*   S   sI      %$	.. . 	.+'
r   r*   c                d    	 t        | j                  d      t              S # t        $ r |cY S w xY wNr   )
isinstancerN   rM   r3   r   defaults     r   _is_binary_readerrf      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)rW   r3   rd   s     r   _is_binary_writerri      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)rf   r'   r(   r)   r    r   bufs     r   _find_binary_readerro      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 rk   )ri   r'   r(   r)   r    rm   s     r   _find_binary_writerrr      rp   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_misconfiguredru      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_attrrz      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   )rz   )r   r   r   s      r   _is_compatible_text_streamr|      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)   TextIOr|   ru   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   rf   ro   )text_readerr   r   r   s       r   _force_correct_text_readerr     #     &% r   c                4    t        | ||t        t        |      S )Nr   )r   ri   rr   )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.)ro   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.)rr   r!   stdoutr   writers    r   get_binary_stdoutr   D  &     ,F~TUUMr   c                 R    t        t        j                        } | t        d      | S )Nz7Was not able to determine binary stream for sys.stderr.)rr   r!   stderrr   r   s    r   get_binary_stderrr   K  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   R  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   Y  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   `  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   g  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     2QqDy2s   )warT   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.rT   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erP   afs    `             r   open_streamr   t  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.   rP   r   real_filenames       r   r-   z_AtomicFile.__init__  s     )+r   c                    | j                   S r&   )r   r4   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   rI   s     r   rJ   z_AtomicFile.__getattr__  s    tww%%r   c                    | S r&   r`   r4   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   r4   s    r   __repr__z_AtomicFile.__repr__  s    DGG}r   N)rP   t.IO[t.Any]r   r]   r   r]   r=   r>   r=   r]   F)r   r;   r=   r>   r\   )r=   r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner=   r>   )r@   rA   rB   r-   propertyr   r   rJ   r   r   r   r`   r   r   r   r     sZ     # #&0,0 (0 !	0
 
0r   r   c                .    t         j                  d|       S )Nrh   )_ansi_resub)rx   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.)rc   r*   r   r+   r0   rA   
startswithrt   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   hasattrr7   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 rb   )localegetpreferredencoding)r  s    r   _get_argv_encodingr    s    **,,r   z'cabc.MutableMapping[t.TextIO, t.TextIO]_ansi_stream_wrappersc                j   	 t         j                  |       }||S ddl}t	        | |      }|j                  | |      t        j                  t        j                  j                        }|j                  dfd}||_
        	 |t         | <   |S # t        $ r d}Y w xY w# t        $ r Y |S w xY w)zbSupport ANSI color and style codes on Windows by wrapping a
        stream with colorama.
        Nr   )stripc                R    	  |       S # t         $ r j                           w xY wr&   )BaseException	reset_all)s_writeansi_wrappers    r   _safe_writez'auto_wrap_for_ansi.<locals>._safe_write"  s0    ay   &&(s    &)r  r]   r=   r^   )r  getr3   coloramar  AnsiToWin32r'   r(   r~   r   rW   )	r   r   cachedr  r
  r#   r  r  r  s	          @@r   r
   r
     s    	*..v6F M!&%0++F%+@VVAHHl112	 	,.!&) 	7  	F	0  			s#   B 		B% B"!B"%	B21B2c                 d    t        t        j                  dd       xs t        j                         S )Nr   )r    r!   r   getfilesystemencodingr`   r   r   r  r  4  s#    syy*d3Rs7P7P7RRr   c                     y r&   r`   )rP   r   r   s      r   r   r   7  s     r   c                *    t        t        |             S r&   )lenr   )rT   s    r   term_lenr  =  s    z!}r   c                B    	 | j                         S # t        $ r Y yw xY wr   )r7   r3   rt   s    r   r7   r7   A  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&   )r  r3   )r   r#   cachesrc_funcwrapper_funcs     r   funcz&_make_cached_stream_func.<locals>.funcN  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$  H  s     6G5HE& Kr   c                 "    t         j                  S r&   )r!   r   r`   r   r   <lambda>r&  d  s
    syy r   c                 "    t         j                  S r&   )r!   r   r`   r   r   r&  r&  e  
    

 r   c                 "    t         j                  S r&   )r!   r   r`   r   r   r&  r&  f  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_streamsr8   )r   r9   r   r:   r   r:   r   r;   r   r;   r=   t.TextIO)r   r]   r=   r;   )r   r   r=   r]   r   )r   r   re   r;   r=   r;   )r   r   r=   zt.BinaryIO | None)r   r,  r=   r;   )r   r,  rw   r]   rx   r:   r=   r;   )r   r,  r   r:   r   r:   r=   r;   )r   r   r   r:   r   r:   r   z%t.Callable[[t.IO[t.Any], bool], bool]r   z,t.Callable[[t.IO[t.Any]], t.BinaryIO | None]r   r;   r   r;   r=   r,  )
r   r   r   r:   r   r:   r   r;   r=   r,  )
r   r   r   r:   r   r:   r   r;   r=   r,  )r=   r9   )NN)r   r:   r   r:   r=   r,  )
r   zstr | os.PathLike[str] | intr   r]   r   r:   r   r:   r=   r   )rNstrictF)r   zstr | os.PathLike[str]r   r]   r   r:   r   r:   r   r;   r=   ztuple[t.IO[t.Any], bool])rx   r]   r=   r]   )r   r   r=   r;   )r   zt.IO[t.Any] | Noner   bool | Noner=   r;   r   r&   )r   r,  r   r/  r=   r,  )rP   r,  r   r:   r   r:   r=   r#  )rT   r]   r=   r^   )r   t.Callable[[], t.TextIO | None]r!  zt.Callable[[], t.TextIO]r=   r0  )A
__future__r   r   collections.abcabccabcior   rer!   typingr'   typesr   weakrefr   platformr   CYGWINWINMACr
   __annotations__compiler   r   r   r   TextIOWrapperr   r*   rf   ri   ro   rr   ru   rz   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  _winconsoler   r  r  r  r7   r$  _default_text_stdin_default_text_stdout_default_text_stderrr*  r+  r`   r   r   <module>rE     s   "   	 	 	 
   %		 	 	*	lle$	llh>B ; B2::/0 !   	
  *%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-
 FWEXBX!JS)3=	-* %8 //@.Q /0BOT /0BOT  A=  SO r   