
    "h^                       d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZ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mZmZ 	 ddlZ	 ddl Z 	 ddl!Z!ddl"m#Z# ddl$m%Z% g dZ&ejN                  dk(  Z(dZ)dZ*d2dZ+eejX                  jZ                  Z-ejX                  j\                  Z.ejX                  j^                  Z/ej`                  jb                  Z1ej`                  jd                  Z2ej`                  jf                  Z3ej`                  jh                  Z4ej`                  jj                  Z5ej`                  jl                  Z6ejn                  jb                  Z8ndZ-dZ.dZ/dZ1dZ2dZ3dZ4dZ5dZ6dZ8e( xs eduZ9e9Z: G d de      Z;ee;ee;   f   Z< G d d       Z= G d! d"      Z> G d# d$e      Z?e G d% d&             Z@e G d' d(             ZA G d) d*      ZB eC       ZDd3d+ZEe G d, d-             ZF eF       ZG	 d3d.ZHe!eGZIne eHZIneEZI G d/ d0      ZJ eC       ZK	 	 	 	 	 	 	 	 d4d1ZLy# e$ r dZY w xY w# e$ r dZ Y w xY w# e$ r dZ!Y w xY w)5zz
Helpers that make development with *structlog* more pleasant.

See also the narrative documentation in `console-output`.
    )annotationsN)	dataclass)StringIO)
ModuleType)	AnyCallableLiteralProtocolSequenceTextIOTypeUnioncast   )_format_exception)_figure_out_exc_info)	EventDictExceptionRendererExcInfoWrappedLogger)Console)	Traceback)ConsoleRendererRichTracebackFormatterbetter_tracebackplain_tracebackrich_tracebackwin32z1{who} requires the {package} package installed.     c                B    |t        |       z
  }| dt        d|      z  z   S )z&
    Pads *s* to length *length*.
     r   )lenmax)slengthmissings      J/var/www/html/sandstorm/venv/lib/python3.12/site-packages/structlog/dev.py_padr(   F   s'     s1voGsc!Wo&&&    z[0mz[1mz[2mz[31mz[34mz[36mz[35mz[33mz[32mz[41mc                      e Zd ZU ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded	<   ded
<   ded<   ded<   ded<   ded<   y)_Stylesstrresetbrightlevel_criticallevel_exceptionlevel_error
level_warn
level_infolevel_debuglevel_notset	timestamplogger_namekv_keykv_valueN)__name__
__module____qualname____annotations__ r)   r'   r+   r+   p   sI    JKOONKMr)   r+   c                  @    e Zd ZeZeZeZeZ	eZ
eZeZeZeZeZeZeZeZy)_ColorfulStylesN)r:   r;   r<   	RESET_ALLr-   BRIGHTr.   REDr/   r0   r1   YELLOWr2   GREENr3   r4   RED_BACKr5   DIMr6   BLUEr7   CYANr8   MAGENTAr9   r>   r)   r'   r@   r@      sC    EFNOKJJKLIKFHr)   r@   c                  @    e Zd ZdZdZdZdZdZdZdZ	dZ
dZdZdZdZdZy)_PlainStyles N)r:   r;   r<   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r>   r)   r'   rL   rL      sC    EFNOKJJKLIKFHr)   rL   c                      e Zd ZdZddZy)ColumnFormatterz
    :class:`~typing.Protocol` for column formatters.

    See `KeyValueColumnFormatter` and `LogLevelColumnFormatter` for examples.

    .. versionadded:: 23.3.0
    c                     y)aK  
        Format *value* for *key*.

        This method is responsible for formatting, *key*, the ``=``, and the
        *value*. That means that it can use any string instead of the ``=`` and
        it can leave out both the *key* or the *value*.

        If it returns an empty string, the column is omitted completely.
        Nr>   )selfkeyvalues      r'   __call__zColumnFormatter.__call__   s    r)   NrR   r,   rS   objectreturnr,   )r:   r;   r<   __doc__rT   r>   r)   r'   rO   rO      s    	r)   rO   c                  &    e Zd ZU dZded<   ded<   y)Columna  
    A column defines the way a key-value pair is formatted, and, by it's
    position to the *columns* argument of `ConsoleRenderer`, the order in which
    it is rendered.

    Args:
        key:
            The key for which this column is responsible. Leave empty to define
            it as the default formatter.

        formatter: The formatter for columns with *key*.

    .. versionadded:: 23.3.0
    r,   rR   rO   	formatterN)r:   r;   r<   rX   r=   r>   r)   r'   rZ   rZ      s     
Hr)   rZ   c                  l    e Zd ZU dZded<   ded<   ded<   ded<   d	Zd
ed<   dZded<   dZded<   ddZy)KeyValueColumnFormattera  
    Format a key-value pair.

    Args:
        key_style: The style to apply to the key. If None, the key is omitted.

        value_style: The style to apply to the value.

        reset_style: The style to apply whenever a style is no longer needed.

        value_repr:
            A callable that returns the string representation of the value.

        width: The width to pad the value to. If 0, no padding is done.

        prefix:
            A string to prepend to the formatted key-value pair. May contain
            styles.

        postfix:
            A string to append to the formatted key-value pair. May contain
            styles.

    .. versionadded:: 23.3.0
    
str | None	key_styler,   value_stylereset_stylezCallable[[object], str]
value_reprr   intwidthrM   prefixpostfixc                   t               }| j                  r6|j                  | j                         |j                  | j                         | j                  X|j                  | j                         |j                  |       |j                  | j                         |j                  d       |j                  | j
                         |j                  t        | j                  |      | j                               |j                  | j                         | j                  r6|j                  | j                         |j                  | j                         |j                         S )N=)r   re   writera   r_   r`   r(   rb   rd   rf   getvalue)rQ   rR   rS   sios       r'   rT   z KeyValueColumnFormatter.__call__   s    j;;IIdkk"IId&&'>>%IIdnn%IIcNIId&&'IIcN		$""#		$tu-tzz:;		$""#<<IIdll#IId&&'||~r)   NrU   )	r:   r;   r<   rX   r=   rd   re   rf   rT   r>   r)   r'   r]   r]      sC    4 ''E3NFCGSr)   r]   c                  R    e Zd ZU dZded<   ded<   ded<   	 d	 	 	 	 	 	 	 dd	Zdd
Zy)LogLevelColumnFormattera  
    Format a log level according to *level_styles*.

    The width is padded to the longest level name (if *level_styles* is passed
    -- otherwise there's no way to know the lengths of all levels).

    Args:
        level_styles:
            A dictionary of level names to styles that are applied to it. If
            None, the level is formatted as a plain ``[level]``.

        reset_style:
            What to use to reset the style after the level name. Ignored if
            if *level_styles* is None.

        width:
            The width to pad the level to. If 0, no padding is done.

    .. versionadded:: 23.3.0
    .. versionadded:: 24.2.0 *width*
    dict[str, str] | Nonelevel_stylesr,   ra   rc   rd   Nc                    || _         |rC|dk(  rdn.t        t        | j                   j                         d             | _        || _        y d| _        d| _        y )Nr   c                    t        |       S Nr"   es    r'   <lambda>z2LogLevelColumnFormatter.__init__.<locals>.<lambda>4  s
    SV r)   rR   rM   )ro   r"   r#   keysrd   ra   )rQ   ro   ra   rd   s       r'   __init__z LogLevelColumnFormatter.__init__)  s\     ) A: T..335;KLM J
  +DDJ!Dr)   c                    t        t        |      }| j                  dn| j                  j                  |d      }d| t	        || j
                         | j                   dS )NrM   [])r   r,   ro   getr(   rd   ra   )rQ   rR   rS   levelstyles        r'   rT   z LogLevelColumnFormatter.__call__;  sh    S%    ( ""&&ub1 	 5'$udjj1243C3C2DAFFr)   rr   )ro   dict[str, str]ra   r,   rd   z
int | NonerW   NonerU   )r:   r;   r<   rX   r=   ry   rT   r>   r)   r'   rm   rm     sP    , ('J !	"$" " 	"
 
"$Gr)   rm   c                >    | j                  dt        |      z          y)a   
    "Pretty"-print *exc_info* to *sio* using our own plain formatter.

    To be passed into `ConsoleRenderer`'s ``exception_formatter`` argument.

    Used by default if neither Rich nor *better-exceptions* are present.

    .. versionadded:: 21.2.0
    
N)ri   r   rk   exc_infos     r'   r   r   I  s     IId&x001r)   c                      e Zd ZU dZdZded<   dZded<   dZd	ed
<   dZded<   dZ	ded<   dZ
d	ed<   dZd	ed<   dZded<   dZd	ed<   dZd	ed<   dZded<   dZded<   dZded<   ddZy)r   ag  
    A Rich traceback renderer with the given options.

    Pass an instance as `ConsoleRenderer`'s ``exception_formatter`` argument.

    See :class:`rich.traceback.Traceback` for details on the arguments.

    If a *width* of -1 is passed, the terminal width is used. If the width
    can't be determined, fall back to 80.

    .. versionadded:: 23.2.0
    	truecolorz:Literal['auto', 'standard', '256', 'truecolor', 'windows']color_systemTboolshow_localsd   rc   
max_framesNr^   themeF	word_wrap   extra_linesrd   indent_guides
   locals_max_lengthP   locals_max_stringlocals_hide_dunderlocals_hide_sunderr>   zSequence[str | ModuleType]suppressc                   | j                   dk(  rt        j                  d      \  | _         }|j                  d       t	        || j
                  | j                         j                  t        j                  || j                  | j                  | j                  | j                  | j                  | j                   | j                  | j                  | j                   | j"                  | j$                  | j&                  d       y )N)r   r   r   )filer   rd   )r   r   r   r   r   rd   r   r   r   r   r   r   )rd   shutilget_terminal_sizeri   r   r   printr   from_exceptionr   r   r   r   r   r   r   r   r   r   r   )rQ   rk   r   _s       r'   rT   zRichTracebackFormatter.__call__u  s    ::"44W=MDJ		$4#4#4DJJ	

%$$ ,,??jj.. ,,jj"00"&"8"8"&"8"8#'#:#:#'#:#:
r)   rk   r   r   r   rW   r   )r:   r;   r<   rX   r   r=   r   r   r   r   r   rd   r   r   r   r   r   r   rT   r>   r)   r'   r   r   V  s     	    KJE:ItKE3M4ss##$$+-H(-
r)   r   c                j    | j                  ddj                  t        j                  |       z          y)a	  
    Pretty-print *exc_info* to *sio* using the *better-exceptions* package.

    To be passed into `ConsoleRenderer`'s ``exception_formatter`` argument.

    Used by default if *better-exceptions* is installed and Rich is absent.

    .. versionadded:: 21.2.0
    r   rM   N)ri   joinbetter_exceptionsformat_exceptionr   s     r'   r   r     s*     IIdRWW.??JKKLr)   c                      e Zd ZdZeedddedddddf	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZ	 	 	 	 	 	 	 	 dd	Z	e
ddd
       Zy)r   a  
    Render ``event_dict`` nicely aligned, possibly in colors, and ordered.

    If ``event_dict`` contains a true-ish ``exc_info`` key, it will be rendered
    *after* the log line. If Rich_ or better-exceptions_ are present, in colors
    and with extra context.

    Args:
        columns:
            A list of `Column` objects defining both the order and format of
            the key-value pairs in the output. If passed, most other arguments
            become meaningless.

            **Must** contain a column with ``key=''`` that defines the default
            formatter.

            .. seealso:: `columns-config`

        pad_event:
            Pad the event to this many characters. Ignored if *columns* are
            passed.

        colors:
            Use colors for a nicer output. `True` by default. On Windows only
            if Colorama_ is installed. Ignored if *columns* are passed.

        force_colors:
            Force colors even for non-tty destinations. Use this option if your
            logs are stored in a file that is meant to be streamed to the
            console. Only meaningful on Windows. Ignored if *columns* are
            passed.

        repr_native_str:
            When `True`, `repr` is also applied to ``str``\ s. The ``event``
            key is *never* `repr` -ed. Ignored if *columns* are passed.

        level_styles:
            When present, use these styles for colors. This must be a dict from
            level names (strings) to terminal sequences (for example, Colorama)
            styles. The default can be obtained by calling
            `ConsoleRenderer.get_default_level_styles`. Ignored when *columns*
            are passed.

        exception_formatter:
            A callable to render ``exc_infos``. If Rich_ or better-exceptions_
            are installed, they are used for pretty-printing by default (rich_
            taking precedence). You can also manually set it to
            `plain_traceback`, `better_traceback`, an instance of
            `RichTracebackFormatter` like `rich_traceback`, or implement your
            own.

        sort_keys:
            Whether to sort keys when formatting. `True` by default. Ignored if
            *columns* are passed.

        event_key:
            The key to look for the main log message. Needed when you rename it
            e.g. using `structlog.processors.EventRenamer`. Ignored if
            *columns* are passed.

        timestamp_key:
            The key to look for timestamp of the log message. Needed when you
            rename it e.g. using `structlog.processors.EventRenamer`. Ignored
            if *columns* are passed.

        pad_level:
            Whether to pad log level with blanks to the longest amongst all
            level label.

    Requires the Colorama_ package if *colors* is `True` **on Windows**.

    Raises:
        ValueError: If there's not exactly one default column formatter.

    .. _Colorama: https://pypi.org/project/colorama/
    .. _better-exceptions: https://pypi.org/project/better-exceptions/
    .. _Rich: https://pypi.org/project/rich/

    .. versionadded:: 16.0.0
    .. versionadded:: 16.1.0 *colors*
    .. versionadded:: 17.1.0 *repr_native_str*
    .. versionadded:: 18.1.0 *force_colors*
    .. versionadded:: 18.1.0 *level_styles*
    .. versionchanged:: 19.2.0
       Colorama now initializes lazily to avoid unwanted initializations as
       ``ConsoleRenderer`` is used by default.
    .. versionchanged:: 19.2.0 Can be pickled now.
    .. versionchanged:: 20.1.0
       Colorama does not initialize lazily on Windows anymore because it breaks
       rendering.
    .. versionchanged:: 21.1.0
       It is additionally possible to set the logger name using the
       ``logger_name`` key in the ``event_dict``.
    .. versionadded:: 21.2.0 *exception_formatter*
    .. versionchanged:: 21.2.0
       `ConsoleRenderer` now handles the ``exc_info`` event dict key itself. Do
       **not** use the `structlog.processors.format_exc_info` processor
       together with `ConsoleRenderer` anymore! It will keep working, but you
       can't have customize exception formatting and a warning will be raised
       if you ask for it.
    .. versionchanged:: 21.2.0
       The colors keyword now defaults to True on non-Windows systems, and
       either True or False in Windows depending on whether Colorama is
       installed.
    .. versionadded:: 21.3.0 *sort_keys*
    .. versionadded:: 22.1.0 *event_key*
    .. versionadded:: 23.2.0 *timestamp_key*
    .. versionadded:: 23.3.0 *columns*
    .. versionadded:: 24.2.0 *pad_level*
    FNTeventr6   c                   || _         || _        |
 g d#fd}|t        k7  r |d       |t        k7  r |d       |dur |d       |dur |d       | |d       |dk7  r |d	       |	d
k7  r |d       D ]  }t	        j
                  |d        |
D cg c]  }|j                  dk(  s| }}|st        d      t        |      dkD  rt        d      |d   j                  | _
        |
D cg c]  }|j                  s| c}| _        y |rt        rt        9| j                  j                  }t!        t"        j%                  |dz   d            |r+t        j&                          t        j(                  d       nt        j(                          t*        }nt,        }|| _        || j1                  |      n|j3                         }|D ]  }||xx   |j4                  z  cc<    t        t7        |j9                         d             | _        || _        t?        |j@                  |jB                  |jD                  | jF                  d      | _
        t?        d |j4                  |jH                  z   |jD                  tJ        dd      }|sdnd }tM        |	t?        d |jN                  |jD                  tJ                    tM        dtQ        ||jD                  |            tM        |t?        d |j4                  |jD                  tJ        |             tM        d!|      tM        d"|      g| _        y c c}w c c}w )$Nc                0    j                  d|  d       y )NzThe `z-` argument is ignored when passing `columns`.)append)argto_warns    r'   add_meaningless_argz5ConsoleRenderer.__init__.<locals>.add_meaningless_arg6  s    C5 MNr)   	pad_eventcolorsFforce_colorsrepr_native_strro   r   	event_keyr6   timestamp_key   
stacklevelrM   z>Must pass a default column formatter (a column with `key=''`).r   z*Only one default column formatter allowed.r   z with `colors=True`colorama)whopackage)stripc                    t        |       S rr   rs   rt   s    r'   rv   z*ConsoleRenderer.__init__.<locals>.<lambda>  s
    SV r)   rw   )rb   rd   r{   r|   )r_   r`   ra   rb   re   rf   )r_   r`   ra   rb   r~   )ra   rd   )r_   r`   ra   rb   rd   loggerr7   )r   r,   rW   r   ))_exception_formatter
_sort_keys_EVENT_WIDTH_has_colorswarningswarnrR   
ValueErrorr"   r[   _default_column_formatter_columns_IS_WINDOWSr   	__class__r:   SystemError_MISSINGformatdeinitinitr@   rL   _stylesget_default_level_stylescopyr.   r#   rx   _longest_level_repr_native_strr]   r8   r9   r-   _reprr7   r,   rZ   r6   rm   )rQ   r   r   r   r   ro   exception_formatter	sort_keysr   r   columns	pad_levelr   wcoldefaults	classnamestyleslevel_to_colorrR   logger_name_formatterlevel_widthr   s                         @r'   ry   zConsoleRenderer.__init__"  s,    %8!#G
 L(#K0$#H-5(#N3e+#$56'#N3G##K0+#O4 /aA./ (/@#''R-@H@ T  8}q  !MNN-5a[-B-BD*,3?SswwS?DM # $ 7 7I%  ),A A$. (    OO%MM.MMO$F!F # ))&1
$&	 	 " 	1C36==0	1!##%+;<
 !0)@MMOOLLzz*
& !8(:(::!
  )ad '" & 0 0 &"	 '"K '" & &"#	 823="787
S A @s   L:0L:4L?L?c                    | j                   du rt        |      S t        |t              rt	        |      h dz  rt        |      S |S t        |      S )zj
        Determine representation of *val* depending on its type &
        self._repr_native_str.
        T>   	r   r!   "'rh   )r   repr
isinstancer,   set)rQ   vals     r'   r   zConsoleRenderer._repr  sL    
   D(9c33x@@Cy JCyr)   c           	        |j                  dd       }|j                  dd       }|j                  dd       }| j                  D cg c]F  }|j                  |j                  t              x}t        ur|j	                  |j                  |      H c}| j
                  rt        |      n|D 	cg c]  }	| j                  |	||	          c}	z   }
t               }|j                  dj                  d |
D              j                  d             |)|j                  d|z          |s||j                  d       t        |      }|r"| j                  ||       |j#                         S |=| j                  t        urt        j                   dd	
       |j                  d|z          |j#                         S c c}w c c}	w )Nstack	exceptionr   r!   c              3  &   K   | ]	  }|s|  y wrr   r>   ).0kvs     r'   	<genexpr>z+ConsoleRenderer.__call__.<locals>.<genexpr>  s     32B3s   r   zR

===============================================================================
zQRemove `format_exc_info` from your processor chain if you want pretty exceptions.r   r   )popr   rR   _NOTHINGr[   r   sortedr   r   ri   r   rstripr   r   r   r   r   rj   )rQ   r   name
event_dictr   excr   r   r   rR   kvsrk   s               r'   rT   zConsoleRenderer.__call__  s    w-nn[$/>>*d3 }}
!~~cggx88I MM#''3'
 /3ooz*:
 **3
3@
	
 j		388333;;C@AIIdUl#3?		23'1%%c84 ||~ _((?5  IIdSj!||~=

s   AF7-F<c           	         | rt         nt        }|j                  |j                  |j                  |j
                  |j
                  |j                  |j                  |j                  dS )a  
        Get the default styles for log levels

        This is intended to be used with `ConsoleRenderer`'s ``level_styles``
        parameter.  For example, if you are adding custom levels in your
        home-grown :func:`~structlog.stdlib.add_log_level` you could do::

            my_styles = ConsoleRenderer.get_default_level_styles()
            my_styles["EVERYTHING_IS_ON_FIRE"] = my_styles["critical"] renderer
            = ConsoleRenderer(level_styles=my_styles)

        Args:
            colors:
                Whether to use colorful styles. This must match the *colors*
                parameter to `ConsoleRenderer`. Default: `True`.
        )criticalr   errorr   warninginfodebugnotset)	r@   rL   r/   r0   r1   r2   r3   r4   r5   )r   r   s     r'   r   z(ConsoleRenderer.get_default_level_styles  s_    & %+--//''%%((%%''))	
 		
r)   )r   rc   r   r   r   r   r   r   ro   rn   r   r   r   r   r   r,   r   r,   r   zlist[Column] | Noner   r   )r   r   rW   r,   )r   r   r   r,   r   r   rW   r,   )T)r   r   rW   r   )r:   r;   r<   rX   r   r   default_exception_formatterry   r   rT   staticmethodr   r>   r)   r'   r   r     s    mb &"" %.21L ('+V
V
 V
 	V

 V
 ,V
 /V
 V
 V
 V
 %V
 V
p%#%+.%<E%	%N 
 
r)   r   c                V    |dk7  s|j                  dt              t        ur|S d|d<   |S )z
    Set ``event_dict["exc_info"] = True`` if *method_name* is ``"exception"``.

    Do nothing if the name is different or ``exc_info`` is already set.
    r   r   T)r}   	_SENTINEL)r   method_namer   s      r'   set_exc_infor    s5     	{">>*i0	A!Jzr)   )r$   r,   r%   rc   rW   r,   r   )r   r   r  r,   r   r   rW   r   )MrX   
__future__r   r   sysr   dataclassesr   ior   typesr   typingr   r   r	   r
   r   r   r   r   r   _framesr   
processorsr   r   r   r   r   r   ImportErrorr   richrich.consoler   rich.tracebackr   __all__platformr   r   r   r(   StylerA   rB   rG   ForerC   rH   rI   rJ   rD   rE   BackrF   r   _use_colorsr+   Stylesr@   rL   rO   rZ   r]   rm   rV   r   r   r   r   r   r   r   r  r  r>   r)   r'   <module>r     s   #  
  !  
 
 
 ' , H H$( llg%>' ((I^^""F
..

C
--

C==D==Dmm##G]]!!FMME}}  H
 IF
C
CDDGFEH o5!5 h " 
wW%	& $ $h *   ( 8 8 8v5G 5Gp 8
2 6
 6
 6
r ()	
M "0""2"1[
 [
|
 H	(+9BW  H
    Ds6   H5 I  I 5I ?I IIII