
    U.j]                       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plain_tracebackrich_tracebackbetter_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      OC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\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)r9   r:   r;   	RESET_ALLr,   BRIGHTr-   REDr.   r/   r0   YELLOWr1   GREENr2   r3   RED_BACKr4   DIMr5   BLUEr6   CYANr7   MAGENTAr8   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)r9   r:   r;   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r=   r(   r&   rK   rK      sC    EFNOKJJKLIKFHr(   rK   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rQ   r+   rR   objectreturnr+   )r9   r:   r;   __doc__rS   r=   r(   r&   rN   rN      s    	r(   rN   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+   rQ   rN   	formatterN)r9   r:   r;   rW   r<   r=   r(   r&   rY   rY      s     
Hr(   rY   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widthrL   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   rd   writer`   r^   r_   r'   ra   rc   re   getvalue)rP   rQ   rR   sios       r&   rS   z KeyValueColumnFormatter.__call__   s    j;;IIdkk"IId&&'>>%IIdnn%IIcNIId&&'IIcN		$""#		$tu-tzz:;		$""#<<IIdll#IId&&'||~r(   NrT   )	r9   r:   r;   rW   r<   rc   rd   re   rS   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*
    zdict[str, str] | Nonelevel_stylesr+   r`   rb   rc   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Vr(   rQ   rL   )rm   r!   r"   keysrc   r`   )rP   rm   r`   rc   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 )NrL   [])r   r+   rm   getr'   rc   r`   )rP   rQ   rR   levelstyles        r&   rS   z LogLevelColumnFormatter.__call__;  sh    S%    ( ""&&ub1 	 5'$udjj1243C3C2DAFFr(   rp   )rm   zdict[str, str]r`   r+   rc   z
int | NonerV   NonerT   )r9   r:   r;   rW   r<   rw   rS   r=   r(   r&   rl   rl     sP    , ('J !	"$" " 	"
 
"$Gr(   rl   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)rh   r   rj   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)RichTracebackFormatterag  
    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   rb   
max_framesNr]   themeF	word_wrap   extra_linesrc   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   rc   )r   r   r   r   r   rc   r   r   r   r   r   r   )rc   shutilget_terminal_sizerh   r   r   printr   from_exceptionr   r   r   r   r   r   r   r   r   r   r   )rP   rj   r   _s       r&   rS   zRichTracebackFormatter.__call__u  s    ::"44W=MDJ		$4#4#4DJJ	

%$$ ,,??jj.. ,,jj"00"&"8"8"&"8"8#'#:#:#'#:#:
r(   rj   r   r   r   rV   r~   )r9   r:   r;   rW   r   r<   r   r   r   r   r   rc   r   r   r   r   r   r   rS   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   rL   N)rh   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 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eventr5   c                l   || _         || _        |
 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|}|D ]  }||xx   |j2                  z  cc<    t        t5        |j7                         d             | _        || _        t=        |j>                  |j@                  |jB                  | jD                  d      | _
        t=        d |j2                  |jF                  z   |jB                  tH        dd      }|sdnd }tK        |	t=        d |jL                  |jB                  tH                    tK        dtO        ||jB                  |            tK        |t=        d |j2                  |jB                  tH        |             tK        d!|      tK        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_arg5  s    C5 MNr(   	pad_eventcolorsFforce_colorsrepr_native_strrm   r   	event_keyr5   timestamp_key   
stacklevelrL   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 rp   rq   rr   s    r&   rt   z*ConsoleRenderer.__init__.<locals>.<lambda>  s    SVr(   ru   )ra   rc   ry   rz   )r^   r_   r`   ra   rd   re   )r^   r_   r`   ra   r|   )r`   rc   )r^   r_   r`   ra   rc   loggerr6   )r   r+   rV   r~   )(_exception_formatter
_sort_keys_EVENT_WIDTH_has_colorswarningswarnrQ   
ValueErrorr!   rZ   _default_column_formatter_columns_IS_WINDOWSr   	__class__r9   SystemError_MISSINGformatdeinitinitr?   rK   _stylesget_default_level_stylesr-   r"   rv   _longest_level_repr_native_strr\   r7   r8   r,   _reprr6   r+   rY   r5   rl   )rP   r   r   r   r   rm   exception_formatter	sort_keysr   r   columns	pad_levelr   wcoldefaults	classnamestyleslevel_to_colorrQ   logger_name_formatterlevel_widthr   s                         @r&   rw   zConsoleRenderer.__init__!  s     %8!#G
 L(#K0$#H-5(#N3e+#$56'#N3G##K0+#O4aA.  (/@w#''R-wH@ T  8}q  !MNN-5a[-B-BD*,3?GSswwSG?DM # $ 7 7I%  ),A A$. (    OO%MM.MMO$F!F # ))&1 	 "C36==0 "!##%+;<
 !0)@MMOOLLzz*
& !8(:(::!
  )ad '" & 0 0 &"	 '"K '" & &"#	 823="787
S A @s   L,0L,4L1L1c                n    | j                   du rt        |      S t        |t              r|S t        |      S )zj
        Determine representation of *val* depending on its type &
        self._repr_native_str.
        T)r   repr
isinstancer+   )rP   vals     r&   r   zConsoleRenderer._repr  s5    
   D(9c3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       |r2t        |      }|dk7  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rp   r=   ).0kvs     r&   	<genexpr>z+ConsoleRenderer.__call__.<locals>.<genexpr>  s     32Bs   r   zR

===============================================================================
)NNNzQRemove `format_exc_info` from your processor chain if you want pretty exceptions.r   r   )popr   rQ   _NOTHINGrZ   r   sortedr   r   rh   r   rstripr   r   r   r   r   ri   )rP   r   name
event_dictr   excr   r   r   rQ   kvsrj   s               r&   rS   zConsoleRenderer.__call__  s    w-nn[$/>>*d3 }}
$!~~cggx88I MM#''3'$
 /3ooz*:M
M **3
3@M
	
 j		388333;;C@AIIdUl#3?		23+H5H--))#x8 ||~ _((?5  IIdSj!||~A

s   AF<-G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?   rK   r.   r/   r0   r1   r2   r3   r4   )r   r   s     r&   r   z(ConsoleRenderer.get_default_level_styles  s_    & %+--//''%%((%%''))	
 		
r(   )r   rb   r   r   r   r   r   r   rm   zStyles | Noner   r   r   r   r   r+   r   r+   r   zlist[Column] | Noner   r   )r   r   rV   r+   )r   r   r   r+   r   r   rV   r+   )T)r   r   rV   r   )r9   r:   r;   rW   r   r   default_exception_formatterrw   r   rS   staticmethodr   r=   r(   r&   r   r     s    l` &"" %&*1L ('+V
V
 V
 	V

 V
 $V
 /V
 V
 V
 V
 %V
 V
p'#'+.'<E'	'R 
 
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$   rb   rV   r+   r   )r   r   r   r+   r   r   rV   r   )MrW   
__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'   Styler@   rA   rF   ForerB   rG   rH   rI   rC   rD   BackrE   r   _use_colorsr*   Stylesr?   rK   rN   rY   r\   rl   rU   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Z
 Z
z
 H	(+9BU  H
    Ds6   H5 I  I 5I ?I IIII