
    g                        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
j,                  e      Zded<   daded<   daded<   ddZ G d deeef         ZddZy)    )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_statec                     ddl m}   |        }|Rt        s+dat        j                         st
        j                  d       t        t        t               d       at        S |j                  S )zGet 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_ctxTzMSession state does not function when running a script without `streamlit run`c                      y N r       `/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/state/session_state_proxy.py<lambda>z#get_session_state.<locals>.<lambda>@   s    4r   )7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   r	   existsr   warningr   r   r   session_state)r   ctxs     r   get_session_stater    $   sc     
C {3370>>#c &"2<><"P""r   c                      e Zd ZdZddZddZddZddZ ed      dd       Z	ddZ
dd	Z ed
      dd       ZddZddZy)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).
    c                <    t        t               j                        S )z1Iterator over user state and keyed widget values.)iterr    filtered_stateselfs    r   __iter__zSessionStateProxy.__iter__N   s     %'6677r   c                <    t        t               j                        S )z>Number of user state and keyed widget values in session_state.)lenr    r%   r&   s    r   __len__zSessionStateProxy.__len__S       $&5566r   c                <    t        t               j                        S )z<String representation of user state and keyed widget values.)strr    r%   r&   s    r   __str__zSessionStateProxy.__str__W   r,   r   c                H    t        |      }t        |       t               |   S )zReturn 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'   keys     r   __getitem__zSessionStateProxy.__getitem__[   s#     #hs# "3''r   zsession_state.set_itemc                J    t        |      }t        |       |t               |<   y)zSet the value of the given key.

        Raises
        ------
        StreamlitAPIException
            If the key is not a valid SessionState user key.
        Nr1   r'   r3   values      r   __setitem__zSessionStateProxy.__setitem__g   s#     #hs##(C r   c                F    t        |      }t        |       t               |= y)zDelete the value with the given key.

        Raises
        ------
        StreamlitAPIException
            If the key is not a valid SessionState user key.
        Nr1   r2   s     r   __delitem__zSessionStateProxy.__delitem__t   s      #hs#$r   c                P    	 | |   S # t         $ r t        t        |            w xY wr   KeyErrorAttributeError_missing_attr_error_messager2   s     r   __getattr__zSessionStateProxy.__getattr__   s4    	C9 	C !<S!ABB	Cs    %zsession_state.set_attrc                    || |<   y r   r   r6   s      r   __setattr__zSessionStateProxy.__setattr__   s    S	r   c                N    	 | |= y # t         $ r t        t        |            w xY wr   r<   r2   s     r   __delattr__zSessionStateProxy.__delattr__   s1    	CS	 	C !<S!ABB	Cs    $c                *    t               j                  S )zCReturn a dict containing all session_state and keyed widget values.)r    r%   r&   s    r   to_dictzSessionStateProxy.to_dict   s     "111r   N)returnzIterator[Any])rG   int)rG   r.   )r3   r
   rG   r   )r3   r
   r7   r   rG   None)r3   r
   rG   rI   )r3   r.   rG   r   )r3   r.   r7   r   rG   rI   )r3   r.   rG   rI   )rG   zdict[str, Any])__name__
__module____qualname____doc__r(   r+   r/   r4   r   r8   r:   r@   rB   rD   rF   r   r   r   r"   r"   E   se    8
77
( ,-
) .
)
%C ,- .C2r   r"   c                    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   )	attr_names    r   r?   r?      s    
-i[ 9j 	kr   )rG   r   )rO   r.   rG   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_loggerrJ   r   __annotations__r   r   r    r"   r?   r   r   r   <module>r\      sx    # 4  '  , 9 A G >###H- - .3 $d 2/3 , 3BM2sCx0 M2`r   