o
    ,&]i                     @  s:  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  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
rd 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" d"eZTd9d%d&ZUG d'd( d(ZVd:d*d+ZWd;d/d0ZXd<d=d4d5ZYd>d7d8ZZdS )?    )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                   @  s   e Zd ZdZdZdZdS )AppSessionStateAPP_NOT_RUNNINGAPP_IS_RUNNINGSHUTDOWN_REQUESTEDN)__name__
__module____qualname__r0   r1   r2    r6   r6   [/var/www/html/IGF-ODF-V3/venv/lib/python3.10/site-packages/streamlit/runtime/app_session.pyr/   B   s    r/   returnstrc                   C  s   t t S )z5Randomly generate a unique ID for a script execution.)r9   uuiduuid4r6   r6   r6   r7   _generate_scriptrun_idH      r<   c                   @  s  e Zd ZdZ	d{d|ddZd}ddZd}ddZd}ddZd~ddZd}ddZ	dd d!Z
dd#d$Zdd'd(Zdd+d,Zd}d-d.Zd}d/d0Zdd3d4Zedd6d7Zdd;d<Zd{dd=d>ZddAdBZd{ddEdFZ						dddRdSZ						dddTdUZddVdWZddXdYZ		dddZd[Zdd^d_Zdd`daZd}dbdcZ	d{ddddeZd}dfdgZ d}dhdiZ!d}djdkZ"ddmdnZ#ddqdrZ$ddudvZ%ddydzZ&dS )
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.

    Nscript_datar'   uploaded_file_managerr+   script_cacher(   message_enqueued_callbackCallable[[], None] | None	user_infodict[str, str | bool | None]session_id_override
str | Noner8   Nonec                 C  s   |pt t | _t | _|| _|| _|| _	t
|j| j	| _t | _|| _tj| _t | _d| _d| _d| _tddkrB|   td| _d| _ddlm} | | _|| _ d| _!t" | _#t$%d| j dS )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))&r9   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_callbackr/   r0   _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)selfr?   r@   rA   rB   rD   rF   r*   r6   r6   r7   __init__Y   s2   -
zAppSession.__init__c                 C     |    dS )zGEnsure that we call shutdown() when an AppSession is garbage collected.N)shutdownrd   r6   r6   r7   __del__   r=   zAppSession.__del__c                 C  sH   | j du rt| j| _ | j | j tj| jdd| _tj	
| j dS )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)rW   r#   rR   register_file_change_callback_on_source_file_changedr   on_config_parsedrX   r   file_change_listenerconnect_on_secrets_file_changedrh   r6   r6   r7   r[      s   
z!AppSession.register_file_watchersc                 C  s\   | j dur
| j   | jdur|   | jdur|   tj| j d| _ d| _d| _dS )zJDisconnect the file watcher handlers registered by register_file_watchers.N)rW   closerX   rY   r   rn   
disconnectrp   rh   r6   r6   r7   disconnect_file_watchers   s   




z#AppSession.disconnect_file_watcherslist[ForwardMsg]c                 C  s
   | 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.

        )rS   flushrh   r6   r6   r7   flush_browser_queue   s   
zAppSession.flush_browser_queuec                 C  sp   | j tjkr6td| j | j| j t	 r(t
 }|j| j |j  |   tj| _ |   dS dS )ziShut down the AppSession.

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

        zShutting down (id=%s)N)rU   r/   r2   r.   rc   rJ   rO   remove_session_filesr
   existsget_instancemedia_file_mgrclear_session_refsremove_orphaned_filesrequest_script_stoprs   )rd   rtr6   r6   r7   rg      s   
zAppSession.shutdownmsgr   c                 C  s0   | j r| j |_| j| | jr|   dS dS )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)ra   debug_last_backmsg_idrS   enqueuerT   rd   r   r6   r6   r7   _enqueue_forward_msg
  s   zAppSession._enqueue_forward_msgr%   c              
   C  s@  z| d}|dkr|jr|j| _| |j W dS |dkr%|   W dS |dkr0|   W dS |dkr;|   W dS |dkrH| |j	 W dS |dkrS| 
  W dS |dkr`| |j W dS |d	krzt| |j}|d
|jj  W dS td| W dS  ty } ztd | | W Y d}~dS d}~w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   ra   _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   rK   create_task_handle_deferred_file_requestr   set_namefile_idr.   warning	Exception	exceptionhandle_backmsg_exception)rd   r   msg_typetaskexr6   r6   r7   handle_backmsg  s:   


zAppSession.handle_backmsgeBaseExceptionc                   sN    jtj j jtjdd  jtj j fdd dS )zGHandle an Exception raised while processing a BackMsg from the browser. )page_script_hashc                     s     S N)r   _create_exception_messager6   r   rd   r6   r7   <lambda>]      z5AppSession.handle_backmsg_exception.<locals>.<lambda>N)_on_scriptrunner_eventr]   r   SCRIPT_STOPPED_WITH_SUCCESSSCRIPT_STARTEDrM   call_soon_threadsafe)rd   r   r6   r   r7   r   C  s   	z#AppSession.handle_backmsg_exceptionclient_stateClientState | Nonec              
   C  s   | j tjkrtd dS |rI|j}|r"| j|s"td| dS |	dr/| j
j|j t|j|j|j|j|r<|nd|jt|j|jd}nt }| jdurnttdrd|jsd| j  d| _n
| j|}|rndS | | dS )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)rU   r/   r2   r.   r   r   rb   containsinfoHasFieldrV   r   CopyFromr   r   r   r   r   r   setr   r]   boolr   rZ   request_stoprequest_rerun_create_scriptrunner)rd   r   r   
rerun_datasuccessr6   r6   r7   r   `  sF   




zAppSession.request_rerunc                 C  s   | j dur| j   dS dS )zgRequest that the scriptrunner stop execution.

        Does nothing if no scriptrunner exists.
        N)r]   r   rh   r6   r6   r7   r}     s   
zAppSession.request_script_stopc                 C  s   | j   dS )z%Clear the user info for this session.N)r`   clearrh   r6   r6   r7   clear_user_info  s   zAppSession.clear_user_infoinitial_rerun_datar   c                 C  sL   t | j| jj| j| j| j|| j| j| j	d	| _
| j
j| j | j
  dS )z;Create and run a new ScriptRunner with the given RerunData.)	
session_idrQ   session_stateuploaded_file_mgrrA   r   rD   fragment_storagepages_managerN)r   rJ   rN   rQ   r_   rO   rP   r`   rb   rR   r]   on_eventro   r   start)rd   r   r6   r6   r7   r     s   zAppSession._create_scriptrunnerr*   c                 C  s   | j S r   )r_   rh   r6   r6   r7   r     s   zAppSession.session_statefilepathr9   r   c                   s@   | j  tt fddd }|d ur| jj}||kS dS )Nc                   s   |  d  kS )Nscript_pathr6   )kr   pagesr6   r7   r     r   z9AppSession._should_rerun_on_file_change.<locals>.<lambda>T)rR   	get_pagesnextfilterrV   r   )rd   r   changed_page_script_hashcurrent_page_script_hashr6   r   r7   _should_rerun_on_file_change  s   
z'AppSession._should_rerun_on_file_changec                 C  sH   | j   |dur| |sdS | jr| | j dS | |   dS )zfOne of our source files changed. Clear the cache and schedule a rerun if
        appropriate.
        N)rP   r   r   r\   r   rV   r   _create_file_change_message)rd   r   r6   r6   r7   rl     s   
z"AppSession._on_source_file_changed_r   c                 C  rf   )z:Called when `secrets.file_change_listener` emits a Signal.N)rl   )rd   r   r6   r6   r7   rp     s   
z#AppSession._on_secrets_file_changedfragment_ids_this_runlist[str] | Nonec                 C  s   | j jd|d d S )NT)retain_lifecycle_msgsr   )rS   r   )rd   r   r6   r6   r7   _clear_queue  s   
zAppSession._clear_queuesenderScriptRunner | Noneeventr   forward_msgForwardMsg | Noner   BaseException | Noner   r   dict[PageHash, PageInfo] | Nonec	           	        s(   j  f	dd dS )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                
     s     S r   )(_handle_scriptrunner_event_on_event_loopr6   	r   r   r   r   r   r   r   rd   r   r6   r7   r     s    z3AppSession._on_scriptrunner_event.<locals>.<lambda>N)rM   r   )	rd   r   r   r   r   r   r   r   r   r6   r   r7   r     s   z!AppSession._on_scriptrunner_eventc	                 C  s:  | j t krtd|| jurtd| dS | j}	|tj	krN| jt
jkr*t
j| _|du r2td|| jjkr<|| j_| | | |||}
| |
 n|tjtjtjhv r| jt
jkrbt
j| _|tjkrktj}n|tjkrttj}ntj}| | | d| _|tjtjhv r| jr| j  | j  nj|du rtdt }
t |
j!j"| | |
 nQ|tj#krt
j| _| | tj$ | jr| j  n6|tj%kr|du rtd| jt
jkrt&' j()| j* || _d| _n|tj+kr|du rtd| | |	t
jk}| jt
jk}||kr| | ,  dS dS )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.)-rM   rK   rL   RuntimeErrorr]   r.   rc   rU   r   r   r/   r2   r1   rV   r   r   _create_new_session_messager   r   !SCRIPT_STOPPED_WITH_COMPILE_ERRORFRAGMENT_STOPPED_WITH_SUCCESSr0   r   FINISHED_SUCCESSFULLY"FINISHED_FRAGMENT_RUN_SUCCESSFULLYFINISHED_WITH_COMPILE_ERROR_create_script_finished_messagera   rW   update_watched_modulesupdate_watched_pagesexception_utilsmarshallsession_eventscript_compilation_exceptionSCRIPT_STOPPED_FOR_RERUNFINISHED_EARLY_FOR_RERUNSHUTDOWNr
   ry   rz   r{   rJ   ENQUEUE_FORWARD_MSG&_create_session_status_changed_message)rd   r   r   r   r   r   r   r   r   
prev_stater   statusapp_was_runningapp_is_runningr6   r6   r7   r     s   3












z3AppSession._handle_scriptrunner_event_on_event_loopc                 C  s$   t  }| j|j_| jtjk|j_|S )z6Create and return a session_status_changed ForwardMsg.)r   r\   session_status_changedrun_on_saverU   r/   r1   script_is_runningr   r6   r6   r7   r     s
   

z1AppSession._create_session_status_changed_messagec                 C  s   t  }d|j_|S )z8Create and return a 'script_changed_on_disk' ForwardMsg.T)r   r   script_changed_on_diskr   r6   r6   r7   r     s   z&AppSession._create_file_change_messagec                 C  s  t  }t |j_| jj|j_| jj|j_| jj|j_||j_	|r'|jj
| | |j|p1| 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jdtjjj  t|jjjjdtjjj  t|jjjjdtjjj  |jj}t|j t|j _!d"t#t$t%j&|j _'t(j)|j _*dt+j,v pdt+j,v |j _-| j.|j/_0| j1t2j3k|j/_4| jj5|_5| j6|_7|S )z+Create and return a new_session ForwardMsg.ztheme..DISPLAYWAYLAND_DISPLAY)8r   r<   new_sessionscript_run_idrN   namerR   rQ   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_msgrD   r"   environment_infostreamlit_versionjoinmapr9   sysversion_infopython_versionr	   SYSTEM	server_ososenvironhas_displayr\   session_statusr   rU   r/   r1   r   is_hellorJ   r   )rd   r   r   r   r   imsgr6   r6   r7   r     s\   


	




z&AppSession._create_new_session_messager   )ForwardMsg.ScriptFinishedStatus.ValueTypec                 C  s   t  }||_|S )z/Create and return a script_finished ForwardMsg.)r   script_finished)rd   r   r   r6   r6   r7   r   %  s   z*AppSession._create_script_finished_messagec                 C  s   t  }t|jjj| |S )z*Create and return an Exception ForwardMsg.)r   r   r   deltanew_elementr   )rd   r   r   r6   r6   r7   r   -  s   z$AppSession._create_exception_messagec           	   
   C  s$  t  }ztddlm} || jj}| }|d u rW d S |\}}}|d}||j_||j_	||j_
|jp5g |jjd d < |jp@g |jjd d < |jrQtjj|j_n|jrbt|jdkrbtjj|j_ntjj|j_td||| | | W d S  ty } ztjd|d W Y d }~d S d }~ww )Nr   )GitRepoz.gitz7Git information found. Name: %s, Branch: %s, Module: %sz+Obtaining Git information produced an errorexc_info)r   streamlit.git_utilr-  rN   rQ   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.   rc   r   r   )	rd   r   r-  repo	repo_inforepository_namer5  r6  r   r6   r6   r7   r   3  s<   

z*AppSession._handle_git_information_requestc                 C  s   |  | dS )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   )rd   r   r6   r6   r7   r   ]  s   z'AppSession._handle_rerun_script_requestc                 C  rf   )z1Tell the ScriptRunner to stop running its script.N)r}   rh   r6   r6   r7   r   k  r=   z&AppSession._handle_stop_script_requestc                 C  s"   t j  t j  | j  dS )zjClear this app's cache.

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

        N)r   
cache_datar   cache_resourcer_   rh   r6   r6   r7   r   o  s   

z&AppSession._handle_clear_cache_requestc                 C  s   dS )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

        Nr6   rh   r6   r6   r7   r   y  s   	z(AppSession._handle_app_heartbeat_request	new_valuec                 C  s   || _ | |   dS )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)r\   r   r   )rd   rF  r6   r6   r7   r     s   z*AppSession._handle_set_run_on_save_requestr   r   c                 C  sX   t  }|j|j_| j| j|j}|D ]}|jj	t
|j|j|jd q| | dS )z6Handle a file_urls_request BackMsg sent by the client.)r   
upload_url
delete_urlN)r   
request_idfile_urls_responseresponse_idrO   get_upload_urlsrJ   
file_names	file_urlsappendr   r   rG  rH  r   )rd   r   r   upload_url_infosupload_url_infor6   r6   r7   r     s   
z$AppSession._handle_file_urls_requestrequestr&   c              
     s   t  }|j|j_ztt jj|jI dH }||j_	W n t
y< } ztd|j t||j_W Y d}~nd}~ww | | dS )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_responserK   	to_threadr
   ry   rz   execute_deferredurlr   r.   r   r9   	error_msgr   )rd   rR  responserV  r   r6   r6   r7   r     s"   


z(AppSession._handle_deferred_file_requestr   dict[PageHash, PageInfo]c                 C  sL   |  D ]\}}|j }||_|d dd|_|d |_|d |_qd S )Nr   r    icon)items	app_pagesaddr   replacer   url_pathnamer[  )rd   r   r   r   	page_info
page_protor6   r6   r7   r
    s   

zAppSession._populate_app_pagesr   )r?   r'   r@   r+   rA   r(   rB   rC   rD   rE   rF   rG   r8   rH   )r8   rH   )r8   rt   )r   r   r8   rH   )r   r%   r8   rH   )r   r   r8   rH   )r   r   r8   rH   )r   r   r8   rH   )r8   r*   )r   r9   r8   r   )r   rG   r8   rH   )r   r   r8   rH   )r   r   r8   rH   )NNNNNN)r   r   r   r   r   r   r   r   r   r   r   rG   r   r   r   r   r8   rH   )r8   r   )NN)r   r9   r   r   r   r   r8   r   )r   r)  r8   r   )r   r   r8   r   )rF  r   r8   rH   )r   r   r8   rH   )rR  r&   r8   rH   )r   r   r   rY  r8   rH   )'r3   r4   r5   __doc__re   ri   r[   rs   rv   rg   r   r   r   r   r}   r   r   propertyr   r   rl   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r
  r6   r6   r6   r7   r>   M   sl    
Z






%

T



	" 
+
		
M

+






r>   Config.ToolbarMode.ValueTypec                  C  s^   d} t | }ttj| }|d u r-ddd tj D }td| d| d| |S )Nzclient.toolbarModez, c                 s  s    | ]}|  V  qd S r   )lower).0r   r6   r6   r7   	<genexpr>      z$_get_toolbar_mode.<locals>.<genexpr>zConfig z. expects to have one of the following values: z. Current value: )	r   rZ   getattrr   ToolbarModeupperr  keys
ValueError)
config_keyconfig_value
enum_valueallowed_valuesr6   r6   r7   _get_toolbar_mode  s   

rs  r   r   rH   c                 C  sP   t d| _t d| _t d| _t d| _t ddu r"d| _t | _d S )Nzbrowser.gatherUsageStatszglobal.maxCachedMessageAgezserver.allowRunOnSavezui.hideTopBarzclient.showSidebarNavigationFT)	r   rZ   gather_usage_statsmax_cached_message_ageallow_run_on_savehide_top_barhide_sidebar_navrs  toolbar_mode)r   r6   r6   r7   r    s   r  themer   sectionc                 C  s  t |}tdd | D rd S | D ]\}}|dvr*|d ur*t| t|| q| jj| jj	d}|
dd }|d urS||vrNtd|t|  n|| | _t| |
dd |
dd |
d	d |} |
d
d }t|trzt|}W n ty } ztjd||d d }W Y d }~nd }~ww |d ur|D ]7}	zd|	v rt|	d |	d< |	d= | jt|	t  W q ty } ztjd|	|d W Y d }~qd }~ww |
dd }
t|
tr|
  }
|
dr|
gd }
n%zt|
}
W n ty } ztjd|
|d d }
W Y d }~nd }~ww |
d urX|
r%t|
dkr.tdt|
 |
D ]'}z	| j| W q0 tyW } ztjd||d W Y d }~q0d }~ww |
dd }t|trzt|}W n ty } ztjd||d d }W Y d }~nd }~ww t|t rt!ddD ]	}| j"| qnRt|tr|rt|dkrtdt| |d d dgdt|   }|D ]'}z	| j"| W q ty } ztjd||d W Y d }~qd }~ww |
dd }t|tr#zt|}W n tj#y" } ztjd||d d }W Y d }~nd }~ww |d urR|D ]'}z	| j$| W q* tyQ } ztjd||d W Y d }~q*d }~ww |
dd }t|trzt|}W n tj#y } ztjd ||d d }W Y d }~nd }~ww |d urt|d!krt%d"t| |D ])}z	| j&| W q ty } ztjd ||d W Y d }~qd }~ww d S d S )#Nc                 s  s    | ]}|d u V  qd S r   r6   )rg  valr6   r6   r7   rh    ri  z&_populate_theme_msg.<locals>.<genexpr>>	   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valuesr\  setattrr!   	BaseThemer  r  getr.   r   listrm  r}  r    
isinstancer9   jsonloadsr   
font_facesrO  r   r   striprf  endswithr>  rn  heading_font_sizesintrangeheading_font_weightsJSONDecodeErrorchart_categorical_colorserrorchart_sequential_colors)r   r{  
theme_optsoption_name
option_valbase_mapr}  r  r   	font_facer  sizer  r   heading_weightsr  r  colorr  r6   r6   r7   r    st  











r  r   c                 C  s$   t  }|j| _|j| _|j| _d S r   )r   instanceinstallation_idinstallation_id_v3installation_id_v4)r   instr6   r6   r7   r    s   r  )r8   r9   )r8   re  )r   r   r8   rH   )rz  )r   r   r{  r9   r8   rH   )r   r   r8   rH   )[
__future__r   rK   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(   r^   r*   'streamlit.runtime.uploaded_file_managerr+   streamlit.source_utilr,   r-   r3   r.   __annotations__r/   r<   r>   rs  r  r  r  r6   r6   r6   r7   <module>   sh   
       


 a