
    g                       U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 d dlmc 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 d d
lmZ 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'm(Z( d dl)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2 d dl3m4Z4 d dl5m6Z6 d dl7m8Z8 er,d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ d dlAmBZB d dlCmDZD d dlEmFZFmGZG  eeH      ZIdeJd<    G d d e      ZKd(d!ZL G d" d#      ZMd)d$ZNd*d%ZOd+d&ZPd,d'ZQy)-    )annotationsN)Enum)TYPE_CHECKINGCallableFinal)configruntime)
get_logger)ClientState)FileURLsFileURLsRequest)
ForwardMsg)GitInfo)ConfigCustomThemeConfig
NewSessionUserInfo)caching)ForwardMsgQueue)FragmentStorageMemoryFragmentStorage)Installation)PagesManager)	RerunDataScriptRunnerScriptRunnerEvent)secrets_singleton)to_snake_case)STREAMLIT_VERSION_STRING)LocalSourcesWatcher)BackMsg)PagesChanged)
ScriptData)ScriptCacheSessionState)UploadedFileManager)PageHashPageInfor   _LOGGERc                      e Zd ZdZdZdZy)AppSessionStateAPP_NOT_RUNNINGAPP_IS_RUNNINGSHUTDOWN_REQUESTEDN)__name__
__module____qualname__r-   r.   r/        R/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/app_session.pyr,   r,   ;   s    'O%N-r4   r,   c                 <    t        t        j                               S )z5Randomly generate a unique ID for a script execution.)struuiduuid4r3   r4   r5   _generate_scriptrun_idr:   A   s    tzz|r4   c                     e Zd ZdZ	 d%	 	 	 	 	 	 	 	 	 	 	 	 	 d&dZd'dZd'dZd'dZd(dZd'dZ	d)d	Z
d*d
Zd+dZd,dZd'dZd'dZd-dZed.d       Zd/dZd%d0dZd'dZd'dZd%d1dZ	 	 	 	 	 	 d2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3dZ	 	 	 	 	 	 d2	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3dZd4dZd4dZ	 	 d5	 	 	 	 	 	 	 d6dZ	 	 	 	 d7dZd8dZd'dZ	 d%	 	 	 d,dZ d'dZ!d'd Z"d'd!Z#d9d"Z$d:d#Z%	 	 	 	 	 	 d;d$Z&y)<
AppSessiona!  
    Contains session data for a single "user" of an active app
    (that is, a connected browser tab).

    Each AppSession has its own ScriptData, root DeltaGenerator, ScriptRunner,
    and widget state.

    An AppSession is attached to each thread involved in running its script.

    Nc                   |xs t        t        j                               | _        t	        j
                         | _        || _        || _        || _	        t        |j                  | j                        | _        t               | _        || _        t         j"                  | _        t'               | _        d| _        d| _        d| _        t1        j2                  d      dk7  r| j5                          t1        j2                  d      | _        d| _        ddlm}  |       | _        || _         d| _!        tE               | _#        tH        jK                  d| j                         y)a  Initialize the AppSession.

        Parameters
        ----------
        script_data
            Object storing parameters related to running a script

        uploaded_file_manager
            Used to manage files uploaded by users via the Streamlit web client.

        script_cache
            The app's ScriptCache instance. Stores cached user scripts. ScriptRunner
            uses the ScriptCache to avoid having to reload user scripts from disk
            on each rerun.

        message_enqueued_callback
            After enqueuing a message, this callable notification will be invoked.

        user_info
            A dict that contains information about the current user. For now,
            it only contains the user's email address.

            {
                "email": "example@example.com"
            }

            Information about the current user is optionally provided when a
            websocket connection is initialized via the "X-Streamlit-User" header.

        session_id_override
            The ID to assign to this session. Setting this can be useful when the
            service that a Streamlit Runtime is running in wants to tie the lifecycle of
            a Streamlit session to some other session-like object that it manages.
        Nzserver.fileWatcherTypenonezserver.runOnSaver   r%   zAppSession initialized (id=%s))&r7   r8   r9   idasyncioget_running_loop_event_loop_script_data_uploaded_file_mgr_script_cacher   main_script_path_pages_managerr   _browser_queue_message_enqueued_callbackr,   r-   _stater   _client_state_local_sources_watcher_stop_config_listener_stop_pages_listenerr   
get_optionregister_file_watchers_run_on_save_scriptrunnerstreamlit.runtime.stater&   _session_state
_user_info_debug_last_backmsg_idr   _fragment_storager*   debug)selfscript_datauploaded_file_managerscript_cachemessage_enqueued_callback	user_infosession_id_overrider&   s           r5   __init__zAppSession.__init__R   s!   Z &:TZZ\):"335'"7)*(($*<*<
 ./*C'%55 )]BF#@D"?C!56&@'')"--.@A26 	9*n#26#2G2I6@r4   c                $    | j                          y)zGEnsure that we call shutdown() when an AppSession is garbage collected.N)shutdownrY   s    r5   __del__zAppSession.__del__   s    r4   c                   | j                   t        | j                        | _         | j                   j                  | j                         t        j                  | j                  d      | _        | j                  j                  | j                        | _
        t        j                  j                  | j                         y)a8  Register handlers to be called when various files are changed.

        Files that we watch include:
          - source files that already exist (for edits)
          - `.py` files in the the main script's `pages/` directory (for file additions
            and deletions)
          - project and user-level config.toml files
          - the project-level secrets.toml files

        This method is called automatically on AppSession construction, but it may be
        called again in the case when a session is disconnected and is being reconnect
        to.
        NT)force_connect)rL   r    rG   register_file_change_callback_on_source_file_changedr   on_config_parsedrM   register_pages_changed_callback_on_pages_changedrN   r   file_change_listenerconnect_on_secrets_file_changedrc   s    r5   rP   z!AppSession.register_file_watchers   s     &&.*=d>Q>Q*RD'##AA((	
 &,%<%<((&
" %)$7$7$W$W""%
! 	..66t7T7TUr4   c                <   | j                   | j                   j                          | j                  | j                          | j                  | j                          t        j
                  j                  | j                         d| _         d| _        d| _        y)zJDisconnect the file watcher handlers registered by register_file_watchers.N)rL   closerM   rN   r   rl   
disconnectrn   rc   s    r5   disconnect_file_watchersz#AppSession.disconnect_file_watchers   s    &&2''--/%%1&&($$0%%'..99$:W:WX&*#%)"$(!r4   c                6    | j                   j                         S )ai  Clear the forward message queue and return the messages it contained.

        The Server calls this periodically to deliver new messages
        to the browser connected to this app.

        Returns
        -------
        list[ForwardMsg]
            The messages that were removed from the queue and should
            be delivered to the browser.

        )rH   flushrc   s    r5   flush_browser_queuezAppSession.flush_browser_queue   s     ""((**r4   c                   | j                   t        j                  k7  rt        j	                  d| j
                         | j                  j                  | j
                         t        j                         rSt        j                         }|j                  j                  | j
                         |j                  j                          | j                          t        j                  | _         | j                          yy)ziShut down the AppSession.

        It's an error to use a AppSession after it's been shut down.

        zShutting down (id=%s)N)rJ   r,   r/   r*   rX   r?   rD   remove_session_filesr	   existsget_instancemedia_file_mgrclear_session_refsremove_orphaned_filesrequest_script_stoprr   )rY   rts     r5   rb   zAppSession.shutdown   s     ;;/<<<MM1477; ##88A~~))+!!44TWW=!!779
 $$&)<<DK ))+) =r4   c                    | j                   r| j                   |_        | j                  j                  |       | j                  r| j	                          yy)zEnqueue a new ForwardMsg to our browser queue.

        This can be called on both the main thread and a ScriptRunner
        run thread.

        Parameters
        ----------
        msg : ForwardMsg
            The message to enqueue

        N)rV   debug_last_backmsg_idrH   enqueuerI   rY   msgs     r5   _enqueue_forward_msgzAppSession._enqueue_forward_msg  sI     &&(,(C(CC%##C(**++- +r4   c                |   	 |j                  d      }|dk(  r9|j                  r|j                  | _        | j                  |j                         y|dk(  r| j                          y|dk(  r| j                          y|dk(  r| j                          y|dk(  r| j                  |j                         y|dk(  r| j                          y|dk(  r| j                  |j                         yt        j                  d	|       y# t        $ r0}t        j!                  d
       | j#                  |       Y d}~yd}~ww xY w)zProcess a BackMsg.typererun_scriptload_git_infoclear_cacheapp_heartbeatset_run_on_savestop_scriptfile_urls_requestzNo handler for "%s"zError processing back messageN)
WhichOneofr   rV   _handle_rerun_script_requestr   _handle_git_information_request_handle_clear_cache_request_handle_app_heartbeat_request_handle_set_run_on_save_requestr   _handle_stop_script_request_handle_file_urls_requestr   r*   warning	Exception	exceptionhandle_backmsg_exception)rY   r   msg_typeexs       r5   handle_backmsgzAppSession.handle_backmsg  s   	.~~f-H>),,252K2KD/11#2B2BC_,446]*002_,224..44S5H5HI]*00200..s/D/DE 5x@ 	.=>))"--	.sB   AD D 'D =D  D 4D 
 D +D 	D;&D66D;c                F     j                   j                  t        j                          j                   j                  t        j                  d        j                   j                  t        j                          j
                  j                   fd       y)zGHandle an Exception raised while processing a BackMsg from the browser. )page_script_hashc                 D    j                  j                               S N)r   _create_exception_message)erY   s   r5   <lambda>z5AppSession.handle_backmsg_exception.<locals>.<lambda>P  s    D--d.L.LQ.OPr4   N)_on_scriptrunner_eventrR   r   SCRIPT_STOPPED_WITH_SUCCESSSCRIPT_STARTEDrB   call_soon_threadsafe)rY   r   s   ``r5   r   z#AppSession.handle_backmsg_exception6  s     	## 1 M M	
 	##,, 	$ 	

 	## 1 M M	
 	--P	
r4   c                   | j                   t        j                  k(  rt        j	                  d       y|r|j
                  }|r5| j                  j                  |      st        j                  d| d       yt        |j                  |j                  |j                  |j                  |r|nd|j                        }n
t               }| j                  jt!        t#        j$                  d            r.|j
                  s"| j                  j'                          d| _        n| j                  j)                  |      }|ry| j+                  |       y)a  Signal that we're interested in running the script.

        If the script is not already running, it will be started immediately.
        Otherwise, a rerun will be requested.

        Parameters
        ----------
        client_state : streamlit.proto.ClientState_pb2.ClientState | None
            The ClientState protobuf to run the script with, or None
            to use previous client state.

        z'Discarding rerun request after shutdownNzThe fragment with id zW does not exist anymore - it might have been removed during a preceding full-app rerun.)fragment_idis_auto_rerunzrunner.fastReruns)rJ   r,   r/   r*   r   r   rW   containsinfor   query_stringwidget_statesr   	page_namer   rR   boolr   rO   request_stoprequest_rerun_create_scriptrunner)rY   client_stater   
rerun_datasuccesss        r5   r   zAppSession.request_rerunS  s*    ;;/<<<OOEF&22K" 4#9#9#B#B;#O+K= 9T T "))**--&&+6KD*88J #J)V&&':;<".. ""//1%)"
 ,,:::F
 	!!*-r4   c                R    | j                   | j                   j                          yy)zgRequest that the scriptrunner stop execution.

        Does nothing if no scriptrunner exists.
        N)rR   r   rc   s    r5   r}   zAppSession.request_script_stop  s'    
 )++- *r4   c                8    | j                   j                          y)z%Clear the user info for this session.N)rU   clearrc   s    r5   clear_user_infozAppSession.clear_user_info  s    r4   c                |   t        | j                  | j                  j                  | j                  | j
                  | j                  || j                  | j                  | j                  	      | _
        | j                  j                  j                  | j                         | j                  j                          y)z;Create and run a new ScriptRunner with the given RerunData.)	
session_idrF   session_stateuploaded_file_mgrr\   initial_rerun_datar^   fragment_storagepages_managerN)r   r?   rC   rF   rT   rD   rE   rU   rW   rG   rR   on_eventrm   r   start)rY   r   s     r5   r   zAppSession._create_scriptrunner  s    )ww!..??--"55++1oo!33--

 	##++D,G,GH  "r4   c                    | j                   S r   )rT   rc   s    r5   r   zAppSession.session_state  s    """r4   c                    | j                   j                         t        t        fd      d       }|| j                  j
                  }||k(  S y)Nc                    |    d   k(  S )Nscript_pathr3   )kfilepathpagess    r5   r   z9AppSession._should_rerun_on_file_change.<locals>.<lambda>  s    U1Xm4@r4   T)rG   	get_pagesnextfilterrK   r   )rY   r   changed_page_script_hashcurrent_page_script_hashr   s    `  @r5   _should_rerun_on_file_changez'AppSession._should_rerun_on_file_change  sY    ##--/#'@%H$
 
 $/'+'9'9'J'J$+/GGGr4   c                    | j                   j                          || j                  |      sy| j                  r| j	                  | j
                         y| j                  | j                                y)zfOne of our source files changed. Clear the cache and schedule a rerun if
        appropriate.
        N)rE   r   r   rQ   r   rK   r   _create_file_change_message)rY   r   s     r5   rh   z"AppSession._on_source_file_changed  s`     	  "(I(I((St112%%d&F&F&HIr4   c                $    | j                          y)z:Called when `secrets.file_change_listener` emits a Signal.N)rh   )rY   _s     r5   rn   z#AppSession._on_secrets_file_changed  s     	$$&r4   c                    t               }| j                  |j                  | j                  j	                                | j                  |       | j                  | j                  j                          y y r   )r   _populate_app_pagespages_changedrG   r   r   rL   update_watched_pages)rY   r   r   s      r5   rk   zAppSession._on_pages_changed  s_    l  !2!2D4G4G4Q4Q4ST!!#&&&2''<<> 3r4   c                >    | j                   j                  d|       y )NT)retain_lifecycle_msgsfragment_ids_this_run)rH   r   )rY   r   s     r5   _clear_queuezAppSession._clear_queue  s!    !!"&>S 	" 	
r4   c	                b      j                   j                   f	d       y)a  Called when our ScriptRunner emits an event.

        This is generally called from the sender ScriptRunner's script thread.
        We forward the event on to _handle_scriptrunner_event_on_event_loop,
        which will be called on the main thread.
        c            
     4   	 j                         S r   )(_handle_scriptrunner_event_on_event_loop)	r   eventr   forward_msgr   r   r   rY   senders	   r5   r   z3AppSession._on_scriptrunner_event.<locals>.<lambda>  s(    DAA %	r4   N)rB   r   )	rY   r   r   r   r   r   r   r   r   s	   `````````r5   r   z!AppSession._on_scriptrunner_event  s$    " 	--	 		
r4   c	                T   | j                   t        j                         k(  sJ d       || j                  urt        j                  d|       y| j                  }	|t        j                  k(  r| j                  t        j                  k7  rt        j                  | _        |J d       || j                  j                  k7  r|| j                  _        | j                  |       | j                  | j!                  |||             n|t        j"                  k(  s'|t        j$                  k(  s|t        j&                  k(  rj| j                  t        j                  k7  rt        j(                  | _        |t        j"                  k(  rt*        j,                  }
n4|t        j&                  k(  rt*        j.                  }
nt*        j0                  }
| j                  | j3                  |
             d| _        |t        j"                  k(  s|t        j&                  k(  rC| j6                  r| j6                  j9                          | j6                  j;                          ny|J d       t+               }t=        j>                  |j@                  jB                  |       | j                  |       n)|t        jD                  k(  rjt        j(                  | _        | j                  | j3                  t*        jF                               | j6                  r| j6                  j9                          n|t        jH                  k(  rl|J d       | j                  t        j                  k(  r7tK        jL                         jN                  jQ                  | jR                         || _        d| _        n-|t        jT                  k(  r|J d       | j                  |       |	t        j                  k(  }| j                  t        j                  k(  }||k7  r | j                  | jW                                yy)a#  Handle a ScriptRunner event.

        This function must only be called on our eventloop thread.

        Parameters
        ----------
        sender : ScriptRunner | None
            The ScriptRunner that emitted the event. (This may be set to
            None when called from `handle_backmsg_exception`, if no
            ScriptRunner was active when the backmsg exception was raised.)

        event : ScriptRunnerEvent
            The event type.

        forward_msg : ForwardMsg | None
            The ForwardMsg to send to the frontend. Set only for the
            ENQUEUE_FORWARD_MSG event.

        exception : BaseException | None
            An exception thrown during compilation. Set only for the
            SCRIPT_STOPPED_WITH_COMPILE_ERROR event.

        client_state : streamlit.proto.ClientState_pb2.ClientState | None
            The ScriptRunner's final ClientState. Set only for the
            SHUTDOWN event.

        page_script_hash : str | None
            A hash of the script path corresponding to the page currently being
            run. Set only for the SCRIPT_STARTED event.

        fragment_ids_this_run : list[str] | None
            The fragment IDs of the fragments being executed in this script run. Only
            set for the SCRIPT_STARTED event. If this value is falsy, this script run
            must be for the full script.

        clear_forward_msg_queue : bool
            If set (the default), clears the queue of forward messages to be sent to the
            browser. Set only for the SCRIPT_STARTED event.
        zXThis function must only be called on the eventloop thread the AppSession was created on.z0Ignoring event from non-current ScriptRunner: %sNz9page_script_hash must be set for the SCRIPT_STARTED eventzEexception must be set for the SCRIPT_STOPPED_WITH_COMPILE_ERROR eventz/client_state must be set for the SHUTDOWN eventz-null forward_msg in ENQUEUE_FORWARD_MSG event),rB   r@   rA   rR   r*   rX   rJ   r   r   r,   r/   r.   rK   r   r   r   _create_new_session_messager   !SCRIPT_STOPPED_WITH_COMPILE_ERRORFRAGMENT_STOPPED_WITH_SUCCESSr-   r   FINISHED_SUCCESSFULLY"FINISHED_FRAGMENT_RUN_SUCCESSFULLYFINISHED_WITH_COMPILE_ERROR_create_script_finished_messagerV   rL   update_watched_modulesr   exception_utilsmarshallsession_eventscript_compilation_exceptionSCRIPT_STOPPED_FOR_RERUNFINISHED_EARLY_FOR_RERUNSHUTDOWNr	   ry   rz   r{   r?   ENQUEUE_FORWARD_MSG&_create_session_status_changed_message)rY   r   r   r   r   r   r   r   r   
prev_statestatusr   app_was_runningapp_is_runnings                 r5   r   z3AppSession._handle_scriptrunner_event_on_event_loop  s   f 7#;#;#== 	
f	
= +++ MMLeT[[
%444{{o@@@-<<#/ K/  4#5#5#F#FF6F""334%%00$&;U &BBB)KKK)GGG{{o@@@-==)EEE#99+III#FF#??%%d&J&J6&RS*.D' *FFF-KKK
 ..//FFH//DDF !, [, !l((%%BBI ))#.'@@@)99DK%%4477
 **++BBD'000+ A+ {{o@@@ $$&55HHQ!-D!%D';;;* ?* %%k2 %(F(FF(F(FF_,%%d&Q&Q&ST -r4   c                    t               }| j                  |j                  _        | j                  t
        j                  k(  |j                  _        |S )z6Create and return a session_status_changed ForwardMsg.)r   rQ   session_status_changedrun_on_saverJ   r,   r.   script_is_runningr   s     r5   r   z1AppSession._create_session_status_changed_message  sD    l151B1B"".KK?999 	""4 
r4   c                <    t               }d|j                  _        |S )z8Create and return a 'script_changed_on_disk' ForwardMsg.T)r   r   script_changed_on_diskr   s     r5   r   z&AppSession._create_file_change_message  s    l370
r4   c                d   t               }t               |j                  _        | j                  j
                  |j                  _        | j                  j                  |j                  _        | j                  j                  |j                  _        ||j                  _	        |r%|j                  j                  j                  |       | j                  |j                  |xs | j                  j                                t        |j                  j                         t!        |j                  j"                         |j                  j$                  }t'        |j(                         t*        |j,                  _        dj1                  t3        t4        t6        j8                              |j,                  _        | j<                  |j>                  _         | jB                  tD        jF                  k(  |j>                  _$        | j                  jJ                  |_%        | jL                  |_'        |S )z+Create and return a new_session ForwardMsg..)(r   r:   new_sessionscript_run_idrC   namerG   rF   main_script_hashr   r   extendr   r   _populate_config_msgr   _populate_theme_msgcustom_theme
initialize_populate_user_info_msgr^   r   environment_infostreamlit_versionjoinmapr7   sysversion_infopython_versionrQ   session_statusr   rJ   r,   r.   r   is_hellor?   r   )rY   r   r   r   r   imsgs         r5   r   z&AppSession._create_new_session_message  s    l(>(@%#0055+/+>+>+O+O(+/+>+>+O+O(+;( OO11889NO  OOUEd&9&9&C&C&E	
 	S__334COO889 ))/2J//2xxCAQAQ8R/S,*.*;*;'KK?999 	- ))22''
r4   c                (    t               }||_        |S )z/Create and return a script_finished ForwardMsg.)r   script_finished)rY   r   r   s      r5   r   z*AppSession._create_script_finished_message  s     l$
r4   c                    t               }t        j                  |j                  j                  j
                  |       |S )z*Create and return an Exception ForwardMsg.)r   r   r   deltanew_elementr   )rY   r   r   s      r5   r   z$AppSession._create_exception_message  s.    l  !6!6!@!@!D
r4   c                l   t               }	 ddlm}  || j                  j                        }|j                         }|y |\  }}}|j                  d      r|d d }||j                  _        ||j                  _	        ||j                  _
        |j                  |j                  j                  d d  |j                  |j                  j                  d d  |j                  r*t        j                  j                   |j                  _        nkt%        |j&                        dkD  r*t        j                  j(                  |j                  _        n)t        j                  j*                  |j                  _        | j-                  |       y # t.        $ r!}t0        j3                  d|       Y d }~y d }~ww xY w)Nr   )GitRepoz.gitz+Obtaining Git information produced an error)exc_info)r   streamlit.git_utilr  rC   rF   get_repo_infoendswithgit_info_changed
repositorybranchmoduleuntracked_filesuncommitted_filesis_head_detachedr   	GitStatesHEAD_DETACHEDstatelenahead_commitsAHEAD_OF_REMOTEDEFAULTr   r   r*   rX   )	rY   r   r  repo	repo_inforepository_namer$  r%  r   s	            r5   r   z*AppSession._handle_git_information_request   sh   l!	V24,,==>D**,I .7+OVV''/"1#2"6.=C  +*0C  '*0C  '6:6J6JC  0038<8N8NC  2215$$-4->->-L-L$$*T''(1,-4->->-N-N$$*-4->->-F-F$$*%%c* 	V MMGRTMUU	Vs   4F	 EF	 		F3F..F3c                &    | j                  |       y)a  Tell the ScriptRunner to re-run its script.

        Parameters
        ----------
        client_state : streamlit.proto.ClientState_pb2.ClientState | None
            The ClientState protobuf to run the script with, or None
            to use previous client state.

        N)r   )rY   r   s     r5   r   z'AppSession._handle_rerun_script_request&  s     	<(r4   c                $    | j                          y)z1Tell the ScriptRunner to stop running its script.N)r}   rc   s    r5   r   z&AppSession._handle_stop_script_request4  s      "r4   c                    t         j                  j                          t         j                  j                          | j                  j                          y)zjClear this app's cache.

        Because this cache is global, it will be cleared for all users.

        N)r   
cache_datar   cache_resourcerT   rc   s    r5   r   z&AppSession._handle_clear_cache_request8  s:     	  "$$&!!#r4   c                     y)zHandle an incoming app heartbeat.

        The heartbeat indicates the frontend is active and keeps the
        websocket from going idle and disconnecting.

        The actual handler here is a noop

        Nr3   rc   s    r5   r   z(AppSession._handle_app_heartbeat_requestB  s     	r4   c                P    || _         | j                  | j                                y)zChange our run_on_save flag to the given value.

        The browser will be notified of the change.

        Parameters
        ----------
        new_value : bool
            New run_on_save value

        N)rQ   r   r   )rY   	new_values     r5   r   z*AppSession._handle_set_run_on_save_requestM  s#     &!!$"M"M"OPr4   c                |   t               }|j                  |j                  _        | j                  j                  | j                  |j                        }|D ]Q  }|j                  j                  j                  t        |j                  |j                  |j                               S | j                  |       y)z6Handle a file_urls_request BackMsg sent by the client.)file_id
upload_url
delete_urlN)r   
request_idfile_urls_responseresponse_idrD   get_upload_urlsr?   
file_names	file_urlsappendr   r<  r=  r>  r   )rY   r   r   upload_url_infosupload_url_infos        r5   r   z$AppSession._handle_file_urls_request[  s    l->-I-I*22BBGG&11
  0O"",,33+33.99.99  0 	!!#&r4   c                    |j                         D ]T  \  }}|j                  j                         }||_        |d   j	                  dd      |_        |d   |_        |d   |_        V y )Nr   r    icon)items	app_pagesaddr   replacer   url_pathnamerJ  )rY   r   r   r   	page_info
page_protos         r5   r   zAppSession._populate_app_pageso  sg     ,1;;='i**,J*:J'#,[#9#A#A#s#KJ &/&<J#'/JO ,9r4   r   )rZ   r#   r[   r'   r\   r$   r]   zCallable[[], None] | Noner^   zdict[str, str | bool | None]r_   
str | NonereturnNone)rS  rT  )rS  zlist[ForwardMsg])r   r   rS  rT  )r   r!   rS  rT  )r   BaseExceptionrS  rT  )r   ClientState | NonerS  rT  )r   r   rS  rT  )rS  r&   )r   r7   rS  r   )r   rR  rS  rT  )r   list[str] | NonerS  rT  )NNNNNN)r   zScriptRunner | Noner   r   r   zForwardMsg | Noner   zBaseException | Noner   rV  r   rR  r   rW  r   dict[PageHash, PageInfo] | NonerS  rT  )rS  r   )NN)r   r7   r   rW  r   rX  rS  r   )r   z)ForwardMsg.ScriptFinishedStatus.ValueTyperS  r   )r   rU  rS  r   )r:  r   rS  rT  )r   r   rS  rT  )r   zNewSession | PagesChangedr   zdict[PageHash, PageInfo]rS  rT  )'r0   r1   r2   __doc__r`   rd   rP   rr   ru   rb   r   r   r   r   r}   r   r   propertyr   r   rh   rn   rk   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r4   r5   r<   r<   F   s{   	$ +/XAXA  3XA "	XA
 $=XA 0XA (XA 
XAtV8)+,8.(.8
:K.Z. #  # #J
'?
 *.*.+/'+2615
#
 !
 '	

 (
 )
 %
  0
 /
 

D *.*.+/'+2615aU#aU !aU '	aU
 (aU )aU %aU  0aU /aU 
aUF 3715	++  0+ /	+
 
+Z?	$VN 26).)	)#$	Q'(	0,	05M	0		0r4   r<   c                    d} t        j                  |       }t        t        j                  |j                               }|Hdj                  d t        j                  j                         D              }t        d| d| d|       |S )Nzclient.toolbarModez, c              3  <   K   | ]  }|j                           y wr   )lower).0r   s     r5   	<genexpr>z$_get_toolbar_mode.<locals>.<genexpr>  s     "P6O17796Os   zConfig z. expects to have one of the following values: z. Current value: )	r   rO   getattrr   ToolbarModeupperr  keys
ValueError)
config_keyconfig_value
enum_valueallowed_valuess       r5   _get_toolbar_moderi    s    %J$$Z0L6=L..07J "Pf6H6H6M6M6O"PPj^ $%%3$4 5*^-
 	

 r4   c                .   t        j                  d      | _        t        j                  d      | _        t        j                  d      | _        t        j                  d      | _        t        j                  d      du rd| _        t               | _        y )Nzbrowser.gatherUsageStatszglobal.maxCachedMessageAgezserver.allowRunOnSavezui.hideTopBarzclient.showSidebarNavigationFT)	r   rO   gather_usage_statsmax_cached_message_ageallow_run_on_savehide_top_barhide_sidebar_navri  toolbar_moder   s    r5   r  r    sx    #../IJC!'!2!23O!PC"--.EFC((9C78EA#(*Cr4   c           	        ddh}t        j                  d      }t        |j                               sy |j	                         D ]#  \  }}||vs|t        | t        |      |       % | j                  j                  | j                  j                  d}|d   }|B||vr4t        j                  d| dt        |j                                d       n
||   | _        | j                  j                   | j                  j"                  | j                  j$                  d}|d   }|C||vr4t        j                  d| d	t        |j                                d
       y ||   | _        y y )Nbasefonttheme)lightdark"z=" is an invalid value for theme.base. Allowed values include z . Setting theme.base to "light".)z
sans serifserif	monospacez=" is an invalid value for theme.font. Allowed values include z%. Setting theme.font to "sans serif".)r   get_options_for_sectionanyvaluesrK  setattrr   	BaseThemeLIGHTDARKr*   r   listrc  rs  
FontFamily
SANS_SERIFSERIF	MONOSPACErt  )	r   enum_encoded_options
theme_optsoption_name
option_valbase_maprs  font_maprt  s	            r5   r  r    sv   "F+//8Jz  "##-#3#3#5Z22z7MC{3Z@ $6 $$""H fDxOOD6 ++/+@*A B22  ~CH nn//%%^^--H
 fDxOOD6 ++/+@*A B77  ~CH r4   c                    t        j                         j                  | _        t        j                         j                  | _        y r   )r   instanceinstallation_idinstallation_id_v3rq  s    r5   r  r    s0    &//1AAC)224GGCr4   )rS  r7   )rS  zConfig.ToolbarMode.ValueType)r   r   rS  rT  )r   r   rS  rT  )r   r   rS  rT  )R
__future__r   r@   r  r8   enumr   typingr   r   r   streamlit.elements.exceptionelementsr   r   	streamlitr   r	   streamlit.loggerr
   streamlit.proto.ClientState_pb2r   streamlit.proto.Common_pb2r   r   streamlit.proto.ForwardMsg_pb2r   streamlit.proto.GitInfo_pb2r   streamlit.proto.NewSession_pb2r   r   r   r   streamlit.runtimer   #streamlit.runtime.forward_msg_queuer   streamlit.runtime.fragmentr   r   streamlit.runtime.metrics_utilr   streamlit.runtime.pages_managerr   streamlit.runtime.scriptrunnerr   r   r   streamlit.runtime.secretsr   streamlit.string_utilr   streamlit.versionr   streamlit.watcherr    streamlit.proto.BackMsg_pb2r!    streamlit.proto.PagesChanged_pb2r"   streamlit.runtime.script_datar#   +streamlit.runtime.scriptrunner.script_cacher$   rS   r&   'streamlit.runtime.uploaded_file_managerr'   streamlit.source_utilr(   r)   r0   r*   __annotations__r,   r:   r<   ri  r  r  r  r3   r4   r5   <module>r     s    #  
   1 1 6 6 % ' 7 @ 5 /  & ? M 7 8 U U 7 / 6 13=8G4K8H% %.d .
r0 r0t +,&^Hr4   