o
    Zh                     @  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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l0m1Z1 d dl2m3Z3 d dl4m5Z5m6Z6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? e
rd dl@mAZA d dlBmCZC d dlDmEZE d dlFmGZG d dlHmIZI d dlJmKZKmLZL eeMZNdeOd< G dd  d eZPd7d#d$ZQG d%d& d&ZRd8d(d)ZSd9d-d.ZTd:d;d2d3ZUd<d5d6ZVdS )=    )annotationsN)Enum)TYPE_CHECKINGAnyCallable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)to_snake_case)STREAMLIT_VERSION_STRING)LocalSourcesWatcher)BackMsg)
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__r.   r/   r0    r4   r4   ^/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/runtime/app_session.pyr-   ?   s    r-   returnstrc                   C  s   t t S )z5Randomly generate a unique ID for a script execution.)r7   uuiduuid4r4   r4   r4   r5   _generate_scriptrun_idE      r:   c                   @  s  e Zd ZdZ	dwdxddZdyddZdyddZdyddZdzddZdyddZ	d{d d!Z
d|d#d$Zd}d'd(Zd~d+d,Zdyd-d.Zdyd/d0Zdd3d4Zedd6d7Zdd;d<Zdwdd=d>ZddAdBZdwddEdFZ						dddRdSZ						dddTdUZddVdWZddXdYZ		dddZd[Zdd^d_Zdd`daZdydbdcZ	dwd~dddeZdydfdgZ dydhdiZ!dydjdkZ"ddmdnZ#ddqdrZ$ddudv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 | Noner6   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))&r7   r8   r9   idasyncioget_running_loop_event_loop_script_data_uploaded_file_mgr_script_cacher   main_script_path_pages_managerr   _browser_queue_message_enqueued_callbackr-   r.   _stater   _client_state_local_sources_watcher_stop_config_listener_stop_pages_listenerr	   
get_optionregister_file_watchers_run_on_save_scriptrunnerstreamlit.runtime.stater(   _session_state
_user_info_debug_last_backmsg_idr   _fragment_storager,   debug)selfr=   r>   r?   r@   rB   rD   r(   r4   r4   r5   __init__V   s2   -
zAppSession.__init__c                 C     |    dS )zGEnsure that we call shutdown() when an AppSession is garbage collected.N)shutdownrb   r4   r4   r5   __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)rU   r#   rP   register_file_change_callback_on_source_file_changedr	   on_config_parsedrV   r    file_change_listenerconnect_on_secrets_file_changedrf   r4   r4   r5   rY      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)rU   closerV   rW   r    rl   
disconnectrn   rf   r4   r4   r5   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.

        )rQ   flushrf   r4   r4   r5   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)rS   r-   r0   r,   ra   rH   rM   remove_session_filesr   existsget_instancemedia_file_mgrclear_session_refsremove_orphaned_filesrequest_script_stoprq   )rb   rtr4   r4   r5   re      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)r_   debug_last_backmsg_idrQ   enqueuerR   rb   r}   r4   r4   r5   _enqueue_forward_msg  s   zAppSession._enqueue_forward_msgr$   c              
   C  s  zh| 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 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_requestz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   r,   warning	Exception	exceptionhandle_backmsg_exception)rb   r}   msg_typeexr4   r4   r5   handle_backmsg  s0   

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_messager4   r   rb   r4   r5   <lambda>Q      z5AppSession.handle_backmsg_exception.<locals>.<lambda>N)_on_scriptrunner_eventr[   r   SCRIPT_STOPPED_WITH_SUCCESSSCRIPT_STARTEDrK   call_soon_threadsafe)rb   r   r4   r   r5   r   7  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)rS   r-   r0   r,   r   r   r`   containsinfoHasFieldrT   r   CopyFromr   r   r   r   r   r   setr   r[   boolr	   rX   request_stoprequest_rerun_create_scriptrunner)rb   r   r   
rerun_datasuccessr4   r4   r5   r   T  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   rf   r4   r4   r5   r{     s   
zAppSession.request_script_stopc                 C  s   | j   dS )z%Clear the user info for this session.N)r^   clearrf   r4   r4   r5   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_idrO   session_stateuploaded_file_mgrr?   r   rB   fragment_storagepages_managerN)r   rH   rL   rO   r]   rM   rN   r^   r`   rP   r[   on_eventrm   r   start)rb   r   r4   r4   r5   r     s   zAppSession._create_scriptrunnerr(   c                 C  s   | j S r   )r]   rf   r4   r4   r5   r     s   zAppSession.session_statefilepathr7   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_pathr4   )kr   pagesr4   r5   r     r   z9AppSession._should_rerun_on_file_change.<locals>.<lambda>T)rP   	get_pagesnextfilterrT   r   )rb   r   changed_page_script_hashcurrent_page_script_hashr4   r   r5   _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)rN   r   r   rZ   r   rT   r   _create_file_change_message)rb   r   r4   r4   r5   rj     s   
z"AppSession._on_source_file_changed_r   c                 C  rd   )z:Called when `secrets.file_change_listener` emits a Signal.N)rj   )rb   r   r4   r4   r5   rn     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   )rQ   r   )rb   r   r4   r4   r5   _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_loopr4   	r   r   r   r   r   r   r   rb   r   r4   r5   r     s    z3AppSession._on_scriptrunner_event.<locals>.<lambda>N)rK   r   )	rb   r   r   r   r   r   r   r   r   r4   r   r5   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.)-rK   rI   rJ   RuntimeErrorr[   r,   ra   rS   r   r   r-   r0   r/   rT   r   r   _create_new_session_messager   r   !SCRIPT_STOPPED_WITH_COMPILE_ERRORFRAGMENT_STOPPED_WITH_SUCCESSr.   r   FINISHED_SUCCESSFULLY"FINISHED_FRAGMENT_RUN_SUCCESSFULLYFINISHED_WITH_COMPILE_ERROR_create_script_finished_messager_   rU   update_watched_modulesupdate_watched_pagesexception_utilsmarshallsession_eventscript_compilation_exceptionSCRIPT_STOPPED_FOR_RERUNFINISHED_EARLY_FOR_RERUNSHUTDOWNr   rw   rx   ry   rH   ENQUEUE_FORWARD_MSG&_create_session_status_changed_message)rb   r   r   r   r   r   r   r   r   
prev_stater}   statusapp_was_runningapp_is_runningr4   r4   r5   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   rZ   session_status_changedrun_on_saverS   r-   r/   script_is_runningr   r4   r4   r5   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   r4   r4   r5   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  |jj}t|j t|j_dtttj |j_!t"j#|j_$dt%j&v psdt%j&v |j_'| j(|j)_*| j+t,j-k|j)_.| jj/|_/| j0|_1|S )z+Create and return a new_session ForwardMsg.ztheme..DISPLAYWAYLAND_DISPLAY)2r   r:   new_sessionscript_run_idrL   namerP   rO   main_script_hashr   r   extend_populate_app_pagesr   _populate_config_msgr	   _populate_theme_msgcustom_themesidebarCustomThemeCategoriesSIDEBARvalue
initialize_populate_user_info_msgrB   r"   environment_infostreamlit_versionjoinmapr7   sysversion_infopython_versionr
   SYSTEM	server_ososenvironhas_displayrZ   session_statusr   rS   r-   r/   r   is_hellorH   r   )rb   r   r   r   r}   imsgr4   r4   r5   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)rb   r   r}   r4   r4   r5   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   )rb   r   r}   r4   r4   r5   r   	  s   z$AppSession._create_exception_messagec           	   
   C  s  t  }zld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_| | W d S  ty } ztjd|d W Y d }~d S d }~ww )Nr   )GitRepoz.gitz+Obtaining Git information produced an errorexc_info)r   streamlit.git_utilr  rL   rO   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,   ra   )	rb   r}   r  repo	repo_inforepository_namer&  r'  r   r4   r4   r5   r     s0   

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   )rb   r   r4   r4   r5   r   3  s   z'AppSession._handle_rerun_script_requestc                 C  rd   )z1Tell the ScriptRunner to stop running its script.N)r{   rf   r4   r4   r5   r   A  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]   rf   r4   r4   r5   r   E  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

        Nr4   rf   r4   r4   r5   r   O  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)rZ   r   r   )rb   r7  r4   r4   r5   r   Z  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.)file_id
upload_url
delete_urlN)r   
request_idfile_urls_responseresponse_idrM   get_upload_urlsrH   
file_names	file_urlsappendr   r8  r9  r:  r   )rb   r   r}   upload_url_infosupload_url_infor4   r4   r5   r   h  s   
z$AppSession._handle_file_urls_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_pathnamerF  )rb   r}   r   r   	page_info
page_protor4   r4   r5   r  |  s   

zAppSession._populate_app_pagesr   )r=   r%   r>   r)   r?   r&   r@   rA   rB   rC   rD   rE   r6   rF   )r6   rF   )r6   rr   )r}   r   r6   rF   )r}   r$   r6   rF   )r   r   r6   rF   )r   r   r6   rF   )r   r   r6   rF   )r6   r(   )r   r7   r6   r   )r   rE   r6   rF   )r   r   r6   rF   )r   r   r6   rF   )NNNNNN)r   r   r   r   r   r   r   r   r   r   r   rE   r   r   r   r   r6   rF   )r6   r   )NN)r   r7   r   r   r   r   r6   r   )r   r  r6   r   )r   r   r6   r   )r7  r   r6   rF   )r   r   r6   rF   )r}   r   r   rD  r6   rF   )&r1   r2   r3   __doc__rc   rg   rY   rq   rt   re   r   r   r   r   r{   r   r   propertyr   r   rj   rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r4   r4   r4   r5   r<   J   sj    
Z








T



	" 
+
		
5

%





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   r4   r4   r5   	<genexpr>      z$_get_toolbar_mode.<locals>.<genexpr>zConfig z. expects to have one of the following values: z. Current value: )	r	   rX   getattrr   ToolbarModeupperr  keys
ValueError)
config_keyconfig_value
enum_valueallowed_valuesr4   r4   r5   _get_toolbar_mode  s   

r^  r}   r   rF   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	   rX   gather_usage_statsmax_cached_message_ageallow_run_on_savehide_top_barhide_sidebar_navr^  toolbar_mode)r}   r4   r4   r5   r    s   r  themer   sectionc                 C  sz  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|| | _|
dd }|r^|| _|
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rO|rt|dkr%tdt| |D ]'}z	| j| W q' tyN }	 ztjd||	d
 W Y d }	~	q'd }	~	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rI|D ]'}z	| j$| W q! tyH }	 ztjd||	d
 W Y d }	~	q!d }	~	ww |
dd }t|tr{zt|}W n tj#yz }	 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   r4   )rR  valr4   r4   r5   rS    rT  z&_populate_theme_msg.<locals>.<genexpr>>   basefont	fontFacesheadingFontSizesheadingFontWeightschartSequentialColorschartCategoricalColors)lightdarkrh  zb"%s" is an invalid value for theme.base. Allowed values include %s. Setting theme.base to "light".ri  rj  zFFailed to parse the theme.fontFaces config option with json.loads: %s.r  weightweight_rangez6Failed to parse the theme.fontFaces config option: %s.rk  )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.rl  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.rn  zCFailed to parse the theme.chartCategoricalColors config option: %s.rm  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valuesrG  setattrr!   	BaseThemeLIGHTDARKgetr,   r   listrX  rh  	body_font
isinstancer7   jsonloadsr   
font_facesrA  r   r   striprQ  endswithr/  rY  heading_font_sizesintrangeheading_font_weightsJSONDecodeErrorchart_categorical_colorserrorchart_sequential_colors)r}   rf  
theme_optsoption_name
option_valbase_maprh  r  r  r   	font_facer  sizer  r   heading_weightsrq  r  colorr  r4   r4   r5   r    sl  









r  r   c                 C  s$   t  }|j| _|j| _|j| _d S r   )r   instanceinstallation_idinstallation_id_v3installation_id_v4)r}   instr4   r4   r5   r
    s   r
  )r6   r7   )r6   rP  )r}   r   r6   rF   )re  )r}   r   rf  r7   r6   rF   )r}   r   r6   rF   )W
__future__r   rI   r  r  r  r8   enumr   typingr   r   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.string_utilr!   streamlit.versionr"   streamlit.watcherr#   streamlit.proto.BackMsg_pb2r$   streamlit.runtime.script_datar%   +streamlit.runtime.scriptrunner.script_cacher&   r\   r(   'streamlit.runtime.uploaded_file_managerr)   streamlit.source_utilr*   r+   r1   r,   __annotations__r-   r:   r<   r^  r  r  r
  r4   r4   r4   r5   <module>   sb   
      
I

 [