o
    $	h&#                  	   @  s  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 d d	lmZmZ d d
lmZ d dlmZ d dlmZmZ d dlm Z m!Z!m"Z" erwd dl#m$Z$ 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)e0f Z1eeeeeddee1f Z2dAddZ3dBddZ4edCd"d#Z5edDd%d#Z5dEd(d#Z5dFd-d.Z6	dGdHd2d3Z7d4d5dId:d;Z8dJd?d@Z9dS )K    )annotationsN)datedatetimetime	timedelta)TYPE_CHECKINGAnyLiteralUnionoverload)Message)	TypeAlias)config)current_form_id)StreamlitDuplicateElementIdStreamlitDuplicateElementKey)	ChatInput)LabelVisibilityMessage)ScriptRunContextget_script_run_ctx)GENERATED_ELEMENT_ID_PREFIXTESTING_KEYuser_key_from_element_id)ellipsis)Iterable)DeltaGeneratorr   Key)visiblehidden	collapsedLabelVisibilityr   label_visibility_stringreturn7LabelVisibilityMessage.LabelVisibilityOptions.ValueTypec                 C  s>   | 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)r!    r)   Y/var/www/html/mmpi2/mmpi_env/lib/python3.10/site-packages/streamlit/elements/lib/utils.py get_label_visibility_proto_valueE   s   r+   accept_file_value'Literal['multiple', 'directory'] | boolChatInput.AcceptFile.ValueTypec                 C  sN   | du rt jjS | du rt jjS | dkrt jjS | dkr t jjS td|  )zEReturns one of ChatInput.AcceptFile enum value based on string value.FTmultiple	directoryzUnknown accept file value: )r   
AcceptFileNONESINGLEMULTIPLE	DIRECTORYr(   )r,   r)   r)   r*   &get_chat_input_accept_file_proto_valueT   s   r6   keyNonec                 C     d S Nr)   r7   r)   r)   r*   to_keye      r<   strc                 C  r9   r:   r)   r;   r)   r)   r*   r<   i   r=   
Key | None
str | Nonec                 C  s   | d u rd S t | S r:   )r>   r;   r)   r)   r*   r<   m   s   ctxr   element_type
element_idc                 C  sV   |sdS t | }r|| jvr| j| nt||| jvr'| j| dS 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   )rA   rB   rC   user_keyr)   r)   r*   _register_element_idq   s   

rH   rG   kwargs#SAFE_VALUES | Iterable[SAFE_VALUES]c                 K  s   t jddd}|| d |r||d | D ]\}}|t|d |t|d qt d|  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.
    md5F)usedforsecurityzutf-8-)hashlibnewupdateencodeitemsr>   r   	hexdigest)rB   rG   rI   hkvr)   r)   r*   _compute_element_id   s   rW   F)key_as_main_identitydgDeltaGenerator | NonerX   boolc          	      K  sr   t  }|o|}|ri ni |}|r|j|d< |r&|s&t||d< |jj|d< t| |fi |}|r7t|| | |S )a  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.

    dg : DeltaGenerator | None
        The DeltaGenerator of each element. `None` if the element is not a widget.

    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

    key_as_main_identity : bool
        If True, if a key is provided by the user, we don't include
        command kwargs in the element ID computation.
    active_script_hashform_idactive_dg_root_container)r   r\   r   
_active_dg_root_containerrW   rH   )	rB   rG   rY   rX   rI   rA   ignore_command_kwargskwargs_to_userC   r)   r)   r*   compute_and_register_element_id   s   .
rc   rU   rV   r   c                 C  sF   t dr!z
|| jt |< W d S  ty    ||i| jt< Y d S w d S )Nzglobal.appTest)r   
get_optionsession_stater   KeyError)rA   rU   rV   r)   r)   r*   save_for_app_testing  s   
rg   )r!   r    r"   r#   )r,   r-   r"   r.   )r7   r8   r"   r8   )r7   r   r"   r>   )r7   r?   r"   r@   )rA   r   rB   r>   rC   r>   r"   r8   r:   )rB   r>   rG   r@   rI   rJ   r"   r>   )rB   r>   rG   r@   rY   rZ   rX   r[   rI   rJ   r"   r>   )rA   r   rU   r>   rV   r   r"   r8   ):
__future__r   rN   r   r   r   r   typingr   r   r	   r
   r   google.protobuf.messager   typing_extensionsr   	streamlitr   !streamlit.elements.lib.form_utilsr   streamlit.errorsr   r   streamlit.proto.ChatInput_pb2r   *streamlit.proto.LabelVisibilityMessage_pb2r   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   streamlit.runtime.state.commonr   r   r   builtinsr   collections.abcr   streamlit.delta_generatorr   r>   intr   __annotations__r    floatr[   bytesPROTO_SCALAR_VALUESAFE_VALUESr+   r6   r<   rH   rW   rc   rg   r)   r)   r)   r*   <module>   sX   



*%H