o
    Yh
0                     @  sJ  U d dl mZ d dlZd dl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mZ d dlmZ d d	lmZ d d
lmZ d dlmZ er]d dlmZ d dlmZ eeZ de!d< dZ"de!d< G dd dZ#ed		d>d?dd Z$		d>d@d$d%Z%dAd(d)Z&dBd+d,Z'dCd/d0Z(dDd4d5Z)ed6Z*dEd<d=Z+dS )F    )annotationsN)TYPE_CHECKINGCallableFinalTypeVarcast)config)validate_width)MarkdownFormattedExceptionStreamlitAPIWarning)
get_logger)	Exception)WidthConfig)gather_metrics)get_script_run_ctx)DeltaGenerator)WidthWithoutContentr   _LOGGERzThis app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app). _GENERIC_UNCAUGHT_EXCEPTION_TEXTc                   @  s0   e Zd Zed	dddd	Zedd
dZdS )ExceptionMixin	exceptionstretchBaseExceptionwidthr   returnr   c                 C  s   t | j||dS )a  Display an exception.

        When accessing the app through ``localhost``, in the lower-right corner
        of the exception, Streamlit displays links to Google and ChatGPT that
        are prefilled with the contents of the exception message.

        Parameters
        ----------
        exception : Exception
            The exception to display.
        width : "stretch" or int
            The width of the exception element. This can be one of the following:

            - ``"stretch"`` (default): The width of the element matches the
              width of the parent container.
            - An integer specifying the width in pixels: The element has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the element matches the width
              of the parent container.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> e = RuntimeError("This is an exception of type RuntimeError")
        >>> st.exception(e)

        .. output ::
            https://doc-status-exception.streamlit.app/
            height: 220px

        )r   )
_exceptiondg)selfr   r    r   ]/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/streamlit/elements/exception.pyr   1   s   $zExceptionMixin.exceptionc                 C  s
   t d| S )zGet our DeltaGenerator.r   )r   )r   r   r   r   r   W   s   
zExceptionMixin.dgN)r   )r   r   r   r   r   r   )r   r   )__name__
__module____qualname__r   r   propertyr   r   r   r   r   r   0   s    %r   r   r   Fr   r   r   r   r   is_uncaught_app_exceptionboolr   c                 C  s    t  }t|||| | d|S )Nr   )ExceptionProtomarshall_enqueue)r   r   r   r$   exception_protor   r   r   r   ^   s   r   r)   r&   Nonec                 C  s  t | t|t}t|dddur|j| _nt|j| _t|}| j	| t|t
| _t }t|tr8||_nd|_| j| zt|trMt|| _n
t| | _|| _W n% ty} } zd| _tdt|j|dt| W Y d}~nd}~ww |rtd}|tjjkptj |}	|	p|tjj!kptj"|}
|
p|tjj#k}|	st$| _|s| %d ntt|}|&d	d&d
d| _|
s| %d dS dS dS )a  Marshalls an Exception.proto message.

    Parameters
    ----------
    exception_proto : Exception.proto
        The Exception protobuf to fill out.

    exception : BaseException
        The exception whose data we're extracting.

    width : int or "stretch"
        The width of the exception display. Can be either an integer (pixels) or "stretch".
        Defaults to "stretch".

    is_uncaught_app_exception: bool
        The exception originates from an uncaught error during script execution.
    alternate_nameNT a*  

Streamlit was unable to parse the data from an exception in the user's script.
This is usually due to a bug in the Exception object itself. Here is some info
about that Exception object, so you can report a bug to the original author:

Exception type:
  %s

Problem:
  %s

Traceback:
%s

        
zclient.showErrorDetailstypez<class 'z'>stack_trace)'r	   
isinstancer
   getattrr+   r.   r    _get_stack_trace_str_listr/   extendWarning
is_warningr   intpixel_widthuse_stretchwidth_configCopyFromSyntaxError_format_syntax_error_messagemessagestrstripmessage_is_markdownr   r   warningjoinr   
get_optionShowErrorDetailsConfigOptionsFULLis_true_variation
STACKTRACEis_false_variationTYPEr   
ClearFieldreplace)r)   r   r   r$   is_markdown_exceptionr/   r9   str_exceptionshow_error_detailsshow_message
show_trace	show_typetype_strr   r   r   r'   j   sp   




	

r'   r;   r>   c                 C  sj   | j r1| jdurdt| jd d nd}d| j d| j d| j   d| d	t| j d
| j S t	| S )a  Returns a nicely formatted SyntaxError message that emulates
    what the Python interpreter outputs.

    For example:

    > File "raven.py", line 3
    >   st.write('Hello world!!'))
    >                            ^
    > SyntaxError: invalid syntax

    N    r   r,   zFile "z", line z
  z^
z: )
textoffsetmaxfilenamelinenorstripr.   r    msgr>   )r   caret_indentr   r   r   r<      s    	r<   	list[str]c                 C  sv   d}t | tr| j}nt| drt| j}|du rdg}|S t|\}}|r-t|}nt|}dd |D }|S )a  Get the stack trace for the given exception.

    Parameters
    ----------
    exception : BaseException
        The exception to extract the traceback from

    Returns
    -------
    tuple of two string lists
        The exception traceback as two lists of strings. The first represents the part
        of the stack trace the users don't typically want to see, containing internal
        Streamlit code. The second is whatever comes after the Streamlit stack trace,
        which is usually what the user wants.

    N__traceback__zdCannot extract the stack trace for this exception. Try calling exception() within the `catch` block.c                 S  s   g | ]}|  qS r   )r?   ).0itemr   r   r   
<listcomp>$  s    z-_get_stack_trace_str_list.<locals>.<listcomp>)	r0   r   tacked_on_stackhasattr	traceback
extract_tbr^    _split_internal_streamlit_framesformat_list)r   extracted_tracebacktrace_str_listinternal_framesexternal_framesr   r   r   r2      s"   


r2   filepackage_pathc                 C  s8   zt jt j| |g}W ||kS  ty   Y dS w )z/True if the given file is part of package_path.F)ospathcommonprefixrealpath
ValueError)rl   rm   common_prefixr   r   r   _is_in_package)  s   rt   extracted_tbtraceback.StackSummaryAtuple[list[traceback.FrameSummary], list[traceback.FrameSummary]]c                   sF   t  }|sg t| fS tjtjt|jd t|  fdddS )a  Split the traceback into a Streamlit-internal part and an external part.

    The internal part is everything up to (but excluding) the first frame belonging to
    the user's code. The external part is everything else.

    So if the stack looks like this:

        1. Streamlit frame
        2. Pandas frame
        3. Altair frame
        4. Streamlit frame
        5. User frame
        6. User frame
        7. Streamlit frame
        8. Matplotlib frame

    ...then this should return 1-4 as the internal traceback and 5-8 as the external.

    (Note that something like the example above is extremely unlikely to happen since
    it's not like Altair is calling Streamlit code, but you get the idea.)
    r,   c                   s   t | j S )N)rt   rX   )tbrm   r   r   <lambda>V  s    z2_split_internal_streamlit_frames.<locals>.<lambda>)split_point)	r   listrn   ro   rB   rq   r>   main_script_parent_split_list)ru   ctxr   ry   r   rf   4  s   
rf   T	orig_listlist[T]r{   Callable[[T], bool]tuple[list[T], list[T]]c                 C  sH   g }g }d}| D ]}|s||rd}|r| | q| | q||fS )NFT)append)r   r{   beforeaftersaw_split_pointr`   r   r   r   r~   ]  s   r~   )r   F)
r   r   r   r   r   r   r$   r%   r   r   )
r)   r&   r   r   r   r   r$   r%   r   r*   )r   r;   r   r>   )r   r   r   r]   )rl   r>   rm   r>   r   r%   )ru   rv   r   rw   )r   r   r{   r   r   r   ),
__future__r   rn   rd   typingr   r   r   r   r   	streamlitr   #streamlit.elements.lib.layout_utilsr	   streamlit.errorsr
   r   streamlit.loggerr   streamlit.proto.Exception_pb2r   r&   streamlit.proto.WidthConfig_pb2r   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   streamlit.delta_generatorr   r   r    r   __annotations__r   r   r   r'   r<   r2   rt   rf   r   r~   r   r   r   r   <module>   s@   
.
v

,
&