o
    [hi^                     @   s  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 ejd  dkZej	
dZej	
do1dejv Zdejv o?dejd	d
v Zej	
doKe oKe ZdZedZdd Z	d{ddZdd Zdd ZG dd dejZG dd deZereZeZe efZ!e"e#fZ$dd Z%e&Z'dd Z(edZ)dd  Z*zd dl+Z+W n	 e,y   Y nw d!d  Z*zd dl-Z-W n	 e,y   Y nw d"d  Z*d#d$ Z.d%d& Z/d'd( Z0d)d* Z1d|d+d,Z2d|d-d.Z3d|d/d0Z4d1d2 Z5njd dlZe Ze6Ze fZ!e"fZ$e7Z'd3d Z.d4d Z%d5d Z(d}d6d7Z8d}d8d9Z9d:d; Z:d<d= Z;d>d? Z<d@dA Z=dBdC Z>		d{dDdEZ?d}dFdGZ@d}dHdIZAdJd& Z/dKd( Z0dLd* Z1d|dMd,Z2d|dNd.Z3d|dOd0Z4dPd2 Z5d~dQdRZBdSdT ZCddWdXZDeEedYrgejFZGdZZHnejIZGe ZHG d[d\ d\eZJdZKdZLdZMd]d^ ZNd_d` ZOd|dadbZPerdcZdddelQmRZRmSZS dfdg ZTerddhdiZzd dlLZLW n
 e,y   Y nw e ZUd~djdkZKdldm ZMndndg ZTdod ZRdpd ZSdqdr ZVdsdt ZWdudv ZXeXdwd e2ZYeXdxd e3ZZeXdyd e4Z[e/e0e1dzZ\e2e3e4dzZ]dS )    NWeakKeyDictionary   cygwinwinZGCCAPPENGINE_RUNTIMEzDevelopment/SERVER_SOFTWARE P   z\033\[[;?0-9]*[a-zA-Z]c                   C   s   t  pt  S N)sysgetfilesystemencodinggetdefaultencoding r   r   t/home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/venv/lib/python3.10/site-packages/click/_compat.pyget_filesystem_encoding      r   Fc                 C   s0   |d u rt | }|d u rd}t| ||d||dS )NreplaceT)line_bufferingforce_readableforce_writable)get_best_encoding_NonClosingTextIOWrapper)streamencodingerrorsr   r   r   r   r   _make_text_stream   s   r   c                 C   s(   z	t | jdkW S  ty   Y dS w )z$Checks if a given encoding is ascii.asciiF)codecslookupnameLookupError)r   r   r   r   is_ascii_encoding,   s
   r"   c                 C   s$   t | ddp	t }t|rdS |S )z1Returns the default stream encoding if not found.r   Nutf-8)getattrr   r   r"   r   rvr   r   r   r   4   s   r   c                   @   s>   e Zd Z		dddZerdd Zdd Zdd	 Zd
d ZdS )r   Fc                 K   s0   t ||| | _}tjj| |||fi | d S r   )_FixupStream_streamioTextIOWrapper__init__)selfr   r   r   r   r   extrar   r   r   r+   =   s   	z!_NonClosingTextIOWrapper.__init__c                 C   sP   t |ts	t|r!z|   W n	 ty   Y nw | jt|S tj| |S r   )	
isinstancestris_bytesflush	Exceptionbufferwriter)   r*   r,   xr   r   r   r4   N   s   z_NonClosingTextIOWrapper.writec                 C   s   |D ]}|  | qd S r   )r4   )r,   linesliner   r   r   
writelinesW   s   z#_NonClosingTextIOWrapper.writelinesc                 C   s$   z|    W d S  ty   Y d S w r   )detachr2   r,   r   r   r   __del__[   s
   z _NonClosingTextIOWrapper.__del__c                 C   s
   | j  S r   )r(   isattyr;   r   r   r   r=   a   s   
z_NonClosingTextIOWrapper.isattyNFF)	__name__
__module____qualname__r+   PY2r4   r9   r<   r=   r   r   r   r   r   <   s    
	r   c                   @   sB   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	dS )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).
    Fc                 C   s   || _ || _|| _d S r   )r(   _force_readable_force_writable)r,   r   r   r   r   r   r   r+   p   s   
z_FixupStream.__init__c                 C      t | j|S r   )r$   r(   r,   r    r   r   r   __getattr__u      z_FixupStream.__getattr__c                 C   s:   t | jdd }|d ur||S tr| j|S | j|S )Nread1)r$   r(   rB   readlineread)r,   sizefr   r   r   rI   x   s   z_FixupStream.read1c                 C   sN   | j rdS t| jdd }|d ur| S z	| jd W dS  ty&   Y dS w )NTreadabler   F)rC   r$   r(   rK   r2   r5   r   r   r   rN      s   z_FixupStream.readablec                 C   st   | j rdS t| jdd }|d ur| S z	| jd W dS  ty9   z
| jd W Y dS  ty8   Y Y dS w w )NTwritabler	       F)rD   r$   r(   r4   r2   r5   r   r   r   rO      s    z_FixupStream.writablec                 C   sJ   t | jdd }|d ur| S z| j| j  W dS  ty$   Y dS w )NseekableFT)r$   r(   seektellr2   r5   r   r   r   rQ      s   z_FixupStream.seekableNr>   )
r?   r@   rA   __doc__r+   rG   rI   rN   rO   rQ   r   r   r   r   r'   f   s    
	r'   c                 C      |   S r   )	iteritemsr6   r   r   r   <lambda>       rX   c                 C   s   t | ttfS r   )r.   r3   	bytearrayrW   r   r   r   r0         r0   z^[a-zA-Z_][a-zA-Z0-9_]*$c                 C      | S r   r   )rM   r   r   r   set_binary_mode      r]   c                 C   s4   z|   }W n
 ty   Y | S w t|tj | S r   )filenor2   msvcrtZsetmodeosO_BINARY)rM   r_   r   r   r   r]      s   c                 C   sL   z|   }W n
 ty   Y | S w t|tj}t|tj|tj @  | S r   )r_   r2   fcntlF_GETFLF_SETFLra   
O_NONBLOCK)rM   r_   flagsr   r   r   r]      s   c                 C   s   t | d uS r   )_identifier_researchrW   r   r   r   isidentifier   r[   rj   c                   C   s
   t tjS r   )r]   r   stdinr   r   r   r   get_binary_stdin      
rl   c                   C      t d ttjS )Nstdout)_wrap_std_streamr]   r   ro   r   r   r   r   get_binary_stdout      
rq   c                   C   rn   )Nstderr)rp   r]   r   rs   r   r   r   r   get_binary_stderr   rr   rt   c                 C   ,   t tj| |}|d ur|S ttj| |ddS NTr   )_get_windows_console_streamr   rk   r   r   r   r&   r   r   r   get_text_stdin   s   rz   c                 C   4   t d ttj| |}|d ur|S ttj| |ddS )Nro   Tr   )rp   rx   r   ro   r   ry   r   r   r   get_text_stdout   
   r}   c                 C   r{   )Nrs   Tr|   )rp   rx   r   rs   r   ry   r   r   r   get_text_stderr  r~   r   c                 C   s   t | tr| t d} | S )Nr   )r.   bytesdecoder   valuer   r   r   filename_to_ui  s   
r   c                 C   rU   r   )rj   rW   r   r   r   rX     rY   c                 C   s   t |  S r   )iteritemsrW   r   r   r   rX     s    c                 C   s   t | tttfS r   )r.   r   
memoryviewrZ   rW   r   r   r   r0     r   c                 C   s*   z	t | dtW S  ty   | Y S w Nr   )r.   rK   r   r2   r   defaultr   r   r   _is_binary_reader   s
   r   c                 C   sL   z|  d W dS  ty%   z	|  d W Y dS  ty$   Y | Y S w w )NrP   r	   FT)r4   r2   r   r   r   r   _is_binary_writer(  s   
r   c                 C   8   t | dr| S t| dd }|d urt |dr|S d S d S NFr3   T)r   r$   r   bufr   r   r   _find_binary_reader4     
r   c                 C   r   r   )r   r$   r   r   r   r   _find_binary_writerC  r   r   c                 C   s   t t| ddpdS )z3A stream is misconfigured if its encoding is ASCII.r   Nr   )r"   r$   r   r   r   r   _stream_is_misconfiguredR  s   r   c                 C   s$   t | |d}||kp|du o|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   attrr   Zstream_valuer   r   r   _is_compat_stream_attrZ  s   r   c                 C   s   t | d|ot | d|S )zkCheck if a stream's encoding and errors attributes are
        compatible with the desired values.
        r   r   )r   )r   r   r   r   r   r   _is_compatible_text_streamb  s
   
r   c                 C   sb   || dr| }nt | ||r|d u rt| s| S || }|d u r"| S |d u r(d}t|||||dS )NFr   )r   r   )r   r   r   )Ztext_streamr   r   Z	is_binaryZfind_binaryr   r   Zbinary_readerr   r   r   _force_correct_text_streamj  s"   
	r   c                 C      t | ||tt|dS )Nrw   )r   r   r   )Ztext_readerr   r   r   r   r   r   _force_correct_text_reader     r   c                 C   r   )Nr|   )r   r   r   )Ztext_writerr   r   r   r   r   r   _force_correct_text_writer  r   r   c                  C      t tj} | d u rtd| S )Nz6Was not able to determine binary stream for sys.stdin.)r   r   rk   RuntimeError)readerr   r   r   rl     s   
c                  C   r   )Nz7Was not able to determine binary stream for sys.stdout.)r   r   ro   r   writerr   r   r   rq        
c                  C   r   )Nz7Was not able to determine binary stream for sys.stderr.)r   r   rs   r   r   r   r   r   rt     r   c                 C   ru   rv   )rx   r   rk   r   ry   r   r   r   rz        
c                 C   ru   NTr|   )rx   r   ro   r   ry   r   r   r   r}     r   c                 C   ru   r   )rx   r   rs   r   ry   r   r   r   r     r   c                 C   s4   t | tr| t d} | S | dddd} | S )Nr   r#   surrogateescape)r.   r   r   r   encoder   r   r   r   r     s
   
c                 C   sB   t | dr	| j}n|d ur|}nt| }t|tr|dd}|S )Nstrerrorr#   r   )hasattrr   r/   r.   r   r   )er   msgr   r   r   get_streerror  s   

r   c              	   C   sb   d|v }|r	i }n||d}t r|rtj| |fi |S t| d|dd}t|fi |S )a+  On Python 2, :func:`io.open` returns a text file wrapper that
    requires passing ``unicode`` to ``write``. Need to open the file in
    binary mode then wrap it in a subclass that can write ``str`` and
    ``unicode``.

    Also handles not passing ``encoding`` and ``errors`` in binary mode.
    br   r   z{}btr	   )rB   r)   openformatr   r   )filemoder   r   binarykwargsrM   r   r   r   _wrap_io_open  s   
r   rstrictc              
      s  d v }| dkr1t  fdddD r"|rt dfS t||ddfS |r)t dfS t||ddfS |s<t|  ||dfS d	 v rDtd
d v rLtdd vrTtddd l}dd l}zt	
| j}W n tyo   d }Y nw t	jt	jB t	jB }	|r|	tt	ddO }		 t	jt	j| d|d}
zt	|
|	|d u rdn|}W n3 ty } z'|j|jkst	jdkr|j|jkrt	j|jrt	|jt	jrW Y d }~q d }~ww |d urt	|
| t| ||}t||
t	j | dfS )Nr   -c                 3   s    | ]}| v V  qd S r   r   ).0mr   r   r   	<genexpr>  s    zopen_stream.<locals>.<genexpr>)war6   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.r6   z&Use the `overwrite`-parameter instead.r   z,Atomic writes only make sense with `w`-mode.r   rb   z.__atomic-write{:08x}l        i  nt)!anyrq   r}   rl   rz   r   
ValueErrorerrnorandomra   statst_modeOSErrorO_RDWRO_CREATO_EXCLr$   pathjoindirnamer   	randranger   EEXISTr    EACCESisdirfilenameaccessW_OKchmod_AtomicFilerealpath)r   r   r   r   Zatomicr   r   r   permrg   tmp_filenamefdr   rM   r   r   r   open_stream  sj   




r   r   Tc                   @   sJ   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
dS )r   c                 C   s   || _ || _|| _d| _d S NF)_f_tmp_filename_real_filenameclosed)r,   rM   r   Zreal_filenamer   r   r   r+   T  s   
z_AtomicFile.__init__c                 C   s   | j S r   )r   r;   r   r   r   r    Z  s   z_AtomicFile.nameFc                 C   sT   | j rd S | j  tszt| j W n	 ty   Y nw t| j	| j d| _ d S )NT)
r   r   close_can_replacera   remover   r   _replacer   )r,   deleter   r   r   r   ^  s   

z_AtomicFile.closec                 C   rE   r   )r$   r   rF   r   r   r   rG   j  rH   z_AtomicFile.__getattr__c                 C   r\   r   r   r;   r   r   r   	__enter__m  r^   z_AtomicFile.__enter__c                 C   s   | j |d ud d S )N)r   )r   )r,   exc_type	exc_valuetbr   r   r   __exit__p     z_AtomicFile.__exit__c                 C   s
   t | jS r   )reprr   r;   r   r   r   __repr__s  rm   z_AtomicFile.__repr__NF)r?   r@   rA   r+   propertyr    r   rG   r   r   r   r   r   r   r   r   S  s    

r   c                 C   s   t d| S )Nr	   )_ansi_resubr   r   r   r   
strip_ansi|  rH   r   c                 C   s8   t rd S t| ttfr| j} t| ttfs| jjdS )Nz
ipykernel.)WINr.   r'   r   r(   	__class__r@   
startswithr   r   r   r   _is_jupyter_kernel_output  s   r   c                 C   s0   |d u r| d u rt j} t|  ot|  S | S r   )r   rk   r=   r   )r   colorr   r   r   should_strip_ansi  s
   r   O      )rx   rp   c                  C   s   dd l } |  S r   )localegetpreferredencoding)r   r   r   r   _get_argv_encoding  s   r   c                 C   s2   t j  | rt }||  t }| dS )Nz
)r   rs   r1   _default_text_stdoutr4   _default_text_stdinrJ   rstrip)promptro   rk   r   r   r   	raw_input  s   

r  c                    s   zt | }W n ty   d}Y nw |dur|S t| |}tj| |dj}|j  fdd}||_z|t | < W |S  tyF   Y |S w )a  This function wraps a stream so that calls through colorama
            are issued to the win32 console API to recolor on demand.  It
            also ensures to reset the colors if a write call is interrupted
            to not destroy the console afterwards.
            N)stripc                    s   z | W S        r   )Z	reset_all)s_writeZansi_wrapperr   r   _safe_write  s
   
z'auto_wrap_for_ansi.<locals>._safe_write)_ansi_stream_wrappersgetr2   r   coloramaZAnsiToWin32r   r4   )r   r   cachedr  r&   r  r   r  r   auto_wrap_for_ansi  s(   

r  c                  C   s*   t jt jjj} | j| j | j| j fS r   )	r
  win32ZGetConsoleScreenBufferInfoSTDOUTZsrWindowZRightZLeftZBottomZTop)r   r   r   r   get_winterm_size  s   r  c                   C   s   t tjdd p	t S )Nr   )r$   r   rk   r   r   r   r   r   r     r   c                  G      d S r   r   rW   r   r   r   rX         c                  G   r  r   r   rW   r   r   r   rX     r  c                 C   s   t t| S r   )lenr   rW   r   r   r   term_len  rH   r  c                 C   s    z|   W S  ty   Y dS w r   )r=   r2   r   r   r   r   r=     s
   
r=   c                    s   t    fdd}|S )Nc                     sh    } z  | }W n ty   d }Y nw |d ur|S  }z
 } | | < W |S  ty3   Y |S w r   )r	  r2   r%   cachesrc_funcwrapper_funcr   r   func  s"   
z&_make_cached_stream_func.<locals>.funcr   )r  r  r  r   r  r   _make_cached_stream_func  s   r  c                   C      t jS r   )r   rk   r   r   r   r   rX         c                   C   r  r   )r   ro   r   r   r   r   rX     r  c                   C   r  r   )r   rs   r   r   r   r   rX     r  )rk   ro   rs   r>   )NNr   r   )r   Nr   F)r	   )^r   r)   ra   rer   weakrefr   version_inforB   platformr   ZCYGWINversionZMSYS2environr	  Z
APP_ENGINEr   ZDEFAULT_COLUMNScompiler   r   r   r"   r   r*   r   objectr'   unicode	text_typer  r/   string_typesintlongZ	int_typesrV   xrangeZ
range_typer0   rh   r]   r`   ImportErrorrc   rj   rl   rq   rt   rz   r}   r   r   inputranger   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   renamer   r  r
  r  r   r   r   Z_winconsolerx   rp   r   r  r  r=   r  r   r   Z_default_text_stderrZbinary_streamsZtext_streamsr   r   r   r   <module>   s   

*C
	








*







J$



	
