
    &e                         U d dl 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 d dlmZ d dlmZ d d	lmZ  e	j        e          Zeed
<   daeed<   defdZ G d deeef                   ZdedefdZdS )    )AnyDictIteratorMutableMapping)Final)logger)runtime)gather_metrics)require_valid_user_key)SafeSessionState)SessionState)KeyLOGGERF$_state_use_warning_already_displayedreturnc                      ddl m}   |             }|St          s/dat          j                    st
                              d           t          t                      d           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_ctxNTzMSession state does not function when running a script without `streamlit run`c                      d S N r       Klib/python3.11/site-packages/streamlit/runtime/state/session_state_proxy.py<lambda>z#get_session_state.<locals>.<lambda>6   s     r   )
streamlit.runtime.scriptrunnerr   r   r	   existsr   warningr   r   session_state)r   ctxs     r   get_session_stater   !   s     BAAAAA



C {3 	370>## c    ===r   c                   
   e Zd ZdZdee         fdZdefdZde	fdZ
dedefdZ ed          ded	edd
fd            Zdedd
fdZde	defdZ ed          de	d	edd
fd            Zde	dd
fdZdee	ef         f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   c                 B    t          t                      j                  S )z1Iterator over user state and keyed widget values.)iterr   filtered_stateselfs    r   __iter__zSessionStateProxy.__iter__C   s     %''6777r   c                 B    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__H       $&&5666r   c                 B    t          t                      j                  S )z<String representation of user state and keyed widget values.)strr   r$   r%   s    r   __str__zSessionStateProxy.__str__L   r+   r   keyc                 f    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&   r/   s     r   __getitem__zSessionStateProxy.__getitem__P   s.     #hhs### ""3''r   zsession_state.set_itemvalueNc                 d    t          |          }t          |           |t                      |<   dS )zSet the value of the given key.

        Raises
        ------
        StreamlitAPIException
            If the key is not a valid SessionState user key.
        Nr1   r&   r/   r4   s      r   __setitem__zSessionStateProxy.__setitem__\   s4     #hhs####(C   r   c                 `    t          |          }t          |           t                      |= dS )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__i   s1     #hhs###$$$r   c                 h    	 | |         S # t           $ r t          t          |                    w xY wr   KeyErrorAttributeError_missing_attr_error_messager2   s     r   __getattr__zSessionStateProxy.__getattr__u   sH    	C9 	C 	C 	C !<S!A!ABBB	Cs   
 '1zsession_state.set_attrc                     || |<   d S r   r   r6   s      r   __setattr__zSessionStateProxy.__setattr__{   s    S			r   c                 b    	 | |= d S # t           $ r t          t          |                    w xY wr   r;   r2   s     r   __delattr__zSessionStateProxy.__delattr__   sI    	CS			 	C 	C 	C !<S!A!AB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1r   )__name__
__module____qualname____doc__r   r   r'   intr*   r-   r.   r   r3   r
   r7   r9   r?   rA   rC   r   rE   r   r   r   r!   r!   :   s        8(3- 8 8 8 8
7 7 7 7 77 7 7 7 7
(s 
(s 
( 
( 
( 
( ^,--
)s 
)3 
)4 
) 
) 
) .-
)
%s 
%t 
% 
% 
% 
%Cs Cs C C C C ^,--s 3 4    .-Cs Ct C C C C2c3h 2 2 2 2 2 2r   r!   	attr_namec                     d|  dS )Nz#st.session_state has no attribute "z". Did you forget to initialize it? More info: https://docs.streamlit.io/library/advanced-features/session-state#initializationr   )rK   s    r   r>   r>      s!    	gi 	g 	g 	gr   N)typingr   r   r   r   typing_extensionsr   	streamlitr   _loggerr	   streamlit.runtime.metrics_utilr
   streamlit.runtime.state.commonr   *streamlit.runtime.state.safe_session_stater   %streamlit.runtime.state.session_stater   streamlit.type_utilr   
get_loggerrF   r   __annotations__r   boolr   r!   r-   r>   r   r   r   <module>rY      sr   7 6 6 6 6 6 6 6 6 6 6 6 6 # # # # # # ' ' ' ' ' '       9 9 9 9 9 9 A A A A A A G G G G G G > > > > > > # # # # # #""8,, , , , .3 $d 2 2 2+    2M2 M2 M2 M2 M2sCx0 M2 M2 M2`3 3      r   