
    [i                       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lCmDZD d dlEmFZFmGZG d dlHmIZI d dlJmKZK d dlLmMZM d dlNmOZO d dlPmQZQ d d lRmSZSmTZT  eeU      ZVd!eWd"<    G d# d$e      ZXd.d%ZY G d& d'      ZZd/d(Z[d0d)Z\d1d*Z]	 d2	 	 	 	 	 	 	 	 	 d3d+Z^d4d5d,Z_d6d-Z`y)7    )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)RepeatedScalarFieldContainer)BackMsgDeferredFileRequest)
ScriptData)ScriptCache)UserInfoType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__r4   r5   r6        n/var/www/html/userprofiledev.eatanceapp.com/venv/lib/python3.12/site-packages/streamlit/runtime/app_session.pyr3   r3   E   s    'O%N-r;   r3   c                 <    t        t        j                               S )z5Randomly generate a unique ID for a script execution.)struuiduuid4r:   r;   r<   _generate_scriptrun_idrA   K   s    tzz|r;   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d.dZed/d       Zd0dZd&d1dZd2dZd&d3dZ	 	 	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZ	 	 	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5dZd6dZd6dZ	 	 d7	 	 	 	 	 	 	 d8dZ	 	 	 	 d9dZd:d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_callbackr3   r4   _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_storager1   debug)selfscript_datauploaded_file_managerscript_cachemessage_enqueued_callback	user_infosession_id_overrider-   s           r<   __init__zAppSession.__init__\   s!   Z &:TZZ\):"335'"7)*(($*<*<
 ./*C'%55 )]BF#@D"?C!56&@'')"--.@A26 	9*n#26#2G2I6@r;   c                $    | j                          y)zGEnsure that we call shutdown() when an AppSession is garbage collected.N)shutdownr`   s    r<   __del__zAppSession.__del__   s    r;   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)rS   r$   rN   register_file_change_callback_on_source_file_changedr	   on_config_parsedrT   r    file_change_listenerconnect_on_secrets_file_changedrj   s    r<   rW   z!AppSession.register_file_watchers   s|     &&.*=d>Q>Q*RD'##AA((	
 &,%<%<((&
" 	..66t7T7TUr;   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)rS   closerT   rU   r    rq   
disconnectrs   rj   s    r<   disconnect_file_watchersz#AppSession.disconnect_file_watchers   s    &&2''--/%%1&&($$0%%'..99$:W:WX&*#%)"$(!r;   c                    t        j                  | j                         t        j                  | j                         y)zClears session-level caches for this session.

        This should be called when a session is disconnected or shut down, since this
        ensures memory is freed up and resource release hooks are called.
        N)r   clear_session_data_cacherF   clear_session_resource_cacherj   s    r<   clear_session_cacheszAppSession.clear_session_caches   s(     	((1,,TWW5r;   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.

        )rO   flushrj   s    r<   flush_browser_queuezAppSession.flush_browser_queue   s     ""((**r;   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                          | 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)rQ   r3   r6   r1   r_   rF   rK   remove_session_filesr   existsget_instancemedia_file_mgrclear_session_refsremove_orphaned_filesrequest_script_stoprw   r{   )r`   rts     r<   ri   zAppSession.shutdown   s     ;;/<<<MM1477; ##88A~~))+!!44TWW=!!779
 $$&)<<DK ))+ %%'/ =r;   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_idrO   enqueuerP   r`   msgs     r<   _enqueue_forward_msgzAppSession._enqueue_forward_msg  sI     &&(,(C(CC%##C(**++- +r;   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   rG   create_task_handle_deferred_file_requestr   set_namefile_idr1   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>l  s    D--d.L.LQ.OPr;   N)_on_scriptrunner_eventrY   r   SCRIPT_STOPPED_WITH_SUCCESSSCRIPT_STARTEDrI   call_soon_threadsafe)r`   r   s   ``r<   r   z#AppSession.handle_backmsg_exceptionR  s     	## 1 M M	
 	##,, 	$ 	

 	## 1 M M	
 	--P	
r;   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"                  |xs 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)rQ   r3   r6   r1   r   r   r^   containsinfoHasFieldrR   r   CopyFromr   r   r   r   r   r   setr   rY   boolr	   rV   request_stoprequest_rerun_create_scriptrunner)r`   client_stater   
rerun_datasuccesss        r<   r   zAppSession.request_reruno  sf    ;;/<<<OOEF&22K" 4#9#9#B#B;#OT
 $$^4""//889R9RS")66*88!-!>!>&00'/4*88&),*L*L&M)66	J #J)V&&':;<".. ""//1%)"
 ,,:::F
 	!!*-r;   c                R    | j                   | j                   j                          yy)zgRequest that the scriptrunner stop execution.

        Does nothing if no scriptrunner exists.
        N)rY   r   rj   s    r<   r   zAppSession.request_script_stop  s'    
 )++- *r;   c                8    | j                   j                          y)z%Clear the user info for this session.N)r\   clearrj   s    r<   clear_user_infozAppSession.clear_user_info  s    r;   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_idrM   session_stateuploaded_file_mgrrc   initial_rerun_datare   fragment_storagepages_managerN)r   rF   rJ   rM   r[   rK   rL   r\   r^   rN   rY   on_eventrr   r   start)r`   r   s     r<   r   zAppSession._create_scriptrunner  s    )ww!..??--"55++1oo!33--

 	##++D,G,GH  "r;   c                    | j                   S r   )r[   rj   s    r<   r   zAppSession.session_state  s    """r;   c                    | j                   j                         t        t        fd      d       }|| j                  j
                  }||k(  S y)Nc                    |    d   k(  S )Nscript_pathr:   )kfilepathpagess    r<   r   z9AppSession._should_rerun_on_file_change.<locals>.<lambda>  s    U1Xm4@r;   T)rN   	get_pagesnextfilterrR   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r;   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)rL   r   r   rX   r   rR   r   _create_file_change_message)r`   r   s     r<   ro   z"AppSession._on_source_file_changed  s`     	  "(I(I((St112%%d&F&F&HIr;   c                $    | j                          y)z:Called when `secrets.file_change_listener` emits a Signal.N)ro   )r`   _s     r<   rs   z#AppSession._on_secrets_file_changed  s     	$$&r;   c                >    | j                   j                  d|       y )NT)retain_lifecycle_msgsfragment_ids_this_run)rO   r   )r`   r   s     r<   _clear_queuezAppSession._clear_queue  s!    !!"&>S 	" 	
r;   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 %	r;   N)rI   r   )	r`   r   r   r   r   r   r   r   r   s	   `````````r<   r   z!AppSession._on_scriptrunner_event  s$    " 	--	 		
r;   c	                   | 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#                  |
       nA|t        jF                  k(  rjt        j*                  | _        | j#                  | j5                  t,        jH                               | j8                  r| j8                  j;                          n|t        jJ                  k(  r|t        d      | j                  t        j                  k(  rGtM        jN                         jP                  jS                  | jT                         | jW                          || _        d| _        n1|t        jX                  k(  r|t        d      | j#                  |       |	t        j                  k(  }| j                  t        j                  k(  }||k7  r | j#                  | j[                                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.).rI   rG   rH   RuntimeErrorrY   r1   r_   rQ   r   r   r3   r6   r5   rR   r   r   _create_new_session_messager   r   !SCRIPT_STOPPED_WITH_COMPILE_ERRORFRAGMENT_STOPPED_WITH_SUCCESSr4   r   FINISHED_SUCCESSFULLY"FINISHED_FRAGMENT_RUN_SUCCESSFULLYFINISHED_WITH_COMPILE_ERROR_create_script_finished_messager]   rS   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   rF   r{   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 -r;   c                    t               }| j                  |j                  _        | j                  t
        j                  k(  |j                  _        |S )z6Create and return a session_status_changed ForwardMsg.)r   rX   session_status_changedrun_on_saverQ   r3   r5   script_is_runningr   s     r<   r  z1AppSession._create_session_status_changed_message  sD    l151B1B"".KK?999 	""4 
r;   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
r;   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   rA   new_sessionscript_run_idrJ   namerN   rM   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_msgre   r#   environment_infostreamlit_versionjoinmapr>   sysversion_infopython_versionr
   SYSTEM	server_ososenvironhas_displayrX   session_statusr  rQ   r3   r5   r  is_hellorF   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''
r;   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_message5  s     l$
r;   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
r;   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_utilrA  rJ   rM   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DEFAULTr1   r_   r   r   )	r`   r   rA  repo	repo_inforepository_namerI  rJ  r   s	            r<   r   z*AppSession._handle_git_information_requestC  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_requestm  s     	<(r;   c                $    | j                          y)z1Tell the ScriptRunner to stop running its script.N)r   rj   s    r<   r   z&AppSession._handle_stop_script_request{  s      "r;   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_resourcer[   rj   s    r<   r   z&AppSession._handle_clear_cache_request  s:     	  "$$&!!#r;   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

        Nr:   rj   s    r<   r   z(AppSession._handle_app_heartbeat_request  s    r;   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)rX   r   r  )r`   	new_values     r<   r   z*AppSession._handle_set_run_on_save_request  s#     &!!$"M"M"OPr;   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_idrK   get_upload_urlsrF   
file_names	file_urlsappendr   r   ra  rb  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
  0O"",,33+33.99.99  0 	!!#&r;   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_responserG   	to_threadr   r   r   execute_deferredurlr   r1   r   r>   	error_msgr   )r`   requestresponserp  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_pathnamerv  )r`   r   r   r   	page_info
page_protos         r<   r  zAppSession._populate_app_pages  sg     ,1;;='i**,J*:J'#,[#9#A#A#s#KJ &/&<J#'/JO ,9r;   r   )ra   r)   rb   r.   rc   r*   rd   zCallable[[], None] | Nonere   r+   rf   
str | NonereturnNone)r  r  )r  zlist[ForwardMsg])r   r   r  r  )r   r'   r  r  )r   BaseExceptionr  r  )r   ClientState | Noner  r  )r   r   r  r  )r  r-   )r   r>   r  r   )r   r~  r  r  )r   r   r  r  )r   list[str] | Noner  r  )NNNNNN)r   zScriptRunner | Noner   r   r   zForwardMsg | Noner   zBaseException | Noner   r  r   r~  r   r  r   dict[PageHash, PageInfo] | Noner  r  )r  r   )NN)r   r>   r   r  r   r  r  r   )r
  z)ForwardMsg.ScriptFinishedStatus.ValueTyper  r   )r   r  r  r   )r_  r   r  r  )r   r   r  r  )rr  r(   r  r  )r   r   r   zdict[PageHash, PageInfo]r  r  )(r7   r8   r9   __doc__rg   rk   rW   rw   r{   r~   ri   r   r   r   r   r   r   r   propertyr   r   ro   rs   r   r   r   r  r   r   r   r   r   r   r   r   r   r   r   r   r  r:   r;   r<   rC   rC   P   s   	$ +/XAXA  3XA "	XA
 $=XA  XA (XA 
XAtV2)6+(>.(#.J
:R.h. #  # #J
'
 *.*.+/'+2615
#
 !
 '	

 (
 )
 %
  0
 /
 

D *.*.+/'+2615iU#iU !iU '	iU
 (iU )iU %iU  0iU /iU 
iUV 3715	KK  0K /	K
 
KZ?	(VV 26).)	)#$Q'(,8	0	0&>	0		0r;   rC   c                    d} t        j                  |       }t        t        j                  |j                               }|Hdj                  d t        j                  j                         D              }t        d| d| d|       |S )Nzclient.toolbarMode, c              3  <   K   | ]  }|j                           y wr   )lower).0r   s     r<   	<genexpr>z$_get_toolbar_mode.<locals>.<genexpr>  s     "P6O17796Os   Config . expects to have one of the following values: . Current value: )	r	   rV   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*^-
 	

 r;   c                    d} t        j                  |       }|du rt        j                  j                  S |du rt        j                  j
                  S g d}t        j                  j                  t        j                  j                  t        j                  j
                  d}||vr#t        d| ddj                  |       d|       ||   S )	Nzclient.showErrorLinksTF)autotruefalser  r  r  r  )	r	   rV   r   ShowErrorLinksSHOW_ERROR_LINKS_TRUESHOW_ERROR_LINKS_FALSESHOW_ERROR_LINKS_AUTOr  r.  )r  r  r  value_to_enums       r<   _get_show_error_linksr    s    (J$$Z0L t$$:::u$$;;; /N%%;;%%;;&&==M
 >)j^ $%%)YY~%>$? @*^-
 	

 &&r;   c                L   t        j                  d      | _        t        j                  d      | _        t        j                  d      | _        t        j                  d      | _        t        j                  d      du rd| _        t               | _        t               | _
        y )Nzbrowser.gatherUsageStatszglobal.maxCachedMessageAgezserver.allowRunOnSavezui.hideTopBarzclient.showSidebarNavigationFT)r	   rV   gather_usage_statsmax_cached_message_ageallow_run_on_savehide_top_barhide_sidebar_navr  toolbar_moder  show_error_links)r   s    r<   r  r    s    #../IJC!'!2!23O!PC"--.EFC((9C78EA#(*C02Cr;   c                   | j                  |      }t        |t              r	 t        j                  |      }|L|0t        |      |k7  r"t        j                  d||t        |             y|D ]  }	 |j                  |        yy# t        j
                  $ 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)a  Parse and populate chart colors from theme config to protobuf message field.

    Parameters
    ----------
    theme_opts
        Dictionary of theme options from config.get_options_for_section.
    config_key
        The key in theme_opts to look for (e.g., "chartCategoricalColors").
    msg_field
        The protobuf repeated string field to append colors to.
    required_length
        If provided, log an error if the colors array doesn't have this exact length.
    z/Failed to parse the theme.%s config option: %s.rB  NzbConfig theme.%s should have %s color values, but got %s. Defaulting to Streamlit's default colors.)get
isinstancer>   jsonloadsJSONDecodeErrorr1   r   rR  errorri  r   )
theme_optsr  	msg_fieldrequired_lengthcolorsr   colors          r<    _parse_and_populate_chart_colorsr    s    & ^^J'F
 &#		ZZ'F &3v;/+IMMHF E  '   ## 	OOA	   F	.  E	    s/   B 2CB?B::B?	C.C))C.c           	     x	   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/                  |         tG        |d| jH                         tG        |d| jJ                  d       tG        |d | jL                  d       y # t*        $ r%}t        j                  d
||       d }Y d }~cd }~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)!Nc              3  $   K   | ]  }|d u  
 y wr   r:   )r  vals     r<   r  z&_populate_theme_msg.<locals>.<genexpr>T  s     
6"533$;"5s   >
   basefontcodeFont	fontFacesheadingFontheadingFontSizesheadingFontWeightschartDivergingColors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.rB  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  r  
   )r  r  )'r	   get_options_for_sectionallvaluesrw  setattrr"   	BaseThemer"  r%  r  r1   r   listr  r  r!   r  r>   r  r  r   
font_facesri  r   r   stripr  endswithrR  r  heading_font_sizesintrangeheading_font_weightsr  chart_categorical_colorschart_sequential_colorschart_diverging_colors)r   sectionr  option_name
option_valbase_mapr  r  r   	font_facer  sizer  r   heading_weightsr  s                   r<   r  r  R  s   //8J

6*"3"3"5
66#-#3#3#5Z  &C{3Z@' $64 $$""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!A$$++,@A 	($	/#s+?'@1'D3457 
 /r2cU())6
 
 &F((//7 & %,c.J.J %##	 %""	a  	OOX  
 J	  L    *  *c&   
 &*"*$  S      	(OOa$  
 $( 	(6  U    s   N *AO
O< P-Q 5R	O
%OO
	O9O44O9<	P*P%%P*-	Q6QQ	R
%RR
	R9R44R9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r;   )r  r>   )r  zConfig.ToolbarMode.ValueType)r  zConfig.ShowErrorLinks.ValueType)r   r   r  r  r   )
r  zdict[str, Any]r  r>   r  z!RepeatedScalarFieldContainer[str]r  z
int | Noner  r  )theme)r   r   r  r>   r  r  )r   r   r  r  )a
__future__r   rG   r  r5  r0  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%   #google.protobuf.internal.containersr&   streamlit.proto.BackMsg_pb2r'   r(   streamlit.runtime.script_datar)   +streamlit.runtime.scriptrunner.script_cacher*   7streamlit.runtime.scriptrunner_utils.script_run_contextr+   rZ   r-   'streamlit.runtime.uploaded_file_managerr.   streamlit.source_utilr/   r0   r7   r1   __annotations__r3   rA   rC   r  r  r  r  r  r+  r:   r;   r<   <module>r     s   #   	 
   , , 1 6 6 / / ' 7 @ 5 /  & ? M 7 8 U U 7 @ / 6 1(PH8GT4K8H% %.d .
J0 J0d '43 #'	888 18  	8
 
8vtn5r;   