
    %e                    d   U d 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	m
Z
mZmZmZmZmZmZmZ ddlmZ ddlmZ dZded	<   d
Zded<   ej        dk    rddini Zded<   d Zd Zd Zd Zd5dZ ed          Z d6d Z! ed!e""          Z#d7d&Z$ G d' d(e%          Z&d8d+Z'd9d/Z(d:d4Z)dS );zA bunch of useful utilities.    )annotationsN)AnyDictIterableListMappingSetTypeVarUnion)Final)env_utilzhttps://docs.streamlit.io/r   HELP_DOCgdy=zFinal[float]FLOAT_EQUALITY_EPSILON)   	   usedforsecurityFDict[str, Any]HASHLIB_KWARGSc                N     g t          j                    fd            }|S )z2Decorator to memoize the result of a no-args func.c                 R    s                                              d         S Nr   )append)funcresults   .lib/python3.11/site-packages/streamlit/util.pywrapped_funczmemoize.<locals>.wrapped_func.   s-     	"MM$$&&!!!ay    )	functoolswraps)r   r   r   s   ` @r   memoizer    *   sD    F_T     
 r   c                N   t           j        rt          |            dS t           j        r7t          j        d          rt          d|            dS t          |            dS t           j        rt          d|            dS ddl}t          d|	                                z            )a  Open a web browser pointing to a given URL.

    We use this function instead of Python's `webbrowser` module because this
    way we can capture stdout/stderr to avoid polluting the terminal with the
    browser's messages. For example, Chrome always prints things like "Created
    new window in existing browser session", and those get on the user's way.

    url : str
        The URL. Must include the protocol.

    Nzxdg-openopenr   z$Cannot open browser in platform "%s")
r   
IS_WINDOWS_open_browser_with_webbrowserIS_LINUX_OR_BSDis_executable_in_path_open_browser_with_command	IS_DARWINplatformErrorsystem)urlr)   s     r   open_browserr-   7   s    0  %c*** )*55 	&z3777F%c*** "63///OOO
69J9JJ
K
KKr   c                8    dd l }|                    |            d S r   )
webbrowserr"   )r,   r/   s     r   r$   r$   a   s&    OOCr   c                    | |g}t          t          j        d          5 }t          j        ||t          j                   d d d            d S # 1 swxY w Y   d S )Nw)stdoutstderr)r"   osdevnull
subprocessPopenSTDOUT)commandr,   cmd_liner5   s       r   r'   r'   g   s    ~H	bj#		 M''*:KLLLLM M M M M M M M M M M M M M M M M Ms   "AAAselfr   returnstrc                b     j         j        }dddg t                      t                      gt	          j                   r" fdt	          j                   D             }n%fd j                                        D             }d	                    d |D                       }| d| d	S )
zA clean repr for a class, excluding both values that are likely defaults,
    and those explicitly default for dataclasses.
    N Fc              3     K   | ]\}|j         rSt          |j                  |j        k    r5t          |j                  v>|j        t          |j                  fV  ]d S N)reprgetattrnamedefault).0fdefaultsr;   s     r   	<genexpr>zrepr_.<locals>.<genexpr>v   s       
 
v
 af%%22af%%X55	 VWT16**+ 6555
 
r   c              3  .   K   | ]\  }}|v	||fV  d S rA    )rF   rG   vrH   s      r   rI   zrepr_.<locals>.<genexpr>~   s5      WW&1aQhEVEV1vEVEVEVEVWWr   z, c              3  *   K   | ]\  }}| d |V  dS )=NrK   )rF   fieldvalues      r   rI   zrepr_.<locals>.<genexpr>   s4      QQ\UEu00u00QQQQQQr   ())
	__class____name__setdictdataclassesis_dataclassfields__dict__itemsjoin)r;   	classnamefields_valsfield_reprsrH   s   `   @r   repr_r`   m   s     'I  UBtvv>H%% 	X
 
 
 
 
 '--
 
 
 XWWWDM,?,?,A,AWWW))QQ[QQQQQK((+((((r   _ValueiterableIterable[_Value]xintc                0   t          |           D ]X\  }}||k    r|c S t          |t                    r4t          |t                    rt          ||z
            t          k     r|c S Yt          d                    t          |                              )a  Return zero-based index of the first item whose value is equal to x.
    Raises a ValueError if there is no such item.

    We need a custom implementation instead of the built-in list .index() to
    be compatible with NumPy array and Pandas Series.

    Parameters
    ----------
    iterable : list, tuple, numpy.ndarray, pandas.Series
    x : Any

    Returns
    -------
    int
    z{} is not in iterable)	enumerate
isinstancefloatabsr   
ValueErrorformatr=   )rb   rd   irP   s       r   index_rn      s      h''  5::HHHu%% 	*Q*>*> 	1u9~~ 666
,33CFF;;
<
<<r   _Key)boundrV   Mapping[_Key, _Value]Dict[str, _Value]c                >    d |                                  D             S )Nc                b    i | ],\  }}|                                                                 |-S rK   )lowerstrip)rF   krL   s      r   
<dictcomp>z)lower_clean_dict_keys.<locals>.<dictcomp>   s0    :::TQAGGIIOOq:::r   r[   )rV   s    r   lower_clean_dict_keysrz      s    ::TZZ\\::::r   c                      e Zd ZdS )r*   N)rT   
__module____qualname__rK   r   r   r*   r*      s        Dr   r*   sUnion[bytes, str]c                    t          j        di t          }t          | t                    r|                     d          n| }|                    |           |                                S )z(Return the md5 hash of the given string.md5zutf-8)r   )hashlibnewr   rh   r=   encodeupdate	hexdigest)r~   hbs      r   calc_md5r      sY    ,,^,,A'3//6QAHHQKKK;;==r   dkeys_to_exclude	List[str]c                D    fd|                                  D             S )z>Returns new object but without keys defined in keys_to_excludec                H    i | ]\  }}|                                 v||S rK   ru   )rF   keyrP   r   s      r   rx   z(exclude_keys_in_dict.<locals>.<dictcomp>   s8       !sE#))++_2T2TU2T2T2Tr   ry   )r   r   s    `r   exclude_keys_in_dictr      s6       %&WWYY   r   query_paramsDict[str, List[str]]	param_keySet[str]c                v     t          d  fd                                 D             D                       S )zWExtracts key (case-insensitive) query params from Dict, and returns them as Set of str.c                @    g | ]}|D ]}|                                 S rK   r   )rF   sublistitems      r   
<listcomp>z,extract_key_query_params.<locals>.<listcomp>   sI     	
 	
 	

  	
 	
  JJLL	
 	
 	
 	
r   c                    g | ]A}|                                 k                        |          /d  |         D             BS )c                6    g | ]}|                                 S rK   r   )rF   rP   s     r   r   z7extract_key_query_params.<locals>.<listcomp>.<listcomp>   s     >>>5>>>r   )ru   get)rF   r   r   r   s     r   r   z,extract_key_query_params.<locals>.<listcomp>   s\       99;;)++0@0@0E0E+ ?>L,=>>>+++r   )rU   keys)r   r   s   ``r   extract_key_query_paramsr      sh     	
 	
    ',,..  	
 	
 	

 
 
r   )r;   r   r<   r=   )rb   rc   rd   ra   r<   re   )rV   rq   r<   rr   )r~   r   r<   r=   )r   r   r   r   r<   r   )r   r   r   r=   r<   r   )*__doc__
__future__r   rW   r   r   r4   r6   systypingr   r   r   r   r   r	   r
   r   typing_extensionsr   	streamlitr   r   __annotations__r   version_infor   r    r-   r$   r'   r`   ra   rn   r=   ro   rz   	Exceptionr*   r   r   r   rK   r   r   <module>r      s2   # " " " " " " " "          				     



 J J J J J J J J J J J J J J J J J J J J # # # # # #       / . . . .'5  5 5 5 5
 #&"2f"<"<"     

 
 
'L 'L 'LT  M M M) ) ) ). 
		= = = =2 wvS!!!; ; ; ;
	 	 	 	 	I 	 	 	           r   