o
    ßñh¯  ã                   @  sÜ   U d dl mZ d dlmZmZ d dl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 d d	lmZ d d
lmZ e
 e¡Zded< daded< daded< ddd„ZG dd„ deeef ƒZddd„ZdS )é    )Úannotations)ÚIteratorÚMutableMapping)ÚAnyÚFinal)Úlogger)Úruntime)ÚKey)Úgather_metrics)Úrequire_valid_user_key)ÚSafeSessionState)ÚSessionStater   Ú_LOGGERFÚboolÚ$_state_use_warning_already_displayedNzSafeSessionState | NoneÚ_mock_session_stateÚreturnr   c                  C  sV   ddl m}  | ƒ }|du r(tsdat ¡ st d¡ tdu r&tt	ƒ dd„ ƒatS |j
S )zÚGet the SessionState object for the current session.

    Note that in streamlit scripts, this function should not be called
    directly. Instead, SessionState objects should be accessed via
    st.session_state.
    r   )Úget_script_run_ctxNTzMSession state does not function when running a script without `streamlit run`c                   S  s   d S ©N© r   r   r   ú_/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/runtime/state/session_state_proxy.pyÚ<lambda>@   s    z#get_session_state.<locals>.<lambda>)Ú7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   r   Úexistsr   Úwarningr   r   r   Úsession_state)r   Úctxr   r   r   Úget_session_state$   s   ÿr   c                   @  s„   e Zd ZdZd#dd„Zd$dd„Zd%d
d„Zd&dd„Zedƒd'dd„ƒZ	d(dd„Z
d)dd„Zedƒd*dd„ƒZd+dd„Zd,d d!„Zd"S )-ÚSessionStateProxya_  A stateless singleton that proxies `st.session_state` interactions
    to the current script thread's SessionState instance.

    The proxy API differs slightly from SessionState: it does not allow
    callers to get, set, or iterate over "keyless" widgets (that is, widgets
    that were created without a user_key, and have autogenerated keys).
    r   úIterator[Any]c                 C  ó   t tƒ jƒS )z1Iterator over user state and keyed widget values.)Úiterr   Úfiltered_state©Úselfr   r   r   Ú__iter__N   s   zSessionStateProxy.__iter__Úintc                 C  r    )z>Number of user state and keyed widget values in session_state.)Úlenr   r"   r#   r   r   r   Ú__len__S   ó   zSessionStateProxy.__len__Ústrc                 C  r    )z<String representation of user state and keyed widget values.)r*   r   r"   r#   r   r   r   Ú__str__W   r)   zSessionStateProxy.__str__Úkeyr	   r   c                 C  s   t |ƒ}t|ƒ tƒ | S )z·Return the state or widget value with the given key.

        Raises
        ------
        StreamlitAPIException
            If the key is not a valid SessionState user key.
        ©r*   r   r   ©r$   r,   r   r   r   Ú__getitem__[   s   
zSessionStateProxy.__getitem__zsession_state.set_itemÚvalueÚNonec                 C  s   t |ƒ}t|ƒ |tƒ |< dS )z¢Set the value of the given key.

        Raises
        ------
        StreamlitAPIException
            If the key is not a valid SessionState user key.
        Nr-   ©r$   r,   r0   r   r   r   Ú__setitem__g   s   	zSessionStateProxy.__setitem__c                 C  s   t |ƒ}t|ƒ tƒ |= dS )z§Delete the value with the given key.

        Raises
        ------
        StreamlitAPIException
            If the key is not a valid SessionState user key.
        Nr-   r.   r   r   r   Ú__delitem__t   s   zSessionStateProxy.__delitem__c                 C  s&   z| | W S  t y   tt|ƒƒ‚w r   ©ÚKeyErrorÚAttributeErrorÚ_missing_attr_error_messager.   r   r   r   Ú__getattr__€   s
   
ÿzSessionStateProxy.__getattr__zsession_state.set_attrc                 C  s   || |< d S r   r   r2   r   r   r   Ú__setattr__†   r)   zSessionStateProxy.__setattr__c                 C  s(   z| |= W d S  t y   tt|ƒƒ‚w r   r5   r.   r   r   r   Ú__delattr__Š   s
   ÿzSessionStateProxy.__delattr__údict[str, Any]c                 C  s   t ƒ jS )zCReturn a dict containing all session_state and keyed widget values.)r   r"   r#   r   r   r   Úto_dict   s   zSessionStateProxy.to_dictN)r   r   )r   r&   )r   r*   )r,   r	   r   r   )r,   r	   r0   r   r   r1   )r,   r	   r   r1   )r,   r*   r   r   )r,   r*   r0   r   r   r1   )r,   r*   r   r1   )r   r<   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r(   r+   r/   r
   r3   r4   r9   r:   r;   r=   r   r   r   r   r   E   s    






r   Ú	attr_namer*   c                 C  s   d| › dS )Nz#st.session_state has no attribute "zƒ". Did you forget to initialize it? More info: https://docs.streamlit.io/develop/concepts/architecture/session-state#initializationr   )rB   r   r   r   r8   •   s   
ÿr8   )r   r   )rB   r*   r   r*   )Ú
__future__r   Úcollections.abcr   r   Útypingr   r   Ú	streamlitr   Ú_loggerr   Ústreamlit.elements.lib.utilsr	   Ústreamlit.runtime.metrics_utilr
   Ústreamlit.runtime.state.commonr   Ú*streamlit.runtime.state.safe_session_stater   Ú%streamlit.runtime.state.session_stater   Ú
get_loggerr>   r   Ú__annotations__r   r   r   r   r8   r   r   r   r   Ú<module>   s    
!P