
    "h9                       d Z ddlmZ ddl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mZmZmZmZ 	 ddlZddlZdd	lmZ g d
Z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"	 	 	 d 	 	 	 	 	 	 	 	 	 d!dZ#deedddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ$ G d d      Z%y# e$ r dZY w xY w)#z
Extract a structured traceback from an exception.

Based on work 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)
ModuleTypeTracebackType)AnyIterableSequenceTupleUnion   )ExcInfo)ExceptionDictTransformerFrameStackSyntaxError_Traceextractsafe_strto_reprT
   P   2   )NNNc                  >    e Zd ZU dZded<   ded<   ded<   dZded	<   y)
r   z*
    Represents a single stack frame.
    strfilenameintlinenonameNzdict[str, str] | Nonelocals)__name__
__module____qualname____doc____annotations__r"        Q/var/www/html/sandstorm/venv/lib/python3.12/site-packages/structlog/tracebacks.pyr   r   7   s#     MK
I$(F!(r)   r   c                  D    e Zd ZU dZded<   ded<   ded<   ded<   ded<   y	)
r   zL
    Contains detailed information about :exc:`SyntaxError` exceptions.
    r   offsetr   r   liner    msgNr#   r$   r%   r&   r'   r(   r)   r*   r   r   C   s"     KM
IK	Hr)   r   c                  z    e Zd ZU dZded<   ded<    ee      Zded<   dZd	ed
<   dZ	ded<    ee      Z
ded<   y)r   z
    Represents an exception and a list of stack frames.

    .. versionchanged:: 25.2.0
       Added the *exc_notes* field.
    r   exc_type	exc_value)default_factoryz	list[str]	exc_notesNzSyntaxError_ | Nonesyntax_errorFboolis_causezlist[Frame]frames)r#   r$   r%   r&   r'   r   listr4   r5   r7   r8   r(   r)   r*   r   r   P   sF     MN 6Iy6(,L%,Hd5FK5r)   r   c                      e Zd ZU dZded<   y)r   z/
    Container for a list of stack traces.
    zlist[Stack]stacksNr/   r(   r)   r*   r   r   a   s     r)   r   c                d    	 t        |       S # t        $ r}dt        |      dcY d}~S d}~ww xY w)z1Don't allow exceptions from __str__ to propagate.z<str-error >N)r   	Exception)_objecterrors     r*   r   r   j   s4    -7| -SZN!,,-s   
 	/*//c                   |r8t         2t         j                  j                  | ||      j                         }|S 	 t	        | t
        t        f      r8|(t        |       |kD  rt        |       |z
  }| d| d| }|S t        |       }	 |S t        |       }|&t        |      |kD  rt        |      |z
  }|d| d| }|S # t        $ r}dt        |      d}Y d}~|S d}~ww xY w)a  
    Get repr string for an object, but catch errors.

    :func:`repr()` is used for strings, too, so that secret wrappers that
    inherit from :func:`str` and overwrite ``__repr__()`` are handled correctly
    (i.e. secrets are not logged in plain text).

    Args:
        obj: Object to get a string representation for.

        max_length: Maximum length of containers before abbreviating, or
            ``None`` for no abbreviation.

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

        use_rich: If ``True`` (the default), use rich_ to compute the repr.
            If ``False`` or if rich_ is not installed, fall back to a simpler
            algorithm.

    Returns:
        The string representation of *obj*.

    .. versionchanged:: 24.3.0
       Added *max_length* argument.  Use :program:`rich` to render locals if it
       is available.  Call :func:`repr()` on strings in fallback
       implementation.
    N)
max_length
max_string+z<repr-error r=   )
richprettytraverserender
isinstancer   byteslenreprr>   )objrB   rC   use_richobj_repr	truncatedr@   s          r*   r   r   r   s   D D$ ;;''J: ( 

&( 	, O	6#U|,)c#h.C #C: 5I"%kz"2!5QykBH O  $CyH O  9)c(mj.H #H
 :I"*;J"7!:!I;GH O  	6%c%j^15HO	6s#   >B? <B? 
3B? ?	C"CC"Fshow_localslocals_max_lengthlocals_max_stringlocals_hide_dunderlocals_hide_sunderrN   c                  g }	d}
	 t        t        | j                        t        |      t        |dd      D cg c]  }t        |       c}|
      }t	        |t
              rWt        |j                  xs d|j                  xs d|j                  xs d|j                  xs d|j                  	      |_        |	j                  |       |j                  j                  }	 	 	 	 dfd
}t        |      D ]  \  }}|j                   j"                  }|r0|j%                  d      st&        j(                  j+                  |      }t-        |xs d||j                   j.                  |rA ||j0                  j3                               D ci c]  \  }}|t5        ||||       c}}nd      } ||        t        |dd      }|r*|j6                  r|j8                  } |}|j6                  }d}
|j:                  }|r7|j6                  r+t        |dd      s|j8                  } |}|j6                  }d}
2	 t=        |	      S c c}w c c}}w )a  
    Extract traceback information.

    Args:
        exc_type: Exception type.

        exc_value: Exception value.

        traceback: Python Traceback object.

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

        locals_max_length:
            Maximum length of containers before abbreviating, or ``None`` for
            no abbreviation.

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

        locals_hide_dunder:
            Hide locals prefixed with double underscore.
            Defaults to True.

        locals_hide_sunder:
            Hide locals prefixed with single underscore.
            This implies hiding *locals_hide_dunder*.
            Defaults to False.

        use_rich: If ``True`` (the default), use rich_ to compute the repr.
            If ``False`` or if rich_ is not installed, fall back to a simpler
            algorithm.

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

    .. versionadded:: 22.1.0
    .. versionchanged:: 24.3.0
       Added *locals_max_length*, *locals_hide_sunder*, *locals_hide_dunder*
       and *use_rich* arguments.
    FT	__notes__r(   )r1   r2   r4   r7   r   ? )r,   r   r    r-   r.   c              3     K   ss| E d{    y| D ]3  \  }}r|j                  d      rr|j                  d      r.||f 5 y7 >w)z-Extract locals from an iterator of key pairs.N___
startswith)iter_localskeyvaluerU   rV   s      r*   
get_localszextract.<locals>.get_locals   s_      '*<&&&) !
U%#..*>%#..*=5j ! 's   
AA?A<)rB   rC   rN   N)r   r    r!   r"   	__cause____suppress_context__)r;   )r`   Iterable[tuple[str, object]]returnrg   )r   r   r#   getattrrI   SyntaxErrorr   r,   r   r    textr.   r5   appendr8   r   f_codeco_filenamer_   ospathabspathr   co_namef_localsitemsr   __traceback__	__class____context__r   )r1   r2   	tracebackrR   rS   rT   rU   rV   rN   r;   r7   notestackrl   rc   frame_summaryline_nor   ra   rb   framecauses         ``              r*   r   r      sP   l FH
h//0y)+29k2+N#' 
 i-!- '',1"++2s '',1^^)rMM"E 	e$$	!5	!)	! '.i&8 	"M7$++77H 3 3C 877??84
 !S"))11 #	 +5)2288:+
 'C W!'8'8%-	 
 #E( 5M9	< 	;5U((HI++IH%%##I'=uEHI++IH 	kZ
s   IIc            	      V    e Zd ZdZeeedddedd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d	dZd
dZ	y)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.

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

        locals_max_length:
            Maximum length of containers before abbreviating, or ``None`` for
            no abbreviation.

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

        locals_hide_dunder:
            Hide locals prefixed with double underscore.
            Defaults to True.

        locals_hide_sunder:
            Hide locals prefixed with single underscore.
            This implies hiding *locals_hide_dunder*.
            Defaults to False.

        suppress:
            Optional sequence of modules or paths for which to suppress the
            display of locals even if *show_locals* is ``True``.

        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.

        use_rich: If ``True`` (the default), use rich_ to compute the repr of
            locals.  If ``False`` or if rich_ is not installed, fall back to
            a simpler algorithm.

    .. seealso::
        :doc:`exceptions` for a broader explanation of *structlog*'s exception
        features.

    .. versionchanged:: 24.3.0
       Added *locals_max_length*, *locals_hide_sunder*, *locals_hide_dunder*,
       *suppress* and *use_rich* arguments.

    .. versionchanged:: 25.1.0
       *locals_max_length* and *locals_max_string* may be None to disable
       truncation.
    TFr(   )rR   rS   rT   rU   rV   suppress
max_framesrN   c               h   ||dk  rd| }	t        |	      ||dk  rd| }	t        |	      |dk  rd| }	t        |	      || _        || _        || _        || _        || _        g | _        |D ]  }
t        |
t              sG|
j                  d|
d}	t        |	      t        j                  j                  |
j                        }n|
}t        j                  j                  t        j                  j                  |            }| j                  j                  |        || _        || _        y )Nr   z""locals_max_length" must be >= 0: z""locals_max_string" must be >= 0:    z"max_frames" must be >= 2: z"suppress" item z+ must be a module with '__file__' attribute)
ValueErrorrR   rS   rT   rU   rV   r   rI   r   __file__ro   rp   dirnamenormpathrq   rl   r   rN   )selfrR   rS   rT   rU   rV   r   r   rN   r.   suppress_entityrp   s               r*   __init__z!ExceptionDictTransformer.__init__~  sD    (->-B67H6IJCS/!(->-B67H6IJCS/!>/
|<CS/!&!2!2"4"4')' 	'Oos3"++3*?*= >; <  %S/)ww'?'?@&77##BGGOOD$9:DMM  &	' % r)   c           
        t        || j                  | j                  | j                  | j                  | 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   |j                  D cg c]  }t        |       }}|D ]3  }|d   D ])  d   t        fd	| j                  D              s'd= + 5 |S c c}w )
NrQ   r   rZ   zSkipped frames: )r   r    r!   r8   r"   c              3  F   K   | ]  }d    j                  |        yw)r   Nr^   ).0rp   
frame_dicts     r*   	<genexpr>z4ExceptionDictTransformer.__call__.<locals>.<genexpr>  s)      7 z*55d;7s   !)r   rR   rS   rT   rU   rV   rN   r;   rK   r8   r   r   r   anyr   )	r   exc_infotracerz   half
fake_framer;   
stack_dictr   s	           @r*   __call__z!ExceptionDictTransformer.__call__  sm   (("44"44#66#66]]
 \\ 	E5<< DOO3 1$  'ELL(9QX(F'GHJ
et$ tef%ELLO	$ .3\\:E&-::  	-J(2 -
h'/3 7 $7 4 #8,-	-  ;s   9EN)rR   r6   rS   r   rT   r   rU   r6   rV   r6   r   zIterable[str | ModuleType]r   r   rN   r6   rh   None)r   r   rh   zlist[dict[str, Any]])
r#   r$   r%   r&   SHOW_LOCALSLOCALS_MAX_LENGTHLOCALS_MAX_STRING
MAX_FRAMESr   r   r(   r)   r*   r   r   E  s    6v (!2!2#'#(/1$)! )! 	)!
 )! !)! !)! -)! )! )! 
)!V&r)   r   )r?   r
   rh   r   )NNT)
rM   r
   rB   
int | NonerC   r   rN   r6   rh   r   )r1   ztype[BaseException]r2   BaseExceptionrx   zTracebackType | NonerR   r6   rS   r   rT   r   rU   r6   rV   r6   rN   r6   rh   r   )&r&   
__future__r   ro   os.pathdataclassesr   r   r   rx   r   typesr   r	   typingr
   r   r   r   r   rE   rich.prettyImportErrorr   __all__r   r   r   r   
OptExcInfor   r   r   r   r   r   r   r   r(   r)   r*   <module>r      s   # 	  0 0  + 8 8 	   
7E"2334
 ) ) ) 	 	 	 6 6 6    - "!	;	;; ; 	;
 	;F ..#$R !R R  $R 
 R  R  R  R  R  R  R jJ JQ	  Ds   C C! C!