
    	hG                       d Z 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 ddlmZmZmZ dd	lmZ g d
ZdZdZdZeeed         f         Ze G d d                      Ze G d d                      Ze G d d                      Ze G d d                      Zd/dZd0d1dZd ed!d2d,Z G d- d.          ZdS )3z
Extract a structured traceback from an exception.

`Contributed by Will McGugan
<https://github.com/hynek/structlog/pull/407#issuecomment-1150926246>`_ from
`rich.traceback
<https://github.com/Textualize/rich/blob/972dedff/rich/traceback.py>`_.
    )annotationsN)asdict	dataclassfield)walk_tb)TracebackType)AnyTupleUnion   )ExcInfo)ExceptionDictTransformerFrameStackSyntaxError_Traceextractsafe_strto_reprTP   2   )NNNc                  N    e Zd ZU dZded<   ded<   ded<   dZded<   d	Zd
ed<   d	S )r   z*
    Represents a single stack frame.
    strfilenameintlinenoname lineNzdict[str, str] | Nonelocals)__name__
__module____qualname____doc____annotations__r   r         a/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/structlog/tracebacks.pyr   r   .   sW           MMMKKKIIIDNNNN$(F((((((r'   r   c                  F    e Zd ZU dZded<   ded<   ded<   ded<   ded<   d	S )
r   zL
    Contains detailed information about :exc:`SyntaxError` exceptions.
    r   offsetr   r   r   r   msgNr!   r"   r#   r$   r%   r&   r'   r(   r   r   ;   sI           KKKMMMIIIKKKHHHHHr'   r   c                  f    e Zd ZU dZded<   ded<   dZded<   dZd	ed
<    ee          Z	ded<   dS )r   z=
    Represents an exception and a list of stack frames.
    r   exc_type	exc_valueNzSyntaxError_ | Nonesyntax_errorFboolis_cause)default_factoryzlist[Frame]frames)
r!   r"   r#   r$   r%   r0   r2   r   listr4   r&   r'   r(   r   r   H   sp           MMMNNN(,L,,,,H%555F555555r'   r   c                      e Zd ZU dZded<   dS )r   z/
    Container for a list of stack traces.
    zlist[Stack]stacksNr,   r&   r'   r(   r   r   U   s*           r'   r   _objectr	   returnr   c                v    	 t          |           S # t          $ r}dt          |          dcY d}~S d}~ww xY w)z1Don't allow exceptions from __str__ to propegate.z<str-error >N)r   	Exception)r8   errors     r(   r   r   ^   sX    -7|| - - -,SZZ,,,,,,,,,-s    
8388obj
max_string
int | Nonec                   t          | t                    r| }n;	 t          |           }n*# t          $ r}dt          |          d}Y d}~nd}~ww xY w|4t	          |          |k    r!t	          |          |z
  }|d|         d| }|S )z0Get repr string for an object, but catch errors.z<repr-error r;   N+)
isinstancer   reprr<   len)r>   r?   obj_reprr=   	truncateds        r(   r   r   f   s    #s 6	6CyyHH 	6 	6 	65c%jj555HHHHHH	6 #h--*"<"<MMJ.	{
{+;;	;;Os   * 
AAAFshow_localslocals_max_stringr.   type[BaseException]r/   BaseException	tracebackTracebackType | NonerI   r1   rJ   r   c          	        g }d}	 t          t          | j                  t          |          |          }t          |t                    r:t          |j        pd|j        pd|j        pd|j	        pd|j
                  |_        |                    |           |j        j        }t          |          D ]\  }	}
|	j        j        }|r4|                    d          st$          j                            |          }t+          |pd|
|	j        j        |r%fd	|	j                                        D             nd
          } ||           t3          |dd
          }|r|j        r|j        } |}|j        }d}x|j        }|r,|j        r%t3          |dd          s|j        } |}|j        }d}	 t;          |          S )a  
    Extract traceback information.

    Arguments:

        exc_type: Exception type.

        exc_value: Exception value.

        traceback: Python Traceback object.

        show_locals: Enable display of local variables. Defaults to False.

        locals_max_string:
            Maximum length of string before truncating, or ``None`` to disable.

        max_frames: Maximum number of frames in each stack

    Returns:
        A Trace instance with structured information about all exceptions.

    .. versionadded:: 22.1.0
    FT)r.   r/   r2   r   ?r   )r*   r   r   r   r+   <c                :    i | ]\  }}|t          |           S ))r?   )r   ).0keyvaluerJ   s      r(   
<dictcomp>zextract.<locals>.<dictcomp>   s=       "U 3DEEE  r'   N)r   r   r   r    	__cause____suppress_context__)r7   )r   r   r!   rC   SyntaxErrorr   r*   r   r   textr+   r0   appendr4   r   f_codeco_filename
startswithospathabspathr   co_namef_localsitemsgetattr__traceback__	__class____context__r   )r.   r/   rM   rI   rJ   r7   r2   stackr[   frame_summaryline_nor   framecauses       `         r(   r   r   w   s;   @ FH9h/00y))
 
 
 i-- 	!- ',1"+2s ',1^)rM" " "E 	e$&-i&8&8 	 	"M7$+7H 5 3 3C 8 8 57??844!S")1
 	    &3&<&B&B&D&D   
 
 
 
E F5MMMM	;55 	U( 	HI+IH%		#		 I'=uEE		
 HI+IH 	r'   c                  *    e Zd ZdZdeefdd
ZddZdS )r   a  
    Return a list of exception stack dictionaries for an exception.

    These dictionaries are based on :class:`Stack` instances generated by
    :func:`extract()` and can be dumped to JSON.

    Arguments:

        show_locals:
            Whether or not to include the values of a stack frame's local
            variables.

        locals_max_string:
            The maximum length after which long string representations are
            truncated.

        max_frames:
            Maximum number of frames in each stack.  Frames are removed from
            the inside out.  The idea is, that the first frames represent your
            code responsible for the exception and last frames the code where
            the exception actually happened.  With larger web frameworks, this
            does not always work, so you should stick with the default.

    .. seealso::
        :doc:`exceptions` for a broader explanation of *structlog*'s exception
        features.
    TrI   r1   rJ   r   
max_framesr9   Nonec                    |dk     rd| }t          |          |dk     rd| }t          |          || _        || _        || _        d S )Nr   z""locals_max_string" must be >= 0:    z"max_frames" must be >= 2: )
ValueErrorrI   rJ   ro   )selfrI   rJ   ro   r+   s        r(   __init__z!ExceptionDictTransformer.__init__   sf     q  J7HJJCS//!>><
<<CS//!&!2$r'   exc_infor   list[dict[str, Any]]c           	     j   t          || j        | j        d}|j        D ]}t	          |j                  | j        k    r | j        dz  }t          dddt	          |j                  d|z  z
             }g |j        d |         ||j        | d          |j        d d <   d |j        D             S )NrH   rr   r   zSkipped frames: )r   r   r   c                ,    g | ]}t          |          S r&   )r   )rS   ri   s     r(   
<listcomp>z5ExceptionDictTransformer.__call__.<locals>.<listcomp>  s    888%u888r'   )r   rI   rJ   r7   rE   r4   ro   r   )rt   rv   traceri   half
fake_frames         r(   __call__z!ExceptionDictTransformer.__call__  s    ("4
 
 
 \ 	 	E5<  DO33 1$  HEL(9(9QX(FHH  J
ete$ teff%ELOO 985<8888r'   N)rI   r1   rJ   r   ro   r   r9   rp   )rv   r   r9   rw   )r!   r"   r#   r$   LOCALS_MAX_STRING
MAX_FRAMESru   r   r&   r'   r(   r   r      sV         < !!2$	% % % % % 9 9 9 9 9 9r'   r   )r8   r	   r9   r   )N)r>   r	   r?   r@   r9   r   )r.   rK   r/   rL   rM   rN   rI   r1   rJ   r   r9   r   )r$   
__future__r   r_   dataclassesr   r   r   rM   r   typesr   typingr	   r
   r   r   __all__SHOW_LOCALSr   r   
OptExcInfor   r   r   r   r   r   r   r   r&   r'   r(   <module>r      s<    # " " " " " 				 0 0 0 0 0 0 0 0 0 0             $ $ $ $ $ $ $ $ $ $      	 	 	  
7E"2334
 	) 	) 	) 	) 	) 	) 	) 	) 	 	 	 	 	 	 	 	 	6 	6 	6 	6 	6 	6 	6 	6        - - - -    , .^  ^  ^  ^  ^  ^ BF9 F9 F9 F9 F9 F9 F9 F9 F9 F9r'   