Ë
    úmxi§  ã                  óÌ   — d dl mZ d dlZd dlmZmZ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 erd d	lmZ d d
lmZ d dlmZ d dlmZ  G d„ d«      Z	 	 	 	 	 	 dd„Zy)é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚLiteral)Úutil)Úcontext_dg_stackÚget_default_dg_stack_value)Úhandle_uncaught_app_exception)ÚFragmentHandledException)ÚRerunExceptionÚStopException)ÚCallable)ÚTracebackType)Ú	RerunData)ÚScriptRunContextc                  ó@   — e Zd ZdZdd„Zdd„Zd	d„Z	 	 	 	 	 	 	 	 d
d„Zy)Úmodified_sys_pathzÁA context for prepending a directory to sys.path for a second.

    Code inspired by IPython:
    Source: https://github.com/ipython/ipython/blob/master/IPython/utils/syspathcontext.py#L42
    c                ó    — || _         d| _        y ©NF)Ú_main_script_pathÚ_added_path)ÚselfÚmain_script_paths     ú_/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.pyÚ__init__zmodified_sys_path.__init__/   s   € Ø!1ˆÔØ ˆÕó    c                ó,   — t        j                  | «      S )N)r   Úrepr_©r   s    r   Ú__repr__zmodified_sys_path.__repr__3   s   € Ü�z‰z˜$ÓÐr   c                ó    — | j                   t        j                  vr2t        j                  j                  d| j                   «       d| _        y y )Nr   T)r   ÚsysÚpathÚinsertr   r   s    r   Ú	__enter__zmodified_sys_path.__enter__6   s9   € Ø×!Ñ!¬¯©Ñ1Ü�H‰H�O‰O˜A˜t×5Ñ5Ô6Ø#ˆDÕð 2r   c                ó�   — | j                   r+	 t        j                  j                  | j                  «       yy# t
        $ r Y yw xY wr   )r   r"   r#   Úremover   Ú
ValueError)r   ÚtypÚexcÚtbs       r   Ú__exit__zmodified_sys_path.__exit__;   sF   € ð ×ÒðÜ—‘—‘ × 6Ñ 6Ô7ñ øô ò àð ðús   Ž)9 ¹	AÁAN)r   ÚstrÚreturnÚNone)r.   r-   )r.   r/   )r)   ztype[BaseException] | Noner*   zBaseException | Noner+   zTracebackType | Noner.   zLiteral[False])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r%   r,   © r   r   r   r   (   sA   „ ñó!ó ó$ð
à'ðð "ðð !ð	ð
 
ôr   r   c                ób  — d}d}d}d}d}	  | «       }|||||fS # t         $ rO}|j                  }|j                  j                  «        t	        j
                  t        «       «       d}Y d}~ŒZd}~wt        $ r d}Y Œjt        $ r d}d}Y Œxt        $ r}d}d}t        |«       |}Y d}~Œ–d}~ww xY w)ad  Execute the passed function wrapped in a try/except block.

    This function is called by the script runner to execute the user's script or
    fragment reruns, but also for the execution of fragment code in context of a normal
    app run. This wrapper ensures that handle_uncaught_exception messages show up in the
    correct context.

    Parameters
    ----------
    func : callable
        The function to execute wrapped in the try/except block.
    ctx : ScriptRunContext
        The context in which the script is being run.

    Returns
    -------
    tuple
        A tuple containing:
        - The result of the passed function.
        - A boolean indicating whether the script ran without errors (RerunException and
            StopException don't count as errors).
        - The RerunData instance belonging to a RerunException if the script was
            interrupted by a RerunException.
        - A boolean indicating whether the script was stopped prematurely (False for
            RerunExceptions, True for all other exceptions).
        - The uncaught exception if one occurred, None otherwise
    TNF)r   Ú
rerun_dataÚcursorsÚclearr   Úsetr	   r   r   Ú	Exceptionr
   )	ÚfuncÚctxÚrun_without_errorsÚrerun_exception_dataÚpremature_stopÚresultÚuncaught_exceptionÚeÚexs	            r   Úexec_func_with_error_handlingrD   L   sÜ   € ðH Ðð .2Ðð !€Nð €Fð ,0Ðð Ù“ˆðB 	ØØØØðð øô? ò Ø Ÿ|™|Ðð 	�‰×ÑÔÜ×ÑÔ7Ó9Ô:ð �ûäò ð ŠÜ#ò Ø"ÐØŠÜò  Ø"ÐØˆÜ% bÔ)ØÕûð	 ús-   Œ š	B.£AA-Á-B.Á=B.ÂB.ÂB)Â)B.)r;   zCallable[[], Any]r<   r   r.   zAtuple[Any | None, bool, RerunData | None, bool, Exception | None])Ú
__future__r   r"   Útypingr   r   r   Ú	streamlitr   Ú$streamlit.delta_generator_singletonsr   r	   Ústreamlit.error_utilr
   Ústreamlit.errorsr   Ú/streamlit.runtime.scriptrunner_utils.exceptionsr   r   Úcollections.abcr   Útypesr   Ú4streamlit.runtime.scriptrunner_utils.script_requestsr   Ú7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   rD   r4   r   r   ú<module>rP      sg   ðõ #ã 
ß .Ñ .å ÷õ ?Ý 5÷ñ
 Ý(Ý#åNÝX÷!ñ !ðH[Ø
ð[Ø"2ð[ðô[r   