
    &e(!                        U d dl Z d dlZd dlZd dlmZmZ d dlmZmZm	Z	m
Z
mZmZ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 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$ee%d<   e	e&ee&         f         Z'ee%d<    ej(        d e)                      Z*ej(        ed                  e%d<   e G d d                      Z+dZ,ee%d<   	 ddeej-                 dee+         fdZ.dde/dee+         fdZ0d dlZdS )     N)	dataclassfield)CallableCounterDictListOptionalSetTuple)parse)Final	TypeAlias)runtime)StreamlitAPIException)
get_logger)
ForwardMsg)Command)ScriptRequests)SafeSessionState)UploadedFileManagerLOGGERUserInfodg_stack)default)z(streamlit.delta_generator.DeltaGenerator.c                   2   e Zd ZU dZeed<   eegdf         ed<   eed<   eed<   e	ed<   eed<   eed	<   e
ed
<   dZeed<   dZeed<    ee          Zee         ed<    eej                  Zee         ed<   dZeed<   dZeed<    ee          Zee         ed<    ee          Zee         ed<    ee          Zee         ed<    ee          Zee df         ed<   dZ!e"e#         ed<   dZ$dZ%d#ded	eddfdZ&d$dZ'deddfdZ(d  Z)d! Z*d" Z+dS )%ScriptRunContextaG  A context object that contains data for a "script run" - that is,
    data that's scoped to a single ScriptRunner execution (and therefore also
    scoped to a single connected "session").

    ScriptRunContext is used internally by virtually every `st.foo()` function.
    It is accessed only from the script thread that's created by ScriptRunner,
    or from app-created helper threads that have been "attached" to the
    ScriptRunContext via `add_script_run_ctx`.

    Streamlit code typically retrieves the active ScriptRunContext via the
    `get_script_run_ctx` function.
    
session_idN_enqueuequery_stringsession_stateuploaded_file_mgrmain_script_pathpage_script_hash	user_infoFgather_usage_statscommand_tracking_deactivated)default_factorytracked_commandstracked_commands_counterT_set_page_config_allowed_has_script_startedwidget_ids_this_runwidget_user_keys_this_runform_ids_this_runzstreamlit.cursor.RunningCursorcursorsscript_requests returnc                    i | _         t                      | _        t                      | _        t                      | _        || _        || _        d| _        d| _        d| _	        g | _
        t          j                    | _        t          j        |d          }| j                                        5 }|                                 |                                D ]w\  }}t)          |          dk    r|                    |d           0t)          |          dk    r|                    ||d                    a|                    ||           x	 d d d            d S # 1 swxY w Y   d S )	NTF)keep_blank_valuesr   r1   )val   )r/   setr,   r-   r.   r   r#   r*   r+   r&   r(   collectionsr   r)   r   parse_qsr    query_paramsclear_with_no_forward_msgitemslenset_with_no_forward_msg)selfr   r#   parsed_query_paramsqpkeyr5   s          Qlib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_run_context.pyresetzScriptRunContext.resetV   s   #&55 ),&!$( 0(,%#( 27) "(3(;(=(=%#n\TRRR,,.. 	9"((***/5577 9 9Ss88q==..s.;;;;XX]]..sB.@@@@..sC88889	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s   2B!E!!E%(E%c                     d| _         d S NT)r+   r@   s    rD   on_script_startz ScriptRunContext.on_script_starto   s    #'       msgc                     |                     d          r| j        st          d          |                     d          s|                     d          r| j        rd| _        |                     |           dS )z0Enqueue a ForwardMsg for this context's session.page_config_changedz`set_page_config()` can only be called once per app page, and must be called as the first Streamlit command in your script.

For more information refer to the [docs](https://docs.streamlit.io/library/api-reference/utilities/st.set_page_config).deltaFN)HasFieldr*   r   r+   r   )r@   rK   s     rD   enqueuezScriptRunContext.enqueuer   s    <<-.. 	t7T 	'd   <<-.. 	2LL!!	2&*&>	2 -2D) 	crJ   c                 D    | j         r| j        rt          d          d S d S )NzUsing `st.query_params` together with either `st.experimental_get_query_params` or `st.experimental_set_query_params` is not supported. Please convert your app to only use `st.query_params`)_experimental_query_params_used_production_query_params_usedr   rH   s    rD   ensure_single_query_api_usedz-ScriptRunContext.ensure_single_query_api_used   sB    / 	D4V 	'2  	 	 	 	rJ   c                 <    d| _         |                                  d S rG   )rR   rT   rH   s    rD   #mark_experimental_query_params_usedz4ScriptRunContext.mark_experimental_query_params_used   s"    /3,))+++++rJ   c                 <    d| _         |                                  d S rG   )rS   rT   rH   s    rD   !mark_production_query_params_usedz2ScriptRunContext.mark_production_query_params_used   s"    -1*))+++++rJ   )r1   r1   )r2   N),__name__
__module____qualname____doc__str__annotations__r   r   r   r   r   r%   boolr&   r   listr(   r   r   r9   r   r)   r*   r+   r8   r,   r
   r-   r.   dictr/   r   intr0   r	   r   rR   rS   rE   rI   rP   rT   rV   rX    rJ   rD   r   r   .   sY          OOO
|T)****####****$$$$). $...&+eD&A&A&Ad7mAAA-2U;CV-W-W-WgclWWW%)d))) %%%%$)E#$>$>$>S>>>*/%*D*D*Ds3xDDD"'%"<"<"<s3x<<<;@5QU;V;V;VGT#778VVV04OXn-444 ',#$)!9 9# 9c 94 9 9 9 92( ( ( (: $    *  , , ,, , , , ,rJ   r   streamlit_script_run_ctxSCRIPT_RUN_CONTEXT_ATTR_NAMEthreadctxc                     | t          j                    } |t                      }|t          | t          |           | S )a
  Adds the current ScriptRunContext to a newly-created thread.

    This should be called from this thread's parent thread,
    before the new thread starts.

    Parameters
    ----------
    thread : threading.Thread
        The thread to attach the current ScriptRunContext to.
    ctx : ScriptRunContext or None
        The ScriptRunContext to add, or None to use the current thread's
        ScriptRunContext.

    Returns
    -------
    threading.Thread
        The same thread that was passed in, for chaining.

    )	threadingcurrent_threadget_script_run_ctxsetattrre   )rf   rg   s     rD   add_script_run_ctxrm      sD    , ~)++
{ ""
4c:::MrJ   Fsuppress_warningr2   c                     t          j                    }t          |t          d          }|5t	          j                    r"| s t                              d|j                   |S )a  
    Parameters
    ----------
    suppress_warning : bool
        If True, don't log a warning if there's no ScriptRunContext.
    Returns
    -------
    ScriptRunContext | None
        The current thread's ScriptRunContext, or None if it doesn't have one.

    Nz%Thread '%s': missing ScriptRunContext)	ri   rj   getattrre   r   existsr   warningname)rn   rf   rg   s      rD   rk   rk      s_     %''F&-,d' 'C {w~''{0@{
 	>LLLJrJ   )NN)F)1r9   contextvarsri   dataclassesr   r   typingr   r   r   r   r	   r
   r   urllibr   typing_extensionsr   r   	streamlitr   streamlit.errorsr   streamlit.loggerr   streamlit.proto.ForwardMsg_pb2r   streamlit.proto.PageProfile_pb2r   .streamlit.runtime.scriptrunner.script_requestsr   streamlit.runtime.stater   'streamlit.runtime.uploaded_file_managerr   rY   r   r^   r]   r   
ContextVartupler   r   re   Threadrm   r_   rk   rc   rJ   rD   <module>r      s                ( ( ( ( ( ( ( ( F F F F F F F F F F F F F F F F F F       . . . . . . . .       2 2 2 2 2 2 ' ' ' ' ' ' 5 5 5 5 5 5 3 3 3 3 3 3 I I I I I I 4 4 4 4 4 4 G G G G G G
8$$ $ $ $3-.) . . . K:uuww777 	+
 	
9: 8 8 8
 f, f, f, f, f, f, f, f,R 'A e @ @ @ RV Y%&4<=M4N   >  (CS:T    6      rJ   