
    .Ph
w                        d Z ddlZddlZddlZg dZ G d d          Z G d d          Z G d d	          Z G d
 d          Z G d de          Z	 G d de          Z
 G d de          Zd Zd Zd ZddZd Z ej        d          Z ej        d          Z ej        d          Z G d d          ZeZdS )a  One of the oft-cited tenets of Python is that it is better to ask
forgiveness than permission. That is, there are many cases where it is
more inclusive and correct to handle exceptions than spend extra lines
and execution time checking for conditions. This philosophy makes good
exception handling features all the more important. Unfortunately
Python's :mod:`traceback` module is woefully behind the times.

The ``tbutils`` module provides two disparate but complementary featuresets:

  1. With :class:`ExceptionInfo` and :class:`TracebackInfo`, the
     ability to extract, construct, manipulate, format, and serialize
     exceptions, tracebacks, and callstacks.
  2. With :class:`ParsedException`, the ability to find and parse tracebacks
     from captured output such as logs and stdout.

There is also the :class:`ContextualTracebackInfo` variant of
:class:`TracebackInfo`, which includes much more information from each
frame of the callstack, including values of locals and neighboring
lines of code.
    N)ExceptionInfoTracebackInfo	CallpointContextualExceptionInfoContextualTracebackInfoContextualCallpointprint_exceptionParsedExceptionc                        e Zd ZdZdZ	 ddZd Zedd            Zed             Z	ed	             Z
 fd
Zd Z xZS )r   a  The Callpoint is a lightweight object used to represent a single
    entry in the code of a call stack. It stores the code-related
    metadata of a given frame. Available attributes are the same as
    the parameters below.

    Args:
        func_name (str): the function name
        lineno (int): the line number
        module_name (str): the module name
        module_path (str): the filesystem path of the module
        lasti (int): the index of bytecode execution
        line (str): the single-line code content (if available)

    	func_namelinenomodule_namemodule_pathlastilineNc                 Z    || _         || _        || _        || _        || _        || _        d S Nr   )selfr   r   r   r   r   r   s          O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/boltons/tbutils.py__init__zCallpoint.__init__Z   s2    "&&
			    c                     i }| j         D ]L}	 t          | |          }t          |t                    rt	          |          n|||<   =# t
          $ r Y Iw xY w|S )zDGet a :class:`dict` copy of the Callpoint. Useful for serialization.)	__slots__getattr
isinstance_DeferredLinestrAttributeError)r   retslotvals       r   to_dictzCallpoint.to_dictc   s~    N 	P 	PDPdD)) )33(F(FOCHHHCD		 "    
s   A
AA   c                 T    t          j        |          }|                     |          S )z>Creates a Callpoint from the location of the calling function.)sys	_getframe
from_frame)clslevelframes      r   from_currentzCallpoint.from_currento   s%     e$$~~e$$$r   c                     |j         j        }|j        }|j                            dd          }|j         j        }|j        }t          |||j                  } | ||||||          S )zCCreate a Callpoint object from data extracted from the given frame.__name__ r   )f_codeco_namef_lineno	f_globalsgetco_filenamef_lastir   )r)   r+   r   r   r   r   r   r   s           r   r(   zCallpoint.from_frameu   sv     L(	o))*b99l.[&%/BBs;Y5t- - - 	-r   c                     |j         j        j        }|j        }|j        }|j         j                            dd          }|j         j        j        }t          |||j         j                  } | ||||||          S )a>  Create a Callpoint from the traceback of the current
        exception. Main difference with :meth:`from_frame` is that
        ``lineno`` and ``lasti`` come from the traceback, which is to
        say the line that failed in the try block, not the line
        currently being executed (in the except block).
        r.   r/   r0   )	tb_framer1   r2   	tb_linenotb_lastir4   r5   r6   r   )r)   tbr   r   r   r   r   r   s           r   from_tbzCallpoint.from_tb   s     K&.	k+//
B??k(4[&"+2GHHs;Y5t- - - 	-r   c                      j         j        } fd j        D             }t          |          s t	                                                      S d                    |d                    d |D                                 S )Nc                 2    g | ]}t          |d           S r   )r   ).0sr   s     r   
<listcomp>z&Callpoint.__repr__.<locals>.<listcomp>   s%    ???1a&&???r   z{}({}), c                 ,    g | ]}t          |          S  )repr)r@   as     r   rB   z&Callpoint.__repr__.<locals>.<listcomp>   s    1H1H1Ha$q''1H1H1Hr   )	__class__r.   r   anysuper__repr__formatjoin)r   cnargsrH   s   `  r   rK   zCallpoint.__repr__   s}    ^$???????4yy 	K77##%%%??2tyy1H1H41H1H1H'I'IJJJr   c                     d                     | j        | j        | j                  }| j        r-|dt          | j                                                   dz  }|S )zRender the Callpoint as it would appear in a standard printed
        Python traceback. Returns a string with filename, line number,
        function name, and the actual code line of the error on up to
        two lines.
        z  File "{}", line {}, in {}
    
)rL   r   r   r   r   r   stripr   r    s     r   tb_frame_strzCallpoint.tb_frame_str   se     .44T5E1515A A 9 	54#di....004444C
r   r   )r$   )r.   
__module____qualname____doc__r   r   r#   classmethodr,   r(   r=   rK   rU   __classcell__rH   s   @r   r   r   H   s         I &*   
 
 
 % % % [%
 	- 	- [	- - - [- K K K K K      r   r   c                   <    e Zd ZdZdZd
dZd Zd Zd Zd Z	d	 Z
dS )r   a3  The _DeferredLine type allows Callpoints and TracebackInfos to be
    constructed without potentially hitting the filesystem, as is the
    normal behavior of the standard Python :mod:`traceback` and
    :mod:`linecache` modules. Calling :func:`str` fetches and caches
    the line.

    Args:
        filename (str): the path of the file containing the line
        lineno (int): the number of the line in question
        module_globals (dict): an optional dict of module globals,
            used to handle advanced use cases using custom module loaders.

    )filenamer   _line	_mod_name_mod_loaderNc                     || _         || _        |d | _        d | _        d S |                    d          | _        |                    d          | _        d S )Nr.   
__loader__)r]   r   r_   r`   r5   )r   r]   r   module_globalss       r   r   z_DeferredLine.__init__   s\     !!DN#D+//
;;DN-11,??Dr   c                 >    | j         | j        f|j         |j        fk    S r   )r   r]   r   others     r   __eq__z_DeferredLine.__eq__   s    T]+en/MMMr   c                     | |k     S r   rE   re   s     r   __ne__z_DeferredLine.__ne__   s    5=  r   c                    t          | dd           }||S 	 t          j        | j                   | j        | j        d}t          j        | j        | j        |          }|                                }n# t          $ r d}Y nw xY w|| _
        |S )Nr^   )r.   rb   r/   )r   	linecache
checkcacher]   r_   r`   getliner   rstripKeyErrorr^   )r   r    mod_globalsr   s       r   __str__z_DeferredLine.__str__   s    dGT**?J		 ///'+~)-)9; ;K$T]%)[%02 2D ;;==DD 	 	 	DDD	
s   AA4 4BBc                 :    t          t          |                     S r   )rF   r   r   s    r   rK   z_DeferredLine.__repr__   s    CIIr   c                 :    t          t          |                     S r   )lenr   rs   s    r   __len__z_DeferredLine.__len__   s    3t99~~r   r   )r.   rV   rW   rX   r   r   rg   ri   rq   rK   rv   rE   r   r   r   r      s          LI@ @ @ @N N N! ! !  "      r   r   c                       e Zd ZdZeZd Zedd            Zedd            Z	ed             Z
d Zd	 Zd
 Zd Zd Zd ZdS )r   a  The TracebackInfo class provides a basic representation of a stack
    trace, be it from an exception being handled or just part of
    normal execution. It is basically a wrapper around a list of
    :class:`Callpoint` objects representing frames.

    Args:
        frames (list): A list of frame objects in the stack.

    .. note ::

      ``TracebackInfo`` can represent both exception tracebacks and
      non-exception tracebacks (aka stack traces). As a result, there
      is no ``TracebackInfo.from_current()``, as that would be
      ambiguous. Instead, call :meth:`TracebackInfo.from_frame`
      without the *frame* argument for a stack trace, or
      :meth:`TracebackInfo.from_traceback` without the *tb* argument
      for an exception traceback.
    c                     || _         d S r   frames)r   rz   s     r   r   zTracebackInfo.__init__   s    r   Nr$   c                 :   g }|t          j        |          }|t          t           dd          }d}|I||k     rC| j                            |          }|                    |           |j        }|dz  }|||k     C|                                  | |          S )a  Create a new TracebackInfo *frame* by recurring up in the stack a
        max of *limit* times. If *frame* is unset, get the frame from
        :func:`sys._getframe` using *level*.

        Args:
            frame (types.FrameType): frame object from
                :func:`sys._getframe` or elsewhere. Defaults to result
                of :func:`sys.get_frame`.
            level (int): If *frame* is unset, the desired frame is
                this many levels up the stack from the invocation of
                this method. Default ``1`` (i.e., caller of this method).
            limit (int): max number of parent frames to extract
                (defaults to :data:`sys.tracebacklimit`)

        Ntracebacklimit  r   r$   )r&   r'   r   callpoint_typer(   appendf_backreverse)r)   r+   r*   limitr    nitems          r   r(   zTracebackInfo.from_frame   s    " =M%((E=C!1488EAII%0077DJJtLEFA	 AII
 	s3xxr   c                 >   g }|*t          j                    d         }|t          d          |t          t           dd          }d}|I||k     rC| j                            |          }|                    |           |j        }|dz  }|||k     C | |          S )a  Create a new TracebackInfo from the traceback *tb* by recurring
        up in the stack a max of *limit* times. If *tb* is unset, get
        the traceback from the currently handled exception. If no
        exception is being handled, raise a :exc:`ValueError`.

        Args:

            frame (types.TracebackType): traceback object from
                :func:`sys.exc_info` or elsewhere. If absent or set to
                ``None``, defaults to ``sys.exc_info()[2]``, and
                raises a :exc:`ValueError` if no exception is
                currently being handled.
            limit (int): max number of parent frames to extract
                (defaults to :data:`sys.tracebacklimit`)

        N   z(no tb set and no exception being handledr|   r}   r   r$   )r&   exc_info
ValueErrorr   r~   r=   r   tb_next)r)   r<   r   r    r   r   s         r   from_tracebackzTracebackInfo.from_traceback  s    $ :"Bz !KLLL=C!1488EnU%--b11DJJtBFA	 nU
 s3xxr   c                 $     | |d                   S )z*Complements :meth:`TracebackInfo.to_dict`.rz   rE   )r)   ds     r   	from_dictzTracebackInfo.from_dict9  s     s1X;r   c                 (    dd | j         D             iS )z\Returns a dict with a list of :class:`Callpoint` frames converted
        to dicts.
        rz   c                 6    g | ]}|                                 S rE   )r#   r@   fs     r   rB   z)TracebackInfo.to_dict.<locals>.<listcomp>C  s     <<<1199;;<<<r   ry   rs   s    r   r#   zTracebackInfo.to_dict?  s      <<<<<==r   c                 *    t          | j                  S r   )ru   rz   rs   s    r   rv   zTracebackInfo.__len__E  s    4;r   c                 *    t          | j                  S r   )iterrz   rs   s    r   __iter__zTracebackInfo.__iter__H  s    DK   r   c                     | j         j        }| j        rd| j        d         }nd}d| dt          | j                   | dS )Nz last=r/   <z frames=>)rH   r.   rz   ru   )r   rN   
frame_parts      r   rK   zTracebackInfo.__repr__K  sX    ^$; 	5$+b/55JJJ>2>>s4;//>>>>>r   c                 *    |                                  S r   )get_formattedrs   s    r   rq   zTracebackInfo.__str__U  s    !!###r   c                 X    d}|d                     d | j        D                       z  }|S )zReturns a string as formatted in the traditional Python
        built-in style observable when an exception is not caught. In
        other words, mimics :func:`traceback.format_tb` and
        :func:`traceback.format_stack`.
        z#Traceback (most recent call last):
r/   c                 6    g | ]}|                                 S rE   )rU   r   s     r   rB   z/TracebackInfo.get_formatted.<locals>.<listcomp>_  s"    >>>Q((>>>r   )rM   rz   rT   s     r   r   zTracebackInfo.get_formattedX  s5     5rww>>$+>>>???
r   )Nr$   NNN)r.   rV   rW   rX   r   r~   r   rY   r(   r   r   r#   rv   r   rK   rq   r   rE   r   r   r   r      s         $ N      [<    [@     [ 
> > >     ! ! !? ? ?$ $ $    r   r   c                   `    e Zd ZdZeZd Zed             Zed             Z	d Z
d Zd Zd Zd	S )
r   a#  An ExceptionInfo object ties together three main fields suitable
    for representing an instance of an exception: The exception type
    name, a string representation of the exception itself (the
    exception message), and information about the traceback (stored as
    a :class:`TracebackInfo` object).

    These fields line up with :func:`sys.exc_info`, but unlike the
    values returned by that function, ExceptionInfo does not hold any
    references to the real exception or traceback. This property makes
    it suitable for serialization or long-term retention, without
    worrying about formatting pitfalls, circular references, or leaking memory.

    Args:

        exc_type (str): The exception type name.
        exc_msg (str): String representation of the exception value.
        tb_info (TracebackInfo): Information about the stack trace of the
            exception.

    Like the :class:`TracebackInfo`, ExceptionInfo is most commonly
    instantiated from one of its classmethods: :meth:`from_exc_info`
    or :meth:`from_current`.
    c                 0    || _         || _        || _        d S r   )exc_typeexc_msgtb_info)r   r   r   r   s       r   r   zExceptionInfo.__init__  s     r   c                     |j         }|j        }|dvr| d| }t          |          }| j                            |          } | |||          S )zCreate an :class:`ExceptionInfo` object from the exception's type,
        value, and traceback, as returned by :func:`sys.exc_info`. See
        also :meth:`from_current`.
        )__main____builtin__
exceptionsbuiltins.)r.   rV   	_some_strtb_info_typer   )r)   r   	exc_value	tracebacktype_strtype_modval_strr   s           r   from_exc_infozExceptionInfo.from_exc_info  sj     $&PPP"//X//HI&&"11)<<s8Wg...r   c                 8     | j         t          j                     S )zCreate an :class:`ExceptionInfo` object from the current exception
        being handled, by way of :func:`sys.exc_info`. Will raise an
        exception if no exception is currently being handled.
        )r   r&   r   )r)   s    r   r,   zExceptionInfo.from_current  s     !s #,..11r   c                 P    | j         | j        | j                                        dS )zjGet a :class:`dict` representation of the ExceptionInfo, suitable
        for JSON serialization.
        )r   r   exc_tb)r   r   r   r#   rs   s    r   r#   zExceptionInfo.to_dict  s.     !M<,..002 2 	2r   c                     | j         j        }	 t          | j        j                  }d| j        j        d         }n# t
          $ r d}d}Y nw xY w|| j        | j        ||f}d|z  S )Nz, last=r   r   r/   z<%s [%s: %s] (%s frames%s)>)rH   r.   ru   r   rz   	Exceptionr   r   )r   rN   
len_frames
last_framerO   s        r   rK   zExceptionInfo.__repr__  s    ^$	T\011J>4<#6r#:>>JJ 	 	 	JJJJ	 DM4<ZH,t33s   .= AAc                     | j                                         }d                    || j         d| j         g          S )zReturns a string formatted in the traditional Python
        built-in style observable when an exception is not caught. In
        other words, mimics :func:`traceback.format_exception`.
        r/   : )r   r   rM   r   r   )r   tb_strs     r   r   zExceptionInfo.get_formatted  s@     ++--ww4= B BDL B BCDDDr   c                 $    | j          d| j         S )Nr   )r   r   rs   s    r   get_formatted_exception_onlyz*ExceptionInfo.get_formatted_exception_only  s    -114<111r   N)r.   rV   rW   rX   r   r   r   rY   r   r,   r#   rK   r   r   rE   r   r   r   r   c  s         2 !L   / / [/ 2 2 [22 2 2	4 	4 	4E E E2 2 2 2 2r   r   c                   n     e Zd ZdZ fdZe fd            Ze fd            Zd	dZd Z	 fdZ
 xZS )
r   a`  The ContextualCallpoint is a :class:`Callpoint` subtype with the
    exact same API and storing two additional values:

      1. :func:`repr` outputs for local variables from the Callpoint's scope
      2. A number of lines before and after the Callpoint's line of code

    The ContextualCallpoint is used by the :class:`ContextualTracebackInfo`.
    c                     |                     di           | _        |                     dg           | _        |                     dg           | _         t	                      j        |i | d S )Nlocal_reprs	pre_lines
post_lines)popr   r   r   rJ   r   )r   rG   kwrH   s      r   r   zContextualCallpoint.__init__  se    66-44R00&&r22!"r"""""r   c                     t                                          |          }|                    |j                   |                                 |S )z)Identical to :meth:`Callpoint.from_frame`)rJ   r(   _populate_local_reprsf_locals_populate_context_lines)r)   r+   r    rH   s      r   r(   zContextualCallpoint.from_frame  sI     gg  ''!!%.111##%%%
r   c                     t                                          |          }|                    |j        j                   |                                 |S )z&Identical to :meth:`Callpoint.from_tb`)rJ   r=   r   r9   r   r   )r)   r<   r    rH   s      r   r=   zContextualCallpoint.from_tb  sJ     ggoob!!!!"+"6777##%%%
r      c                 J    t            j        c}	  j        j        n# t          $ r d Y nw xY wt          d||z
            } fdt          ||          D             }| j        d d <    fdt          |dz   |dz   |z             D             }| j        d d <   d S )Nr   c                 4    g | ]} j         |          S rE   r   r@   lnDLrc   r   s     r   rB   z?ContextualCallpoint._populate_context_lines.<locals>.<listcomp>  s:     : : : R("n== : : :r   c                 4    g | ]} j         |          S rE   r   r   s     r   rB   z?ContextualCallpoint._populate_context_lines.<locals>.<listcomp>  s@     G G G b)2~>> G G Gr   r$   )	r   r   r   rc   r   maxranger   r   )r   pivotr   
start_liner   r   r   rc   s   `     @@r   r   z+ContextualCallpoint._populate_context_lines  s   "DK
F	"!Y5NN 	" 	" 	"!NNN	"FUN++
: : : : : :$Z88: : :	%qqqG G G G G G %fqj&1*u2D E EG G G
's   ! 00c                     | j         }|                                D ]D\  }}	 t          |          ||<   # t          $ r dt	          |          j        z  }|||<   Y Aw xY wd S Nz<unprintable %s object>)r   itemsrF   r   typer.   )r   r   r   kv	surrogates         r   r   z)ContextualCallpoint._populate_local_reprs  s    &NN$$ 	+ 	+DAq+!%aA + + +5Q8HH	!*A+ 	s   5&AAc                     t                                                      }t           j                  |d<    j        t           j                  z
  fdt           j                  D             }t          |          D ]\  }}|d         r n|r
||d         }||d<    fdt           j                  D             }d}t          |          D ]\  }}|d         r|}|d|dz            }||d	<   |S )
a  
        Same principle as :meth:`Callpoint.to_dict`, but with the added
        contextual values. With ``ContextualCallpoint.to_dict()``,
        each frame will now be represented like::

          {'func_name': 'print_example',
           'lineno': 0,
           'module_name': 'example_module',
           'module_path': '/home/example/example_module.pyc',
           'lasti': 0,
           'line': 'print "example"',
           'locals': {'variable': '"value"'},
           'pre_lines': ['variable = "value"'],
           'post_lines': []}

        The locals dictionary and line lists are copies and can be mutated
        freely.
        localsc                 @    g | ]\  }}|z   t          |          d S )r   r   )r   )r@   ilr   s      r   rB   z/ContextualCallpoint.to_dict.<locals>.<listcomp>  s?     < < <A !+QA?? < < <r   r   Nr   c                 J    g | ]\  }}j         |z   t          |          d  S r   )r   r   )r@   r   r   r   s      r   rB   z/ContextualCallpoint.to_dict.<locals>.<listcomp>  sA     > > >!Q "&q#a&&AA > > >r   r   r$   r   )	rJ   r#   dictr   r   ru   r   	enumerater   )	r   r    r   r   r   r   _lastr   rH   s	   `      @r   r#   zContextualCallpoint.to_dict  sO   & ggooT-..H [3t~#6#66
< < < <!*4>!:!:< < <	 !++ 	 	GAtF|  	&!!""I$K> > > >"+DO"<"<> > >
 ,, 	 	GAtF| 

+
&L
r   )r   )r.   rV   rW   rX   r   rY   r(   r=   r   r   r#   rZ   r[   s   @r   r   r     s         # # # # #     [     [     , , , , , , , , ,r   r   c                       e Zd ZdZeZdS )r   zThe ContextualTracebackInfo type is a :class:`TracebackInfo`
    subtype that is used by :class:`ContextualExceptionInfo` and uses
    the :class:`ContextualCallpoint` as its frame-representing
    primitive.
    N)r.   rV   rW   rX   r   r~   rE   r   r   r   r   "  s         
 )NNNr   r   c                       e Zd ZdZeZdS )r   a>  The ContextualTracebackInfo type is a :class:`TracebackInfo`
    subtype that uses the :class:`ContextualCallpoint` as its
    frame-representing primitive.

    It carries with it most of the exception information required to
    recreate the widely recognizable "500" page for debugging Django
    applications.
    N)r.   rV   rW   rX   r   r   rE   r   r   r   r   +  s          +LLLr   r   c                    | t          | |          gS | j        }| j        }|dvr|dz   |z   }t          | t                    st          ||          gS g }|j        pd}t          |j                  pd}|                    d| d| d           |j	        }|j
        }||                    d	|                                z             |f|                    d          d|                                         }	d
 |	D             }	|                    dd                    |	          z             |j        pd}
|                    | d|
 d           |S )a  Format the exception part of a traceback.

    The arguments are the exception type and value such as given by
    sys.last_type and sys.last_value. The return value is a list of
    strings, each ending in a newline.

    Normally, the list contains a single string; however, for
    SyntaxError exceptions, it contains several lines that (when
    printed) display detailed information about where the syntax
    error occurred.

    The message indicating which exception occurred is always the last
    string in the list.

    N)r   r   r   r   z<string>?z  File "z", line rR   z    %s
c              3   F   K   | ]}|                                 r|pd V  dS ) N)isspace)r@   cs     r   	<genexpr>z(format_exception_only.<locals>.<genexpr>a  s4      II199;;,13IIIIIIr   z   %s^
r/   z<no detail available>r   )_format_final_exc_liner.   rV   
issubclassSyntaxErrorr]   r   r   r   textoffsetrS   rn   lstriprM   msg)etypevaluestypesmodlinesr]   r   badliner   
caretspacer   s              r   format_exception_onlyr   8  s   $ }&ue4455NED999s
U"e[)) 6&ue4455 E~+H%#F	LL8H88f888999jG\FZ'--//1222 --gvg6==??JIIjIIIJLLbggj&9&99:::
)
..C	LLE$$S$$$%%%Lr   c                 p    	 t          |           S # t          $ r Y nw xY wdt          |           j        z  S r   )r   r   r   r.   )r   s    r   r   r   j  sG    5zz   $tE{{';;;s    
c                 H    t          |          }||sd| z  }n|  d| d}|S )Nz%s
r   rR   )r   )r   r   valuestrr   s       r   r   r   r  s>    H}H}~''8'''Kr   c                     |t           j        }|r:t                              ||          }t	          t          |          d|           t          | |          D ]}t	          |d|           dS )a  Print exception up to 'limit' stack trace entries from 'tb' to 'file'.

    This differs from print_tb() in the following ways: (1) if
    traceback is not None, it prints a header "Traceback (most recent
    call last):"; (2) it prints the exception type and value after the
    stack trace; (3) if type is SyntaxError and value has the
    appropriate format, it prints the line where the syntax error
    occurred with a caret on the next line indicating the approximate
    position of the error.
    Nr/   )endfile)r&   stderrr   r   printr   r   )r   r   r<   r   r  tbir   s          r   r	   r	   {  s     |z	 +**2u55c#hhBT****%eU33 ' 'd&&&&&' 'r   c                  (    t           t          _        dS )z
    Sets the default exception hook :func:`sys.excepthook` to the
    :func:`tbutils.print_exception` that uses all the ``tbutils``
    facilities to provide a consistent output behavior.
    N)r	   r&   
excepthookrE   r   r   fix_print_exceptionr    s     %CNNNr   zD^File "(?P<filepath>.+)", line (?P<lineno>\d+), in (?P<funcname>.+)$z.^File "(?P<filepath>.+)", line (?P<lineno>\d+)z^[~^ ]*$c                   X    e Zd ZdZd	dZed             Zd Zd Zd Z	e
d             ZdS )
r
   zStores a parsed traceback and exception as would be typically
    output by :func:`sys.excepthook` or
    :func:`traceback.print_exception`.

    .. note:

       Does not currently store SyntaxError details such as column.

    Nc                 N    || _         || _        t          |pg           | _        d S r   r   r   listrz   )r   exc_type_namer   rz   s       r   r   zParsedException.__init__  s'    %6<R((r   c                 L    	 | j         d         d         S # t          $ r Y dS w xY w)z~
        The file path of module containing the function that raised the
        exception, or None if not available.
        r   filepathN)rz   
IndexErrorrs   s    r   source_filezParsedException.source_file  s:    	;r?:.. 	 	 	44	s    
##c                 F    | j         | j        t          | j                  dS )z0Get a copy as a JSON-serializable :class:`dict`.)r   r   rz   r  rs   s    r   r#   zParsedException.to_dict  s(     M<t{++- - 	-r   c                 T    | j         j        }|d| j        d| j        d| j        dS )N(rC   z	, frames=))rH   r.   r   r   rz   )r   rN   s     r   rK   zParsedException.__repr__  s7    ^$22t}}}dlllDKKKA 	Br   c           	         dg}| j         D ]m}|                    d                    |d         |d         |d                              |                    d          }|r|                    d|            n| j        r%|                    | j         d| j                    n|                    | j                    d	                    |          S )
a  Formats the exception and its traceback into the standard format,
        as returned by the traceback module.

        ``ParsedException.from_string(text).to_string()`` should yield
        ``text``.

        .. note::

           Note that this method does not output "anchors" (e.g.,
           ``~~~~~^^``), as were added in Python 3.13. See the built-in
           ``traceback`` module if these are necessary.
        "Traceback (most recent call last):z  File "{}", line {}, in {}r  r   funcnamesource_linerQ   r   rR   )rz   r   rL   r5   r   r   rM   )r   r   r+   r  s       r   	to_stringzParsedException.to_string  s     66[ 	3 	3ELL6==eJ>O;@?;@;LN N O O O  ))M22K 31K11222< 	-LLDM;;T\;;<<<<LLDM+,,,yyr   c                    t          |t                    s|                    d          }|                                                                }|rJ|d         }|                    d          r*|                    d          r|                                 nn|J|r(|d                                         dk    r
d}t          }nYt          |          dk    r7|d                                                             d	          r
d}t          }nt          d
          g }|}	 ||                                         }|                    |          }	|	r|	                                }
	 ||dz            }n# t          $ r d}Y nw xY w|                                }|                    |          s|                    d          sd|
d<   n
||
d<   |dz  }t                               ||dz                      r|dz  }nn|dz  }|                    |
           	 d                    ||d                   }|                    d          \  }}}n# t(          $ r d\  }}Y nw xY w | |||          S )a/  Parse a traceback and exception from the text *tb_str*. This text
        is expected to have been decoded, otherwise it will be
        interpreted as UTF-8.

        This method does not search a larger body of text for
        tracebacks. If the first line of the text passed does not
        match one of the known patterns, a :exc:`ValueError` will be
        raised. This method will ignore trailing text after the end of
        the first traceback.

        Args:
            tb_str (str): The traceback text (:class:`unicode` or UTF-8 bytes)
        zutf-8r   z
Exception ignoredr   r  r$   ^z$unrecognized traceback string formatTr/   r   r  rR   Nr   )r/   r/   )r   r   decoder   
splitlines
startswithendswithr   rS   	_frame_reru   _se_frame_rer   match	groupdictr  _underline_rer   rM   	partitionr   )r)   r   tb_linesclr   frame_rerz   line_no
frame_lineframe_match
frame_dict	next_linenext_line_strippedexc_liner   _r   s                    r   from_stringzParsedException.from_string  s    &#&& 	,]]7++F==??--//
  	"B}}\** r{{9/E/E   	  
	E))++/SSSJ HH]]Q8B<#6#6#8#8#C#CC#H#H J#HHCDDD	&!'*0022J"..44K (2244
# (1 5II! # # # "III# &/__%6%6" '9::! &0055! 13J}--0BJ}-qLG &&x!'<== Q,'qLGMM*%%%;	&>	'yy'((!344H#+#5#5d#;#; Ha 	' 	' 	' &Hggg	' s8Wf---s$   +E7 7FF6I I&%I&r   )r.   rV   rW   rX   r   propertyr  r#   rK   r  rY   r7  rE   r   r   r
   r
     s         ) ) ) )
   X- - -B B B
     8 N. N. [N. N. N.r   r
   r   )rX   rer&   rk   __all__r   r   r   r   r   r   r   r   r   r   r	   r  compiler&  r'  r*  r
   ParsedTBrE   r   r   <module>r=     sP  > , 
			 



    H H H
] ] ] ] ] ] ] ]@5 5 5 5 5 5 5 5r       DU2 U2 U2 U2 U2 U2 U2 U2pd d d d d) d d dN) ) ) ) )m ) ) )	+ 	+ 	+ 	+ 	+m 	+ 	+ 	+. . .d< < <  ' ' ' ',% % % BJ 1 2 2	rzKLL
;''P. P. P. P. P. P. P. P.f r   