
    g              	         U d dl mZ d dlZd dlmZmZmZmZ d dlmZm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d d	lmZ d d
lmZmZ d dlmZmZmZ d dlm Z  erd dl!m"Z" d dl#m$Z$ ee%e&f   Z'de(d<   e
d   Z)de(d<   ee*e&e+e%e,f   Z-eeeeeddee-f   Z.	 	 	 	 ddZ/edd       Z0edd       Z0ddZ0	 	 	 	 	 	 	 	 d dZ1	 d!	 	 	 	 	 	 	 d"dZ2	 	 	 	 	 	 	 	 	 	 d#dZ3d$dZ4y)%    )annotationsN)datedatetimetime	timedelta)TYPE_CHECKINGAnyLiteralUnionoverload)Message)	TypeAlias)config)StreamlitDuplicateElementIdStreamlitDuplicateElementKey)LabelVisibilityMessage)ScriptRunContextget_script_run_ctx)GENERATED_ELEMENT_ID_PREFIXTESTING_KEYuser_key_from_element_id)HASHLIB_KWARGS)ellipsis)Iterabler   Key)visiblehidden	collapsedLabelVisibilityr   c                    | dk(  rt         j                  j                  S | dk(  rt         j                  j                  S | dk(  rt         j                  j                  S t        d|        )zNReturns one of LabelVisibilityMessage enum constants.py based on string value.r   r   r   z Unknown label visibility value: )r   LabelVisibilityOptionsVISIBLEHIDDEN	COLLAPSED
ValueError)label_visibility_strings    Q/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/lib/utils.py get_label_visibility_proto_valuer(   B   sg    
 )+%<<DDD	 H	,%<<CCC	 K	/%<<FFF
78O7PQ
RR    c                     y N keys    r'   to_keyr/   Q   s    "r)   c                     y r+   r,   r-   s    r'   r/   r/   U   s     r)   c                     | d S t        |       S r+   )strr-   s    r'   r/   r/   Y   s    ;4,CH,r)   c                    |syt        |      x}r5|| j                  vr| j                  j                  |       nt        |      || j                  vr| j                  j                  |       yt        |      )a  Register the element ID and key for the given element.

    If the element ID or key is not unique, an error is raised.

    Parameters
    ----------

    element_type : str
        The type of the element to register.

    element_id : str
        The ID of the element to register.

    Raises
    ------

    StreamlitDuplicateElementKey
        If the element key is not unique.

    StreamlitDuplicateElementID
        If the element ID is not unique.

    N)r   widget_user_keys_this_runaddr   widget_ids_this_runr   )ctxelement_type
element_iduser_keys       r'   _register_element_idr;   ]   st    6 +J77x73888))--h7.x88000##J/),77r)   c                   t        j                  di t        }|j                  | j	                  d             |r |j                  |j	                  d             |j                         D ]W  \  }}|j                  t        |      j	                  d             |j                  t        |      j	                  d             Y t         d|j                          d| S )aK  Compute the ID for the given element.

    This ID is stable: a given set of inputs to this function will always produce
    the same ID output. Only stable, deterministic values should be used to compute
    element IDs. Using nondeterministic values as inputs can cause the resulting
    element ID to change between runs.

    The element ID includes the user_key so elements with identical arguments can
    use it to be distinct. The element ID includes an easily identified prefix, and the
    user_key as a suffix, to make it easy to identify it and know if a key maps to it.
    zutf-8-)md5)	hashlibnewr   updateencodeitemsr2   r   	hexdigest)r8   r:   kwargshkvs         r'   _compute_element_idrI      s      	,^,AHH\  )*
 	
)* 1	Qw'(	Qw'(  **!AKKM?!H:FFr)   c                   t               }|rd|i|n|}|r|j                  |d<   t        | |fi |}|rt        || |       |S )a4  Compute and register the ID for the given element.

    This ID is stable: a given set of inputs to this function will always produce
    the same ID output. Only stable, deterministic values should be used to compute
    element IDs. Using nondeterministic values as inputs can cause the resulting
    element ID to change between runs.

    The element ID includes the user_key so elements with identical arguments can
    use it to be distinct. The element ID includes an easily identified prefix, and the
    user_key as a suffix, to make it easy to identify it and know if a key maps to it.

    The element ID gets registered to make sure that only one ID and user-specified
    key exists at the same time. If there are duplicated IDs or keys, an error
    is raised.

    Parameters
    ----------
    element_type : str
        The type (command name) of the element to register.

    user_key : str | None
        The user-specified key for the element. `None` if no key is provided
        or if the element doesn't support a specifying a key.

    form_id : str | None
        The ID of the form that the element belongs to. `None` or empty string
        if the element doesn't belong to a form or doesn't support forms.

    kwargs : SAFE_VALUES | Iterable[SAFE_VALUES]
        The arguments to use to compute the element ID.
        The arguments must be stable, deterministic values.
        Some common parameters like key, disabled,
        format_func, label_visibility, args, kwargs, on_change, and
        the active_script_hash are not supposed to be added here
    form_idactive_script_hash)r   rL   rI   r;   )r8   r:   rK   rE   r7   kwargs_to_user9   s          r'   compute_and_register_element_idrN      si    T 
C 7>Y2626M
 /2.D.D*+$ J S,
;r)   c                    t        j                  d      r	 || j                  t           |<   y y # t        $ r ||i| j                  t        <   Y y w xY w)Nzglobal.appTest)r   
get_optionsession_stater   KeyError)r7   rG   rH   s      r'   save_for_app_testingrS      sU    )*	401Ck*1- +  	4./VCk*	4s   / AA)r&   r   returnz7LabelVisibilityMessage.LabelVisibilityOptions.ValueType)r.   NonerT   rU   )r.   r   rT   r2   )r.   z
Key | NonerT   
str | None)r7   r   r8   r2   r9   r2   rT   rU   r+   )r8   r2   r:   rV   rE   #SAFE_VALUES | Iterable[SAFE_VALUES]rT   r2   )
r8   r2   r:   rV   rK   rV   rE   rW   rT   r2   )r7   r   rG   r2   rH   r	   )5
__future__r   r?   r   r   r   r   typingr   r	   r
   r   r   google.protobuf.messager   typing_extensionsr   	streamlitr   streamlit.errorsr   r   *streamlit.proto.LabelVisibilityMessage_pb2r   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   streamlit.runtime.state.commonr   r   r   streamlit.utilr   builtinsr   collections.abcr   r2   intr   __annotations__r   floatboolbytesPROTO_SCALAR_VALUESAFE_VALUESr(   r/   r;   rI   rN   rS   r,   r)   r'   <module>rk      s~   #  4 4  , '  V M 
 *!( sCxY  $%EF F5#tS%78 	S,S<S 
 " 
 " 
   
  -'8	'8),'8:='8	'8X  GGG 2G 		G@<< < 	<
 2< 	<~4r)   