
    /_i                    F   U d dl mZ d dlZd dl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Z d dlmc mZ d dl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$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/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6 d dl7m8Z8 d dl9m:Z: d dl;m<Z< d dl=m>Z> d dl?m@Z@ e
r.d dlAmBZB d dlCmDZDmEZE d dlFmGZG d dlHmIZI d dlJmKZK d dlLmMZM d dlNmOZOmPZP  eeQ      ZRdeSd <    G d! d"e      ZTd*d#ZU G d$ d%      ZVd+d&ZWd,d'ZXd-d.d(ZYd/d)ZZy)0    )annotationsN)Enum)TYPE_CHECKINGAnyFinal)	ParseDict)configenv_utilruntime)
get_logger)ClientState)FileURLsFileURLsRequest)
ForwardMsg)GitInfo)ConfigCustomThemeConfigFontFace
NewSessionUserInfo)caching)ForwardMsgQueue)FragmentStorageMemoryFragmentStorage)Installation)PagesManager)	RerunDataScriptRunnerScriptRunnerEvent)secrets_singleton)parse_fonts_with_source)to_snake_case)STREAMLIT_VERSION_STRING)LocalSourcesWatcher)Callable)BackMsgDeferredFileRequest)
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__r2   r3   r4        \/var/www/html/land_sniper/venv/lib/python3.12/site-packages/streamlit/runtime/app_session.pyr1   r1   B   s    'O%N-r9   r1   c                 <    t        t        j                               S )z5Randomly generate a unique ID for a script execution.)struuiduuid4r8   r9   r:   _generate_scriptrun_idr?   H   s    tzz|r9   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d1dZd%d2dZ	 	 	 	 	 	 d3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4dZ	 	 	 	 	 	 d3	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4dZd5dZd5dZ	 	 d6	 	 	 	 	 	 	 d7dZ	 	 	 	 d8dZd9dZd'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&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))&r<   r=   r>   idasyncioget_running_loop_event_loop_script_data_uploaded_file_mgr_script_cacher   main_script_path_pages_managerr   _browser_queue_message_enqueued_callbackr1   r2   _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           r:   __init__zAppSession.__init__Y   s!   Z &:TZZ\):"335'"7)*(($*<*<
 ./*C'%55 )]BF#@D"?C!56&@'')"--.@A26 	9*n#26#2G2I6@r9   c                $    | j                          y)zGEnsure that we call shutdown() when an AppSession is garbage collected.N)shutdownr^   s    r:   __del__zAppSession.__del__   s    r9   c                8   | j                   t        | j                        | _         | j                   j                  | j                         t        j                  | j                  d      | _        t        j                  j                  | j                         y)a4  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 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)rQ   r$   rL   register_file_change_callback_on_source_file_changedr	   on_config_parsedrR   r    file_change_listenerconnect_on_secrets_file_changedrh   s    r:   rU   z!AppSession.register_file_watchers   s|     &&.*=d>Q>Q*RD'##AA((	
 &,%<%<((&
" 	..66t7T7TUr9   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)rQ   closerR   rS   r    ro   
disconnectrq   rh   s    r:   disconnect_file_watchersz#AppSession.disconnect_file_watchers   s    &&2''--/%%1&&($$0%%'..99$:W:WX&*#%)"$(!r9   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.

        )rM   flushrh   s    r:   flush_browser_queuezAppSession.flush_browser_queue   s     ""((**r9   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)rO   r1   r4   r/   r]   rD   rI   remove_session_filesr   existsget_instancemedia_file_mgrclear_session_refsremove_orphaned_filesrequest_script_stopru   )r^   rts     r:   rg   zAppSession.shutdown   s     ;;/<<<MM1477; ##88A~~))+!!44TWW=!!779
 $$&)<<DK ))+) =r9   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)r[   debug_last_backmsg_idrM   enqueuerN   r^   msgs     r:   _enqueue_forward_msgzAppSession._enqueue_forward_msg
  sI     &&(,(C(CC%##C(**++- +r9   c                4   	 |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|d	k(  rWt        j                  | j                  |j                               }|j#                  d
|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_requestdeferred_file_requestdeferred_file_zNo handler for "%s"zError processing back messageN)
WhichOneofr   r[   _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   rE   create_task_handle_deferred_file_requestr   set_namefile_idr/   warning	Exception	exceptionhandle_backmsg_exception)r^   r   msg_typetaskexs        r:   handle_backmsgzAppSession.handle_backmsg  sb   !	.~~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44 **66s7P7PQ s/H/H/P/P.QRS 5x@ 	.=>))"--	.sI   AE E 'E =E  E 4E 
 E +AE E 	F'&FF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)er^   s   r:   <lambda>z5AppSession.handle_backmsg_exception.<locals>.<lambda>]  s    D--d.L.LQ.OP r9   N)_on_scriptrunner_eventrW   r   SCRIPT_STOPPED_WITH_SUCCESSSCRIPT_STARTEDrG   call_soon_threadsafe)r^   r   s   ``r:   r   z#AppSession.handle_backmsg_exceptionC  s     	## 1 M M	
 	##,, 	$ 	

 	## 1 M M	
 	--P	
r9   c                ^   | j                   t        j                  k(  rt        j	                  d       y|r|j
                  }|r2| j                  j                  |      st        j                  d|       y|j                  d      r/| j                  j                  j                  |j                         t        |j                  |j                  |j                   |j"                  |r|nd|j$                  t'        |j(                        |j                        }n
t               }| j*                  jt-        t/        j0                  d            r.|j
                  s"| j*                  j3                          d| _        n| j*                  j5                  |      }|ry| j7                  |       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 shutdownNznThe fragment with id %s does not exist anymore - it might have been removed during a preceding full-app rerun.context_info)query_stringwidget_statesr   	page_namefragment_idis_auto_reruncached_message_hashesr   zrunner.fastReruns)rO   r1   r4   r/   r   r   r\   containsinfoHasFieldrP   r   CopyFromr   r   r   r   r   r   setr   rW   boolr	   rT   request_stoprequest_rerun_create_scriptrunner)r^   client_stater   
rerun_datasuccesss        r:   r   zAppSession.request_rerun`  se    ;;/<<<OOEF&22K" 4#9#9#B#B;#OT
 $$^4""//889R9RS")66*88!-!>!>&00+6KD*88&),*L*L&M)66	J #J)V&&':;<".. ""//1%)"
 ,,:::F
 	!!*-r9   c                R    | j                   | j                   j                          yy)zgRequest that the scriptrunner stop execution.

        Does nothing if no scriptrunner exists.
        N)rW   r   rh   s    r:   r   zAppSession.request_script_stop  s'    
 )++- *r9   c                8    | j                   j                          y)z%Clear the user info for this session.N)rZ   clearrh   s    r:   clear_user_infozAppSession.clear_user_info  s    r9   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_idrK   session_stateuploaded_file_mgrra   initial_rerun_datarc   fragment_storagepages_managerN)r   rD   rH   rK   rY   rI   rJ   rZ   r\   rL   rW   on_eventrp   r   start)r^   r   s     r:   r   zAppSession._create_scriptrunner  s    )ww!..??--"55++1oo!33--

 	##++D,G,GH  "r9   c                    | j                   S r   )rY   rh   s    r:   r   zAppSession.session_state  s    """r9   c                    | j                   j                         t        t        fd      d       }|| j                  j
                  }||k(  S y)Nc                    |    d   k(  S )Nscript_pathr8   )kfilepathpagess    r:   r   z9AppSession._should_rerun_on_file_change.<locals>.<lambda>  s    U1Xm4@ r9   T)rL   	get_pagesnextfilterrP   r   )r^   r   changed_page_script_hashcurrent_page_script_hashr   s    `  @r:   _should_rerun_on_file_changez'AppSession._should_rerun_on_file_change  sY    ##--/#'@%H$
 
 $/'+'9'9'J'J$+/GGGr9   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)rJ   r   r   rV   r   rP   r   _create_file_change_message)r^   r   s     r:   rm   z"AppSession._on_source_file_changed  s`     	  "(I(I((St112%%d&F&F&HIr9   c                $    | j                          y)z:Called when `secrets.file_change_listener` emits a Signal.N)rm   )r^   _s     r:   rq   z#AppSession._on_secrets_file_changed  s     	$$&r9   c                >    | j                   j                  d|       y )NT)retain_lifecycle_msgsfragment_ids_this_run)rM   r   )r^   r   s     r:   _clear_queuezAppSession._clear_queue  s!    !!"&>S 	" 	
r9   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   r^   senders	   r:   r   z3AppSession._on_scriptrunner_event.<locals>.<lambda>  s*    DAA %	 r9   N)rG   r   )	r^   r   r   r   r   r   r   r   r   s	   `````````r:   r   z!AppSession._on_scriptrunner_event  s$    " 	--	 		
r9   c	                h   | j                   t        j                         k7  rt        d      || j                  urt
        j                  d|       y| j                  }	|t        j                  k(  r| j                  t        j                  k7  rt        j                  | _        |t        d      || j                  j                  k7  r|| j                  _        | j                  |       | j!                  |||      }
| j#                  |
       n|t        j$                  t        j&                  t        j(                  hv rj| j                  t        j                  k7  rt        j*                  | _        |t        j$                  k(  rt,        j.                  }n4|t        j(                  k(  rt,        j0                  }nt,        j2                  }| j#                  | j5                  |             d| _        |t        j$                  t        j(                  hv rC| j8                  r| j8                  j;                          | j8                  j=                          n|t        d      t-               }
t?        j@                  |
jB                  jD                  |       | j#                  |
       n1|t        jF                  k(  rjt        j*                  | _        | j#                  | j5                  t,        jH                               | j8                  r| j8                  j;                          n|t        jJ                  k(  rp|t        d      | j                  t        j                  k(  r7tM        jN                         jP                  jS                  | jT                         || _        d| _        n1|t        jV                  k(  r|t        d      | j#                  |       |	t        j                  k(  }| j                  t        j                  k(  }||k7  r | j#                  | jY                                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.
        zrThis function must only be called on the eventloop thread the AppSession was created on. This should never happen.z0Ignoring event from non-current ScriptRunner: %sNzTpage_script_hash must be set for the SCRIPT_STARTED event. This should never happen.z`exception must be set for the SCRIPT_STOPPED_WITH_COMPILE_ERROR event. This should never happen.zJclient_state must be set for the SHUTDOWN event. This should never happen.zHnull forward_msg in ENQUEUE_FORWARD_MSG event. This should never happen.)-rG   rE   rF   RuntimeErrorrW   r/   r]   rO   r   r   r1   r4   r3   rP   r   r   _create_new_session_messager   r   !SCRIPT_STOPPED_WITH_COMPILE_ERRORFRAGMENT_STOPPED_WITH_SUCCESSr2   r   FINISHED_SUCCESSFULLY"FINISHED_FRAGMENT_RUN_SUCCESSFULLYFINISHED_WITH_COMPILE_ERROR_create_script_finished_messager[   rQ   update_watched_modulesupdate_watched_pagesexception_utilsmarshallsession_eventscript_compilation_exceptionSCRIPT_STOPPED_FOR_RERUNFINISHED_EARLY_FOR_RERUNSHUTDOWNr   r|   r}   r~   rD   ENQUEUE_FORWARD_MSG&_create_session_status_changed_message)r^   r   r   r   r   r   r   r   r   
prev_stater   statusapp_was_runningapp_is_runnings                 r:   r   z3AppSession._handle_scriptrunner_event_on_event_loop  s   f w7799, 
 +++ MMLeT[[
%444{{o@@@-<<'"j   4#5#5#F#FF6F""33422 "7C %%c*99??;;
 

 {{o@@@-==)EEE#99+III#FF#??%%d&J&J6&RS*.D'!==!??  ..//FFH//DDF $&4  !l((%%BBI ))#.'@@@)99DK%%4477
 **++BBD'000#"`  {{o@@@ $$&55HHQ!-D!%D';;;""^  %%k2 %(F(FF(F(FF_,%%d&Q&Q&ST -r9   c                    t               }| j                  |j                  _        | j                  t
        j                  k(  |j                  _        |S )z6Create and return a session_status_changed ForwardMsg.)r   rV   session_status_changedrun_on_saverO   r1   r3   script_is_runningr   s     r:   r  z1AppSession._create_session_status_changed_message  sD    l151B1B"".KK?999 	""4 
r9   c                <    t               }d|j                  _        |S )z8Create and return a 'script_changed_on_disk' ForwardMsg.T)r   r   script_changed_on_diskr   s     r:   r   z&AppSession._create_file_change_message  s    l370
r9   c                J   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"                         t!        |j                  j"                  j$                  dt        j&                  j(                  j*                          t!        |j                  j"                  j,                  dt        j&                  j.                  j*                          t!        |j                  j"                  j0                  dt        j&                  j2                  j*                          t!        |j                  j"                  j$                  j0                  dt        j&                  j4                  j*                          t!        |j                  j"                  j,                  j0                  dt        j&                  j6                  j*                          |j                  j8                  }t;        |j<                         t>        |j@                  _!        djE                  tG        tH        tJ        jL                              |j@                  _'        tP        jR                  |j@                  _*        dtV        jX                  v xs dtV        jX                  v |j@                  _-        | j\                  |j^                  _0        | jb                  td        jf                  k(  |j^                  _4        | j                  jj                  |_5        | jl                  |_7        |S )z+Create and return a new_session ForwardMsg.ztheme..DISPLAYWAYLAND_DISPLAY)8r   r?   new_sessionscript_run_idrH   namerL   rK   main_script_hashr   r   extend_populate_app_pagesr   _populate_config_msgr	   _populate_theme_msgcustom_themelightCustomThemeCategoriesLIGHTvaluedarkDARKsidebarSIDEBARLIGHT_SIDEBARDARK_SIDEBAR
initialize_populate_user_info_msgrc   r#   environment_infostreamlit_versionjoinmapr<   sysversion_infopython_versionr
   SYSTEM	server_ososenvironhas_displayrV   session_statusr	  rO   r1   r3   r
  is_hellorD   r   )r^   r   r   r   r   imsgs         r:   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OO((..V1177==>?	

 	OO((--V1166<<=>	

 	OO((00V1199??@A	

 	OO((..66V11??EEFG	

 	OO((--55V11>>DDEF	
 ))/2J//2xxCAQAQ8R/S,*2//'#F'8BJJ'F 	) +/*;*;'KK?999 	- ))22''
r9   c                (    t               }||_        |S )z/Create and return a script_finished ForwardMsg.)r   script_finished)r^   r  r   s      r:   r   z*AppSession._create_script_finished_message%  s     l$
r9   c                    t               }t        j                  |j                  j                  j
                  |       |S )z*Create and return an Exception ForwardMsg.)r   r   r   deltanew_elementr   )r^   r   r   s      r:   r   z$AppSession._create_exception_message-  s.    l  !6!6!@!@!D
r9   c                   t               }	 ddlm}  || j                  j                        }|j                         }|y |\  }}}|j                  d      }||j                  _        ||j                  _	        ||j                  _
        |j                  xs g |j                  j                  d d  |j                  xs g |j                  j                  d d  |j                  r*t        j                  j                   |j                  _        nw|j$                  rBt'        |j$                        dkD  r*t        j                  j(                  |j                  _        n)t        j                  j*                  |j                  _        t,        j/                  d|||       | j1                  |       y # t2        $ r!}t,        j/                  d|       Y d }~y d }~ww xY w)Nr   )GitRepoz.gitz7Git information found. Name: %s, Branch: %s, Module: %sz+Obtaining Git information produced an errorexc_info)r   streamlit.git_utilr;  rH   rK   get_repo_inforemovesuffixgit_info_changed
repositorybranchmoduleuntracked_filesuncommitted_filesis_head_detachedr   	GitStatesHEAD_DETACHEDstateahead_commitslenAHEAD_OF_REMOTEDEFAULTr/   r]   r   r   )	r^   r   r;  repo	repo_inforepository_namerC  rD  r   s	            r:   r   z*AppSession._handle_git_information_request3  s   l%	V24,,==>D**,I .7+OVV-::6BO.=C  +*0C  '*0C  '6:6J6J6PbC  0038<8N8N8TRTC  2215$$-4->->-L-L$$*##D,>,>(?!(C-4->->-N-N$$*-4->->-F-F$$*MMI	 %%c* 	V MMGRTMUU	Vs   4F0 E.F0 0	G9GG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   )r^   r   s     r:   r   z'AppSession._handle_rerun_script_request]  s     	<(r9   c                $    | j                          y)z1Tell the ScriptRunner to stop running its script.N)r   rh   s    r:   r   z&AppSession._handle_stop_script_requestk  s      "r9   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_resourcerY   rh   s    r:   r   z&AppSession._handle_clear_cache_requesto  s:     	  "$$&!!#r9   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

        Nr8   rh   s    r:   r   z(AppSession._handle_app_heartbeat_requesty  s     	r9   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)rV   r   r  )r^   	new_values     r:   r   z*AppSession._handle_set_run_on_save_request  s#     &!!$"M"M"OPr9   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.)r   
upload_url
delete_urlN)r   
request_idfile_urls_responseresponse_idrI   get_upload_urlsrD   
file_names	file_urlsappendr   r   r[  r\  r   )r^   r   r   upload_url_infosupload_url_infos        r:   r   z$AppSession._handle_file_urls_request  s    l->-I-I*22BBGG&11
  0 	O"",,33+33.99.99	 	!!#&r9   c                  K   t               }|j                  |j                  _        	 t        j                  t        j                         j                  j                  |j                         d{   }||j                  _	        | j                  |       y7 '# t        $ rD}t        j                  d|j                         t        |      |j                  _        Y d}~\d}~ww xY ww)zHandle a deferred_file_request BackMsg sent by the client.

        Execute the deferred callable in a separate thread and send the URL back
        to the frontend. This prevents blocking the main event loop if the callable
        is slow.
        Nz0Error executing deferred callable for file_id %s)r   r   deferred_file_responserE   	to_threadr   r|   r}   execute_deferredurlr   r/   r   r<   	error_msgr   )r^   requestresponserj  r   s        r:   r   z(AppSession._handle_deferred_file_request  s      <29//''/	?  ))$$&55FF C 36H++/ 	!!(+
  	?BGOO 9<AH++55	?sA   &C,A	B 2B3B C,B 	C)%:C$C,$C))C,c                    |j                         D ]T  \  }}|j                  j                         }||_        |d   j	                  dd      |_        |d   |_        |d   |_        V y )Nr   r    icon)items	app_pagesaddr   replacer   url_pathnamerp  )r^   r   r   r   	page_info
page_protos         r:   r  zAppSession._populate_app_pages  sl     ,1;;= 	0'i**,J*:J'#,[#9#A#A#s#KJ &/&<J#'/JO	0r9   r   )r_   r(   r`   r,   ra   r)   rb   zCallable[[], None] | Nonerc   zdict[str, str | bool | None]rd   
str | NonereturnNone)ry  rz  )ry  zlist[ForwardMsg])r   r   ry  rz  )r   r&   ry  rz  )r   BaseExceptionry  rz  )r   ClientState | Nonery  rz  )r   r   ry  rz  )ry  r+   )r   r<   ry  r   )r   rx  ry  rz  )r   r   ry  rz  )r   list[str] | Nonery  rz  )NNNNNN)r   zScriptRunner | Noner   r   r   zForwardMsg | Noner   zBaseException | Noner   r|  r   rx  r   r}  r   dict[PageHash, PageInfo] | Nonery  rz  )ry  r   )NN)r   r<   r   r}  r   r~  ry  r   )r  z)ForwardMsg.ScriptFinishedStatus.ValueTypery  r   )r   r{  ry  r   )rY  r   ry  rz  )r   r   ry  rz  )rl  r'   ry  rz  )r   r   r   zdict[PageHash, PageInfo]ry  rz  )'r5   r6   r7   __doc__re   ri   rU   ru   rx   rg   r   r   r   r   r   r   r   propertyr   r   rm   rq   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r  r8   r9   r:   rA   rA   M   s   	$ +/XAXA  3XA "	XA
 $=XA 0XA (XA 
XAtV2)+,8.(#.J
:R.h. #  # #J
'
 *.*.+/'+2615
#
 !
 '	

 (
 )
 %
  0
 /
 

D *.*.+/'+2615hU#hU !hU '	hU
 (hU )hU %hU  0hU /hU 
hUT 3715	KK  0K /	K
 
KZ?	(VV 26).)	)#$	Q'(,8	0	0&>	0		0r9   rA   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     r:   	<genexpr>z$_get_toolbar_mode.<locals>.<genexpr>  s     "P1779"Ps   zConfig z. expects to have one of the following values: z. Current value: )	r	   rT   getattrr   ToolbarModeupperr(  keys
ValueError)
config_keyconfig_value
enum_valueallowed_valuess       r:   _get_toolbar_moder    s    %J$$Z0L6=L..07J "Pf6H6H6M6M6O"PPj^ $%%3$4 5*^-
 	

 r9   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	   rT   gather_usage_statsmax_cached_message_ageallow_run_on_savehide_top_barhide_sidebar_navr  toolbar_mode)r   s    r:   r  r    sx    #../IJC!'!2!23O!PC"--.EFC((9C78EA#(*Cr9   c           	     ^   t        j                  |      }t        d |j                         D              ry |j	                         D ]#  \  }}|dvs|t        | t        |      |       % | j                  j                  | j                  j                  d}|j                  dd       }|=||vr/t        j                  d|t        |j                                      n
||   | _        t!        | |j                  dd       |j                  dd       |j                  dd       |      } |j                  d	d       }t#        |t$              r	 t'        j(                  |      }|M|D ]H  }		 d|	v rt%        |	d         |	d<   |	d= | j,                  j/                  t1        |	t3                            J |j                  dd       }
t#        |
t$              rL|
j5                         j7                         }
|
j9                  d      r|
gdz  }
n	 t'        j(                  |
      }
|
J|
rt;        |
      dkD  rt=        dt;        |
             |
D ]  }	 | j>                  j/                  |         |j                  dd       }t#        |t$              r	 t'        j(                  |      }t#        |t@              r-tC        dd      D ]  }| jD                  j/                  |        nrt#        |t              rb|rt;        |      dkD  rt=        dt;        |             |d d dgdt;        |      z
  z  z   }|D ]  }	 | jD                  j/                  |         |j                  dd       }t#        |t$              r	 t'        j(                  |      }|#|D ]  }	 | jH                  j/                  |         |j                  dd       }t#        |t$              r	 t'        j(                  |      }|Qt;        |      d k7  rt        jK                  d!t;        |             |D ]  }	 | jL                  j/                  |         y y # t*        $ r%}t        j                  d
||       d }Y d }~d }~ww xY w# t*        $ r#}t        j                  d|	|       Y d }~-d }~ww xY w# t*        $ r%}t        j                  d|
|       d }
Y d }~d }~ww xY w# t*        $ r#}t        j                  d||       Y d }~d }~ww xY w# t*        $ r%}t        j                  d||       d }Y d }~d }~ww xY w# t*        $ r#}t        j                  d||       Y d }~"d }~ww xY w# t&        jF                  $ r%}t        j                  d||       d }Y d }~d }~ww xY w# t*        $ r#}t        j                  d||       Y d }~/d }~ww xY w# t&        jF                  $ r%}t        j                  d||       d }Y d }~d }~ww xY w# t*        $ r#}t        j                  d||       Y d }~d }~ww xY w)"Nc              3  $   K   | ]  }|d u  
 y wr   r8   )r  vals     r:   r  z&_populate_theme_msg.<locals>.<genexpr>  s     
633$;
6s   >	   basefontcodeFont	fontFacesheadingFontheadingFontSizesheadingFontWeightschartSequentialColorschartCategoricalColors)r  r  r  zb"%s" is an invalid value for theme.base. Allowed values include %s. Setting theme.base to "light".r  r  r  r  zFFailed to parse the theme.fontFaces config option with json.loads: %s.r<  weightweight_rangez6Failed to parse the theme.fontFaces config option: %s.r  )pxrem   zMFailed to parse the theme.headingFontSizes config option with json.loads: %s.zUConfig theme.headingFontSizes should have 1-6 values corresponding to h1-h6, but got z=Failed to parse the theme.headingFontSizes config option: %s.r  zOFailed to parse the theme.headingFontWeights config option with json.loads: %s.      zWConfig theme.headingFontWeights should have 1-6 values corresponding to h1-h6, but got iX  z?Failed to parse the theme.headingFontWeights config option: %s.r  zCFailed to parse the theme.chartCategoricalColors config option: %s.r  zBFailed to parse the theme.chartSequentialColors config option: %s.
   zuConfig theme.chartSequentialColors should have 10 color values, but got %s. Defaulting to Streamlit's default colors.)'r	   get_options_for_sectionallvaluesrq  setattrr"   	BaseThemer  r  getr/   r   listr  r  r!   
isinstancer<   jsonloadsr   
font_facesrc  r   r   stripr  endswithrL  r  heading_font_sizesintrangeheading_font_weightsJSONDecodeErrorchart_categorical_colorserrorchart_sequential_colors)r   section
theme_optsoption_name
option_valbase_mapr  r  r   	font_facer  sizer  r   heading_weightsr  r  colorr  s                      r:   r  r    su   //8J

6*"3"3"5
66#-#3#3#5 AZ 
 &C{3Z@%A2 $$""H >>&$'DxOO1X]]_%	  ~CH "vt$z4(}d+C T2J *c"	J/J # 	I
y(03Ih4G0HIn-!(+%%i	8:&FG	 $(:DA
 $c*/557==?&&}5"4!5!9*%)ZZ0B%C" %!S);%<q%@1235  ' 	D&&--d3	 &>>*>E &,	(#'::.B#C  &,q! 	BA$$++,@A	B	($	/#s+?'@1'D3457 
 /r2cU())6
 
 & 	F((//7	  *~~.FM *C0	,'+zz2J'K$  +- 	E,,33E:	 )nn-DdK )3/	+&*jj1H&I# *&'2-MMH+,
 - 	E++2259	 +_  	OOX  
 J	  L    *  *c&   
 &*"*$  S      	(OOa$  
 $( 	(6  U     ## 	,OOU(  
 (,$	,  Y     ## 	+OOT'  
 '+#	+&  X    s   P; *AQ,
R SS; 5T,5U VW X ;	Q)Q$$Q),	R5RR	S	$SS		S8S33S8;	T)T$$T),	U5UUV.VV	WV==WW=W88W= 	X,	X''X,c                    t        j                         }|j                  | _        |j                  | _        |j                  | _        y r   )r   instanceinstallation_idinstallation_id_v3installation_id_v4)r   insts     r:   r%  r%    s:      "D..C!44C!44Cr9   )ry  r<   )ry  zConfig.ToolbarMode.ValueType)r   r   ry  rz  )theme)r   r   r  r<   ry  rz  )r   r   ry  rz  )[
__future__r   rE   r  r/  r*  r=   enumr   typingr   r   r   google.protobuf.json_formatr   streamlit.elements.exceptionelementsr   r   	streamlitr	   r
   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   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.runtime.theme_utilr!   streamlit.string_utilr"   streamlit.versionr#   streamlit.watcherr$   collections.abcr%   streamlit.proto.BackMsg_pb2r&   r'   streamlit.runtime.script_datar(   +streamlit.runtime.scriptrunner.script_cacher)   rX   r+   'streamlit.runtime.uploaded_file_managerr,   streamlit.source_utilr-   r.   r5   r/   __annotations__r1   r?   rA   r  r  r  r%  r8   r9   r:   <module>r     s    #   	 
   , , 1 6 6 / / ' 7 @ 5 /  & ? M 7 8 U U 7 @ / 6 1(H8G4K8H% %.d .
~0 ~0L +]@5r9   