Ë
    úmxis  ã                  ód  — 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mZmZ d dl	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 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! 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-m.Z. d dl/m0Z0m1Z1 d dl2m3Z3 er*d dl4m5Z5 d dl6m7Z7 d dl8m9Z9 d dl:m;Z; d dl<m=Z= d dl>m?Z? d dl@mAZA dZBdeCd<   ejˆ                  dk(  rd ndZEdeCd!<    eeF«      ZGdeCd"<    G d#„ d$eH«      ZI ed%¬&«       G d'„ d(«      «       ZJ G d)„ d*e
«      ZK G d+„ d,e«      ZL G d-„ d.«      ZMy)/é    )ÚannotationsN)Ú	dataclassÚfield)ÚEnum)ÚTYPE_CHECKINGÚFinalÚ
NamedTuple)ÚLocalComponentRegistry)ÚBidiComponentManager)Ú
get_logger)Ú
ForwardMsg)Ú
AppSession)Úget_data_cache_stats_providerÚ!get_resource_cache_stats_provider)ÚLocalDiskCacheStorageManager)ÚMediaFileManager)ÚMemorySessionStorage)Ú
ScriptData)ÚScriptCache)ÚActiveSessionInfoÚSessionClientÚSessionClientDisconnectedErrorÚSessionManagerÚSessionStorage)ÚSCRIPT_RUN_WITHOUT_ERRORS_KEYÚSessionStateStatProvider)ÚStatsManagerÚStatsProvider)ÚWebsocketSessionManager)Ú	Awaitable)ÚBaseComponentRegistry)ÚBackMsg)ÚCacheStorageManager)ÚMediaFileStorage)ÚUserInfoType)ÚUploadedFileManageré<   r   ÚSCRIPT_RUN_CHECK_TIMEOUTÚwin32g      à?Ú_SIGNAL_CHECK_INTERVALÚ_LOGGERc                  ó   — e Zd ZdZy)ÚRuntimeStoppedErrorz;Raised by operations on a Runtime instance that is stopped.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úP/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/runtime/runtime.pyr-   r-   N   s   „ ÚEr3   r-   T)Úfrozenc                  óÆ   — e Zd ZU dZded<   ded<   ded<   ded	<    ee¬
«      Zded<    ee¬
«      Z	ded<    ee
¬
«      Zded<   eZded<    ee¬
«      Zded<   dZded<   y)ÚRuntimeConfigz$Config options for StreamlitRuntime.ÚstrÚscript_pathú
str | NoneÚcommand_liner$   Úmedia_file_storager&   Úuploaded_file_manager)Údefault_factoryr#   Úcache_storage_managerr!   Úcomponent_registryr   Úbidi_component_registryztype[SessionManager]Úsession_manager_classr   Úsession_storageFÚboolÚis_helloN)r.   r/   r0   r1   Ú__annotations__r   r   r?   r
   r@   r   rA   r   rB   r   rC   rE   r2   r3   r4   r7   r7   R   sš   … á.ð Óð Óð )Ó(ð /Ó.ñ 27Ø4ô2ÐÐ.ó ñ
 16Ø.ô1ÐÐ-ó ñ
 5:Ø,ô5ÐÐ1ó ð
 3JÐÐ/ÓIñ ',Ð<PÔ&Q€O�^ÓQð €HˆdÔr3   r7   c                  ó    — e Zd ZdZdZdZdZdZy)ÚRuntimeStateÚINITIALÚNO_SESSIONS_CONNECTEDÚONE_OR_MORE_SESSIONS_CONNECTEDÚSTOPPINGÚSTOPPEDN)r.   r/   r0   rI   rJ   rK   rL   rM   r2   r3   r4   rH   rH   ‚   s   „ Ø€GØ3ÐØ%EÐ"Ø€HØ�Gr3   rH   c                  óN   — e Zd ZU dZded<   ded<   ded<   ded<   ded	<   ded
<   y)ÚAsyncObjectsz‡Container for all asyncio objects that Runtime manages.
    These cannot be initialized until the Runtime's eventloop is assigned.
    zasyncio.AbstractEventLoopÚ	eventloopzasyncio.EventÚ	must_stopÚhas_connectionÚneed_send_datazasyncio.Future[None]ÚstartedÚstoppedN)r.   r/   r0   r1   rF   r2   r3   r4   rO   rO   Š   s7   … ñð
 )Ó(ð Óð "Ó!ð "Ó!ð "Ó!ð "Ô!r3   rO   c                  ó¶  — e Zd ZU dZded<   ed"d„«       Zed#d„«       Zd$d„Ze	d%d„«       Z
e	d&d„«       Ze	d'd	„«       Ze	d(d
„«       Ze	d)d„«       Ze	d*d„«       Ze	d+d„«       Ze	d,d„«       Zd-d„Zd.d„Zd/d„Zd/d„Zd0d„Z	 	 d1	 	 	 	 	 	 	 	 	 d2d„Z	 	 d1	 	 	 	 	 	 	 	 	 d2d„Zd.d„Zd.d„Zd3d„Z	 	 	 	 	 	 d4d„Ze	d5d„«       Zd5d„Zd6d„Zd/d„Z d7d„Z!d/d„Z"d8d „Z#d/d!„Z$y)9ÚRuntimeNzRuntime | NoneÚ	_instancec                óH   — | j                   €t        d«      ‚| j                   S )znReturn the singleton Runtime instance. Raise an Error if the
        Runtime hasn't been created yet.
        zRuntime hasn't been created!)rX   ÚRuntimeError©Úclss    r4   ÚinstancezRuntime.instance¥   s$   € ð
 �=‰=Ð ÜÐ=Ó>Ð>Ø�}‰}Ðr3   c                ó   — | j                   duS )a2  True if the singleton Runtime instance has been created.

        When a Streamlit app is running in "raw mode" - that is, when the
        app is run via `python app.py` instead of `streamlit run app.py` -
        the Runtime will not exist, and various Streamlit functions need
        to adapt.
        N)rX   r[   s    r4   ÚexistszRuntime.exists®   s   € ð �}‰} DÐ(Ð(r3   c                óÔ  — t         j                  �t        d«      ‚| t         _        d| _        d| _        |j
                  | _        |j                  | _        t        j                  | _        |j                  | _        |j                  | _        |j                   | _        t%        |j&                  ¬«      | _        |j*                  | _        t/        «       | _        | j                  j3                  «        |j5                  |j6                  | j"                  | j0                  | j8                  ¬«      | _        t=        «       | _        | j>                  jA                  tC        «       «       | j>                  jA                  tE        «       «       | j"                  �%| j>                  jA                  | j"                  «       tG        |j&                  tH        «      r%| j>                  jA                  |j&                  «       | j>                  jA                  tK        | j:                  «      «       tG        | j:                  tH        «      r&| j>                  jA                  | j:                  «       yy)a   Create a Runtime instance. It won't be started yet.

        Runtime is *not* thread-safe. Its public methods are generally
        safe to call only on the same thread that its event loop runs on.

        Parameters
        ----------
        config
            Config options.
        Nz Runtime instance already exists!)Ústorage)rC   r=   Úscript_cacheÚmessage_enqueued_callback)&rW   rX   rZ   Ú_async_objsÚ_loop_coroutine_taskr9   Ú_main_script_pathrE   Ú	_is_hellorH   rI   Ú_stater@   Ú_component_registryrA   Ú_bidi_component_registryr=   Ú_uploaded_file_mgrr   r<   Ú_media_file_mgrr?   Ú_cache_storage_managerr   Ú_script_cacheÚ discover_and_register_componentsrB   rC   Ú_enqueued_some_messageÚ_session_mgrr   Ú
_stats_mgrÚregister_providerr   r   Ú
isinstancer   r   )ÚselfÚconfigs     r4   Ú__init__zRuntime.__init__¹   s×  € ô ×ÑÐ(ÜÐAÓBÐBØ ŒÔð 15ˆÔð @DˆÔ!à!'×!3Ñ!3ˆÔØŸ™ˆŒä"×*Ñ*ˆŒð $*×#<Ñ#<ˆÔ Ø(.×(FÑ(FˆÔ%Ø"(×">Ñ">ˆÔÜ/¸×8QÑ8QÔRˆÔØ&,×&BÑ&BˆÔ#Ü(›]ˆÔð 	×%Ñ%×FÑFÔHà"×8Ñ8Ø"×2Ñ2Ø"&×"9Ñ"9Ø×+Ñ+Ø&*×&AÑ&Að	 9ó 
ˆÔô '›.ˆŒØ�‰×)Ñ)Ô*GÓ*IÔJØ�‰×)Ñ)Ô*KÓ*MÔNØ×"Ñ"Ð.Ø�O‰O×-Ñ-¨d×.EÑ.EÔFä�f×/Ñ/´Ô?Ø�O‰O×-Ñ-¨f×.GÑ.GÔHØ�‰×)Ñ)Ô*BÀ4×CTÑCTÓ*UÔVô �d×'Ñ'¬Ô7Ø�O‰O×-Ñ-¨d×.?Ñ.?Õ@ð 8r3   c                ó   — | j                   S ©N)rh   ©ru   s    r4   ÚstatezRuntime.stateô   s   € à�{‰{Ðr3   c                ó   — | j                   S ry   )ri   rz   s    r4   r@   zRuntime.component_registryø   s   € à×'Ñ'Ð'r3   c                ó   — | j                   S ry   )rj   rz   s    r4   rA   zRuntime.bidi_component_registryü   s   € à×,Ñ,Ð,r3   c                ó   — | j                   S ry   )rk   rz   s    r4   Úuploaded_file_mgrzRuntime.uploaded_file_mgr   s   € à×&Ñ&Ð&r3   c                ó   — | j                   S ry   )rm   rz   s    r4   r?   zRuntime.cache_storage_manager  s   € à×*Ñ*Ð*r3   c                ó   — | j                   S ry   )rl   rz   s    r4   Úmedia_file_mgrzRuntime.media_file_mgr  s   € à×#Ñ#Ð#r3   c                ó   — | j                   S ry   )rr   rz   s    r4   Ú	stats_mgrzRuntime.stats_mgr  s   € à�‰Ðr3   c                ó6   — | j                  «       j                  S )z?A Future that completes when the Runtime's run loop has exited.)Ú_get_async_objsrU   rz   s    r4   rU   zRuntime.stopped  s   € ð ×#Ñ#Ó%×-Ñ-Ð-r3   c                óV   — | j                   j                  |«      }|€y|j                  S )z¶Get the SessionClient for the given session_id, or None
        if no such session exists.

        Notes
        -----
        Threading: SAFE. May be called on any thread.
        N)rq   Úget_active_session_infoÚclient©ru   Ú
session_idÚsession_infos      r4   Ú
get_clientzRuntime.get_client  s/   € ð ×(Ñ(×@Ñ@ÀÓLˆØÐØØ×"Ñ"Ð"r3   c                ót   — | j                   j                  |«      }|�|j                  j                  «        yy)z‰Clear the user_info for the given session_id.

        Notes
        -----
        Threading: SAFE. May be called on any thread.
        N)rq   Úget_session_infoÚsessionÚclear_user_inforŠ   s      r4   Úclear_user_info_for_sessionz#Runtime.clear_user_info_for_session(  s7   € ð ×(Ñ(×9Ñ9¸*ÓEˆØÐ#Ø× Ñ ×0Ñ0Õ2ð $r3   c           	   ƒ  ó”  K  — t        t        j                  «       t        j                  «       t        j                  «       t        j                  «       t        j                  «       t        j                  «       ¬«      }|| _        t        j                  | j                  «       d¬«      | _        |j                  ƒ d{  –—†  y7 Œ­w)a  Start the runtime. This must be called only once, before
        any other functions are called.

        When this coroutine returns, Streamlit is ready to accept new sessions.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        )rP   rQ   rR   rS   rT   rU   zRuntime.loop_coroutine)ÚnameN)
rO   ÚasyncioÚget_running_loopÚEventÚFuturerd   Úcreate_taskÚ_loop_coroutinere   rT   ©ru   Ú
async_objss     r4   ÚstartzRuntime.start3  sŠ   è ø€ ô "Ü×.Ñ.Ó0Ü—m‘m“oÜ"Ÿ=™=›?Ü"Ÿ=™=›?Ü—N‘NÓ$Ü—N‘NÓ$ô
ˆ
ð &ˆÔä$+×$7Ñ$7Ø× Ñ Ó"Ð)Aô%
ˆÔ!ð × Ñ × Ò ús   ‚B>CÃ CÃCc                ól   ‡ ‡— ‰ j                  «       Šdˆˆ fd„}‰j                  j                  |«       y)zÕRequest that Streamlit close all sessions and stop running.
        Note that Streamlit won't stop running immediately.

        Notes
        -----
        Threading: SAFE. May be called from any thread.
        c                 óü   •— ‰j                   t        j                  t        j                  fv ry t        j                  d«       ‰j                  t        j                  «       ‰ j                  j                  «        y )NzRuntime stopping...)	rh   rH   rL   rM   r+   ÚdebugÚ
_set_staterQ   Úset)rœ   ru   s   €€r4   Ústop_on_eventloopz'Runtime.stop.<locals>.stop_on_eventloop[  sT   ø€ Ø�{‰{œ|×4Ñ4´l×6JÑ6JÐKÑKØä�M‰MÐ/Ô0Ø�O‰OœL×1Ñ1Ô2Ø× Ñ ×$Ñ$Õ&r3   N©ÚreturnÚNone)r†   rP   Úcall_soon_threadsafe)ru   r£   rœ   s   ` @r4   ÚstopzRuntime.stopP  s/   ù€ ð ×)Ñ)Ó+ˆ
ö	'ð 	×Ñ×1Ñ1Ð2CÕDr3   c                ó8   — | j                   j                  |«      S )z�True if the session_id belongs to an active session.

        Notes
        -----
        Threading: SAFE. May be called on any thread.
        )rq   Úis_active_session)ru   r‹   s     r4   rª   zRuntime.is_active_sessione  s   € ð × Ñ ×2Ñ2°:Ó>Ð>r3   c                ó¸  — |r|rt        d«      ‚| j                  t        j                  t        j                  fv rt        d| j                  › d�«      ‚| j                  j                  |t        | j                  | j                  «      |||¬«      }| j                  t        j                  «       | j                  «       j                  j                  «        |S )a‹  Create a new session (or connect to an existing one) and return its unique ID.

        Parameters
        ----------
        client
            A concrete SessionClient implementation for communicating with
            the session's client.
        user_info
            A dict that contains information about the session's user. For now,
            it only (optionally) contains the user's email address.

            {
                "email": "example@example.com"
            }
        existing_session_id
            The ID of an existing session to reconnect to. If one is not provided, a new
            session is created. Note that whether the Runtime's SessionManager supports
            reconnecting to an existing session depends on the SessionManager that this
            runtime is configured with.
        session_id_override
            The ID to assign to a new session being created with this method. 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. Only one of existing_session_id and
            session_id_override should be set.

        Returns
        -------
        str
            The session's unique string ID.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        z`Only one of existing_session_id and session_id_override should be set. This should never happen.zCan't connect_session (state=ú))r‰   Úscript_dataÚ	user_infoÚexisting_session_idÚsession_id_override)rZ   rh   rH   rL   rM   r-   rq   Úconnect_sessionr   rf   rg   r¡   rK   r†   rR   r¢   )ru   r‰   r®   r¯   r°   r‹   s         r4   r±   zRuntime.connect_sessionn  sÆ   € ñT Ñ#6Üð,óð ð
 �;‰;œ<×0Ñ0´,×2FÑ2FÐGÑGÜ%Ð(EÀdÇkÁkÀ]ÐRSÐ&TÓUÐUà×&Ñ&×6Ñ6ØÜ" 4×#9Ñ#9¸4¿>¹>ÓJØØ 3Ø 3ð 7ó 
ˆ
ð 	�‰œ×CÑCÔDØ×ÑÓ×-Ñ-×1Ñ1Ô3àÐr3   c                óV   — t         j                  d«       | j                  ||||¬«      S )zÚCreate a new session (or connect to an existing one) and return its unique ID.

        Notes
        -----
        This method is simply an alias for connect_session added for backwards
        compatibility.
        z:create_session is deprecated! Use connect_session instead.)r‰   r®   r¯   r°   )r+   Úwarningr±   )ru   r‰   r®   r¯   r°   s        r4   Úcreate_sessionzRuntime.create_session­  s5   € ô 	�‰ÐTÔUØ×#Ñ#ØØØ 3Ø 3ð	 $ó 
ð 	
r3   c                ó”   — | j                   j                  |«      }|r| j                   j                  |«       | j                  «        y)a9  Close and completely shut down a session.

        This differs from disconnect_session in that it always completely shuts down a
        session, permanently losing any associated state (session state, uploaded files,
        etc.).

        This function may be called multiple times for the same session,
        which is not an error. (Subsequent calls just no-op.)

        Parameters
        ----------
        session_id
            The session's unique ID.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        N)rq   r�   Úclose_sessionÚ_on_session_disconnectedrŠ   s      r4   r¶   zRuntime.close_sessionÃ  s=   € ð& ×(Ñ(×9Ñ9¸*ÓEˆÙØ×Ñ×+Ñ+¨JÔ7Ø×%Ñ%Õ'r3   c                ó”   — | j                   j                  |«      }|r| j                   j                  |«       | j                  «        y)aZ  Disconnect a session. It will stop producing ForwardMsgs.

        Differs from close_session because disconnected sessions can be reconnected to
        for a brief window (depending on the SessionManager/SessionStorage
        implementations used by the runtime).

        This function may be called multiple times for the same session,
        which is not an error. (Subsequent calls just no-op.)

        Parameters
        ----------
        session_id
            The session's unique ID.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        N)rq   rˆ   Údisconnect_sessionr·   rŠ   s      r4   r¹   zRuntime.disconnect_sessionÛ  s=   € ð& ×(Ñ(×@Ñ@ÀÓLˆÙØ×Ñ×0Ñ0°Ô<Ø×%Ñ%Õ'r3   c                ó,  — | j                   t        j                  t        j                  fv rt	        d| j                   › d�«      ‚| j
                  j                  |«      }|€t        j                  d|«       y|j                  j                  |«       y)a+  Send a BackMsg to an active session.

        Parameters
        ----------
        session_id
            The session's unique ID.
        msg
            The BackMsg to deliver to the session.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        zCan't handle_backmsg (state=r¬   Nz3Discarding BackMsg for disconnected session (id=%s))rh   rH   rL   rM   r-   rq   rˆ   r+   r    r�   Úhandle_backmsg)ru   r‹   ÚmsgrŒ   s       r4   r»   zRuntime.handle_backmsgó  s�   € ð �;‰;œ<×0Ñ0´,×2FÑ2FÐGÑGÜ%Ð(DÀTÇ[Á[ÀMÐQRÐ&SÓTÐTà×(Ñ(×@Ñ@ÀÓLˆØÐÜ�M‰MØEÀzôð à×Ñ×+Ñ+¨CÕ0r3   c                ó,  — | j                   t        j                  t        j                  fv rt	        d| j                   › d�«      ‚| j
                  j                  |«      }|€t        j                  d|«       y|j                  j                  |«       y)a.  Handle an Exception raised during deserialization of a BackMsg.

        Parameters
        ----------
        session_id
            The session's unique ID.
        exc
            The Exception.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        z6Can't handle_backmsg_deserialization_exception (state=r¬   Nz=Discarding BackMsg Exception for disconnected session (id=%s))rh   rH   rL   rM   r-   rq   rˆ   r+   r    r�   Úhandle_backmsg_exception)ru   r‹   ÚexcrŒ   s       r4   Ú(handle_backmsg_deserialization_exceptionz0Runtime.handle_backmsg_deserialization_exception  sˆ   € ð  �;‰;œ<×0Ñ0´,×2FÑ2FÐGÑGÜ%ØHÈÏÉÈÐUVÐWóð ð ×(Ñ(×@Ñ@ÀÓLˆØÐÜ�M‰MØOØôð à×Ñ×5Ñ5°cÕ:r3   c              ƒ  ó„   K  — | j                   t        j                  t        j                  t        j                  fvryy­w)N)TÚok)FÚunavailable)rh   rH   rI   rL   rM   rz   s    r4   Úis_ready_for_browser_connectionz'Runtime.is_ready_for_browser_connection,  s:   è ø€ à�;‰;Ü× Ñ Ü×!Ñ!Ü× Ñ ð
ñ 
ð
 à#ùs   ‚>A c              ƒ  ó¾  K  — t        t        | j                  | j                  «      | j                  | j
                  | j                  ddi¬«      }	 |j                  d«       t        j                  «       }t        |j                  vrlt        j                  «       |z
  t        k  rNt        j                  d«      ƒ d{  –—†  t        |j                  vrt        j                  «       |z
  t        k  rŒNt        |j                  vr	 |j                  «        y|j                  t           }|rdnd}||f|j                  «        S 7 Œ†# |j                  «        w xY w­w)	aJ  Load and execute the app's script to verify it runs without an error.

        Returns
        -------
        (True, "ok") if the script completes without error, or (False, err_msg)
        if the script raises an exception.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        Úemailztest@example.com)r­   r=   rb   rc   r®   Ngš™™™™™¹?)FÚtimeoutrÂ   Úerror)r   r   rf   rg   rk   rn   rp   Úrequest_rerunÚtimeÚperf_counterr   Úsession_stater(   r•   ÚsleepÚshutdown)ru   r�   ÚnowrÂ   r¼   s        r4   Údoes_script_run_without_errorz%Runtime.does_script_run_without_error7  s-  è ø€ ô Ü" 4×#9Ñ#9¸4¿>¹>ÓJØ"&×"9Ñ"9Ø×+Ñ+Ø&*×&AÑ&AØÐ 2Ð3ô
ˆð	Ø×!Ñ! $Ô'ä×#Ñ#Ó%ˆCä-°W×5JÑ5JÑJÜ×&Ñ&Ó(¨3Ñ.Ô2JÒJä—m‘m CÓ(×(Ð(ô .°W×5JÑ5JÑJÜ×&Ñ&Ó(¨3Ñ.Ô2JÓJô -°G×4IÑ4IÑIØ'ð ×ÑÕð ×&Ñ&Ô'DÑEˆBÙ‘$ 'ˆCà�s�7à×ÑÕð )ùð ×ÑÕüsC   ‚AEÁA-E Â?EÃ 4E Ã5E ÄEÄE Ä5EÅE ÅEÅEc                óT   — t         j                  d| j                  |«       || _        y )NzRuntime state: %s -> %s)r+   r    rh   )ru   Ú	new_states     r4   r¡   zRuntime._set_stateb  s   € Ü�‰Ð/°·±¸iÔHØˆ�r3   c              ƒ  óŽ  K  — | j                  «       }	 | j                  t        j                  k(  r | j	                  t        j
                  «       n6| j                  t        j                  k(  rnt        d| j                  › �«      ‚|j                  j                  d«       |j                  j                  «       �sZ| j                  t        j
                  k(  r­t        j                  t        j                  |j                  j                  «       «      t        j                  |j                  j                  «       «      ft        j                   t"        ¬«      ƒ d{  –—† \  }}|D ]  }|j%                  «        Œ |sÍt"        �ÇŒå| j                  t        j                  k(  r¨|j&                  j)                  «        | j*                  j-                  «       D ]S  }|j.                  j1                  «       }|D ]2  }	 | j3                  ||«       t        j:                  d«      ƒ d{  –—†  Œ4 ŒU t        j:                  d«      ƒ d{  –—†  nnÊt        j                  t        j                  |j                  j                  «       «      t        j                  |j&                  j                  «       «      ft        j                   t"        ¬«      ƒ d{  –—† \  }}|D ]  }|j%                  «        Œ |st"        ��ŒY|j                  j                  «       s�ŒZ| j*                  j=                  «       D ]1  }| j*                  j?                  |j.                  j8                  «       Œ3 | j	                  t        j@                  «       |jB                  j                  d«       y7 �ŒA# t4        $ r3 | j*                  j7                  |j.                  j8                  «       Y �ŒÑw xY w7 �Œ½7 �ŒŸ7 �Œ# tD        $ rN}	|jB                  jG                  |	«       tI        jJ                  «        tL        jO                  d«       Y d}	~	yd}	~	ww xY w­w)z¹The main Runtime loop.

        This function won't exit until `stop` is called.

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        zBad Runtime state at start: N)Úreturn_whenrÇ   r   g{®Gáz„?zJ
Please report this bug at https://github.com/streamlit/streamlit/issues.
)(r†   rh   rH   rI   r¡   rJ   rK   rZ   rT   Ú
set_resultrQ   Úis_setr•   Úwaitr™   rR   ÚFIRST_COMPLETEDr*   ÚcancelrS   Úclearrq   Úlist_active_sessionsr�   Úflush_browser_queueÚ_send_messager   r¹   ÚidrÍ   Úlist_sessionsr¶   rM   rU   Ú	ExceptionÚset_exceptionÚ	tracebackÚ	print_excr+   Úinfo)
ru   rœ   Ú
done_tasksÚpending_tasksÚtaskÚactive_session_infoÚmsg_listr¼   rŒ   Úes
             r4   rš   zRuntime._loop_coroutinef  s‚  è ø€ ð ×)Ñ)Ó+ˆ
ð^	Ø�{‰{œl×2Ñ2Ò2Ø—‘¤× BÑ BÕCØ—‘¤× KÑ KÒKØä"Ð%AÀ$Ç+Á+ÀÐ#OÓPÐPð ×Ñ×)Ñ)¨$Ô/à ×*Ñ*×1Ñ1Õ3Ø—;‘;¤,×"DÑ"DÒDô
 7>·l±lä#×/Ñ/°
×0DÑ0D×0IÑ0IÓ0KÓLÜ#×/Ñ/°
×0IÑ0I×0NÑ0NÓ0PÓQðô %,×$;Ñ$;ä 6ô7÷ 1Ñ-�J ð !.ò &˜ØŸ™�ð&ñ &Ô*@Ð*LØ Ø—[‘[¤L×$OÑ$OÒOØ×-Ñ-×3Ñ3Ô5à/3×/@Ñ/@×/UÑ/UÓ/Wò 3Ð+Ø#6×#>Ñ#>×#RÑ#RÓ#T˜Ø#+ò 	3˜Cð"Ø $× 2Ñ 2Ð3FÈÔ Lô #*§-¡-°Ó"2×2Ñ2ñ	3ð3ô "Ÿ-™-¨Ó-×-Ñ-ð ô 3:·,±,ä×+Ñ+¨J×,@Ñ,@×,EÑ,EÓ,GÓHÜ×+Ñ+¨J×,EÑ,E×,JÑ,JÓ,LÓMðô !(× 7Ñ 7ä2ô3÷ -Ñ)�
˜Mð *ò "�DØ—K‘K•Mð"ñ "Ô&<Ð&HÙðA !×*Ñ*×1Ñ1Ö3ðF !%× 1Ñ 1× ?Ñ ?Ó Aò I�ð ×!Ñ!×/Ñ/°×0DÑ0D×0GÑ0GÕHð	Ið �O‰OœL×0Ñ0Ô1Ø×Ñ×)Ñ)¨$Õ/ðI1úô0 $Bò "Ø $× 1Ñ 1× DÑ DØ$7×$?Ñ$?×$BÑ$B÷!"ð"úð 3ùð .ùð-úô< ò 	Ø×Ñ×,Ñ,¨QÔ/Ü×ÑÔ!Ü�L‰Lð÷ñ ûð	üs    ‚Q”EO+ ÅN Å BO+ Ç;N#ÈO+ È%O"È& O+ ÉO%ÉBO+ ËO(ËAO+ ÌBO+ ÎQÎ O+ Î#8OÏO+ ÏOÏO+ Ï%O+ Ï(O+ Ï+	QÏ4AP=Ð8QÐ=QÑQc                óÆ   — |j                  d«      dk(  r2|j                  t        j                  k(  r|xj                  dz  c_        |j
                  j                  |«       y)a  Send a message to a client.
        If the client is likely to have already cached the message, we may
        instead send a "reference" message that contains only the hash of the
        message.

        Parameters
        ----------
        session_info : ActiveSessionInfo
            The ActiveSessionInfo associated with websocket
        msg : ForwardMsg
            The message to send to the client

        Notes
        -----
        Threading: UNSAFE. Must be called on the eventloop thread.
        ÚtypeÚscript_finishedé   N)Ú
WhichOneofrí   r   ÚFINISHED_SUCCESSFULLYÚscript_run_countr‰   Úwrite_forward_msg)ru   rŒ   r¼   s      r4   rÝ   zRuntime._send_messageÒ  sQ   € ð( �>‰>˜&Ó!Ð%6Ò6Ø×Ñ¤:×#CÑ#CÒCà×)Ò)¨QÑ.Õ)ð 	×Ñ×-Ñ-¨cÕ2r3   c                ó‚   — | j                  «       }|j                  j                  |j                  j                  «       y)a  Callback called by AppSession after the AppSession has enqueued a
        message. Sets the "needs_send_data" event, which causes our core
        loop to wake up and flush client message queues.

        Notes
        -----
        Threading: SAFE. May be called on any thread.
        N)r†   rP   r§   rS   r¢   r›   s     r4   rp   zRuntime._enqueued_some_messageî  s2   € ð ×)Ñ)Ó+ˆ
Ø×Ñ×1Ñ1°*×2KÑ2K×2OÑ2OÕPr3   c                óH   — | j                   €t        d«      ‚| j                   S )zpReturn our AsyncObjects instance. If the Runtime hasn't been
        started, this will raise an error.
        zRuntime hasn't started yet!)rd   rZ   rz   s    r4   r†   zRuntime._get_async_objsú  s(   € ð ×ÑÐ#ÜÐ<Ó=Ð=Ø×ÑÐr3   c                ó
  — | j                   t        j                  k(  rf| j                  j	                  «       dk(  rH| j                  «       j                  j                  «        | j                  t        j                  «       yyy)zlSet the runtime state to NO_SESSIONS_CONNECTED if the last active
        session was disconnected.
        r   N)
rh   rH   rK   rq   Únum_active_sessionsr†   rR   rÚ   r¡   rJ   rz   s    r4   r·   z Runtime._on_session_disconnected  se   € ð
 �K‰Kœ<×FÑFÒFØ×!Ñ!×5Ñ5Ó7¸1Ò<à× Ñ Ó"×1Ñ1×7Ñ7Ô9Ø�O‰OœL×>Ñ>Õ?ð =ð Gr3   )r¥   rW   )r¥   rD   )rv   r7   r¥   r¦   )r¥   rH   )r¥   r!   )r¥   r   )r¥   r&   )r¥   r#   )r¥   r   )r¥   r   )r¥   zAwaitable[None])r‹   r8   r¥   zSessionClient | None)r‹   r8   r¥   r¦   r¤   )r‹   r8   r¥   rD   )NN)
r‰   r   r®   r%   r¯   r:   r°   r:   r¥   r8   )r‹   r8   r¼   r"   r¥   r¦   )r‹   r8   r¿   ÚBaseExceptionr¥   r¦   )r¥   ztuple[bool, str])rÒ   rH   r¥   r¦   )rŒ   r   r¼   r   r¥   r¦   )r¥   rO   )%r.   r/   r0   rX   rF   Úclassmethodr]   r_   rw   Úpropertyr{   r@   rA   r   r?   r‚   r„   rU   r�   r’   r�   r¨   rª   r±   r´   r¶   r¹   r»   rÀ   rÄ   rÐ   r¡   rš   rÝ   rp   r†   r·   r2   r3   r4   rW   rW   ¢   sÖ  … Ø $€Iˆ~Ó$àòó ðð ò)ó ð)ó9Aðv òó ðð ò(ó ð(ð ò-ó ð-ð ò'ó ð'ð ò+ó ð+ð ò$ó ð$ð òó ðð ò.ó ð.ó#ó	3ó!ó:Eó*?ð +/Ø*.ð=àð=ð  ð=ð (ð	=ð
 (ð=ð 
ó=ðF +/Ø*.ð
àð
ð  ð
ð (ð	
ð
 (ð
ð 
ó
ó,(ó0(ó01ð4;Øð;Ø$1ð;à	ó;ð> ò$ó ð$ó)óV ójóX3ó8
Qó ô	@r3   rW   )NÚ
__future__r   r•   ÚsysrÊ   râ   Údataclassesr   r   Úenumr   Útypingr   r   r	   Ú1streamlit.components.lib.local_component_registryr
   Ú)streamlit.components.v2.component_managerr   Ústreamlit.loggerr   Ústreamlit.proto.ForwardMsg_pb2r   Ústreamlit.runtime.app_sessionr   Ústreamlit.runtime.cachingr   r   Ú:streamlit.runtime.caching.storage.local_disk_cache_storager   Ú$streamlit.runtime.media_file_managerr   Ú(streamlit.runtime.memory_session_storager   Ústreamlit.runtime.script_datar   Ú+streamlit.runtime.scriptrunner.script_cacher   Ú!streamlit.runtime.session_managerr   r   r   r   r   Ústreamlit.runtime.stater   r   Ústreamlit.runtime.statsr   r   Ú+streamlit.runtime.websocket_session_managerr   Úcollections.abcr    Ú2streamlit.components.types.base_component_registryr!   Ústreamlit.proto.BackMsg_pb2r"   Ú!streamlit.runtime.caching.storager#   Ú$streamlit.runtime.media_file_storager$   Ú7streamlit.runtime.scriptrunner_utils.script_run_contextr%   Ú'streamlit.runtime.uploaded_file_managerr&   r(   rF   Úplatformr*   r.   r+   rà   r-   r7   rH   rO   rW   r2   r3   r4   ú<module>r     s  ðö #ã Û 
Û Û ß (Ý ß 3Ñ 3å TÝ JÝ 'Ý 5Ý 4÷õõ BÝ IÝ 4Ý C÷õ ÷÷õ PáÝ)åXÝ3ÝEÝEÝTÝKð #%Ð ˜%Ó $ð (+§|¡|°wÒ'>¡ÀDÐ ˜Ó Há˜HÓ%€ˆÓ %ôF˜)ô Fñ �$Ô÷&ð &ó ð&ô^�4ô ô"�:ô "÷0i	@ò i	@r3   