o
    ADi^                     @  s  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 zddlZW n eye   dZY nw zddl Z W n eyw   dZ Y nw zddl!Z!ddl"m#Z# ddl$m%Z% W n ey   dZ!Y nw g dZ&ej'dkZ(dZ)dZ*dEddZ+edurej,j-Z-ej,j.Z.ej,j/Z/ej0j1Z1ej0j2Z2ej0j3Z3ej0j4Z4ej0j5Z5ej0j6Z6ej7j1Z8ndZ-dZ.dZ/dZ1dZ2dZ3dZ4d Z5d!Z6d"Z8e( peduZ9e9Z:G d#d$ d$eZ;ee;ee; f Z<G d%d& d&Z=G d'd( d(Z>G d)d* d*eZ?eG d+d, d,Z@eG d-d. d.ZAG d/d0 d0ZBeC ZDdFd6d7ZEeG d8d9 d9ZFeF ZG	 dFd:d;ZHe!durSeGZIn
e dur[eHZIneEZIG d<d= d=ZJeC ZKdGdCdDZLdS )Hzz
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.     sstrlengthintreturnc                 C  s   |t |  }| dtd|  S )z&
    Pads *s* to length *length*.
     r   )lenmax)r   r!   missing r(   F/var/www/Datamplify/venv/lib/python3.10/site-packages/structlog/dev.py_padF   s   r*   z[0mz[1mz[2mz[31mz[34mz[36mz[35mz[33mz[32mz[41mc                   @  sv   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< dS )_Stylesr    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)   r+   p   s   
 r+   c                   @  s@   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dS )_ColorfulStylesN)r9   r:   r;   	RESET_ALLr,   BRIGHTr-   REDr.   r/   r0   YELLOWr1   GREENr2   r3   RED_BACKr4   DIMr5   BLUEr6   CYANr7   MAGENTAr8   r(   r(   r(   r)   r=          r=   c                   @  s@   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dS )_PlainStyles N)r9   r:   r;   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r(   r(   r(   r)   rI      rH   rI   c                   @  s   e Zd ZdZd
ddZd	S )ColumnFormatterz
    :class:`~typing.Protocol` for column formatters.

    See `KeyValueColumnFormatter` and `LogLevelColumnFormatter` for examples.

    .. versionadded:: 23.3.0
    keyr    valueobjectr#   c                 C  s   dS )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(   )selfrL   rM   r(   r(   r)   __call__   s    zColumnFormatter.__call__NrL   r    rM   rN   r#   r    )r9   r:   r;   __doc__rP   r(   r(   r(   r)   rK      s    rK   c                   @  s"   e Zd ZU dZded< ded< dS )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    rL   rK   	formatterN)r9   r:   r;   rR   r<   r(   r(   r(   r)   rS      s   
 rS   c                   @  s`   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dZdS )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   r"   widthrJ   prefixpostfixrL   rM   rN   r#   c                 C  s   t  }| jr|| j || j | jd ur-|| j || || j |d || j |t| || j || j | j	rT|| j	 || j |
 S )N=)r   r\   writerY   rW   rX   r*   rZ   r[   r]   getvalue)rO   rL   rM   sior(   r(   r)   rP      s    


z KeyValueColumnFormatter.__call__NrQ   )	r9   r:   r;   rR   r<   r[   r\   r]   rP   r(   r(   r(   r)   rU      s   
 rU   c                   @  sB   e Zd ZU dZded< ded< ded< 	ddddZdddZdS )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    rY   r"   r[   Ndict[str, str]
int | Noner#   Nonec                 C  sL   || _ |r|dkrdntt| j  dd d| _|| _d S d| _d| _d S )Nr   c                 S     t | S Nr%   er(   r(   r)   <lambda>4      z2LogLevelColumnFormatter.__init__.<locals>.<lambda>rL   rJ   )rd   r%   r&   keysr[   rY   )rO   rd   rY   r[   r(   r(   r)   __init__)  s   

z LogLevelColumnFormatter.__init__rL   rM   rN   c                 C  sD   t t|}| jd u rdn| j|d}d| t|| j | j dS )NrJ   [])r   r    rd   getr*   r[   rY   )rO   rL   rM   levelstyler(   r(   r)   rP   ;  s   

z LogLevelColumnFormatter.__call__ri   )rd   re   rY   r    r[   rf   r#   rg   rQ   )r9   r:   r;   rR   r<   rq   rP   r(   r(   r(   r)   rb     s   
 rb   ra   r   exc_infor   rg   c                 C  s   |  dt|  dS )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)r_   r   ra   rw   r(   r(   r)   r   I  s   
r   c                   @  s   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#d$ZdS )&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   r"   
max_framesNrV   themeF	word_wrap   extra_linesr[   indent_guides
   locals_max_lengthP   locals_max_stringlocals_hide_dunderlocals_hide_sunderr(   zSequence[str | ModuleType]suppressra   r   rw   r   r#   rg   c                 C  sz   | j dkrtd\| _ }|d t|| j| j dtj|| j	| j
| j| j| j| j | j| j| j| j| j| jd d S )N)r   r   rx   )filer{   r[   )r}   r   r   r   r   r[   r   r   r   r   r   r   )r[   shutilget_terminal_sizer_   r   r{   printr   from_exceptionr}   r   r   r   r   r   r   r   r   r   r   )rO   ra   rw   _r(   r(   r)   rP   u  s.   


zRichTracebackFormatter.__call__ra   r   rw   r   r#   rg   )r9   r:   r;   rR   r{   r<   r}   r   r   r   r   r[   r   r   r   r   r   r   rP   r(   r(   r(   r)   r   V  s"   
 
r   c                 C  s   |  ddtj|   dS )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
    rx   rJ   N)r_   joinbetter_exceptionsformat_exceptionry   r(   r(   r)   r     s   
r   c                   @  sV   e Zd ZdZeedddedddddfd)ddZd*ddZd+d$d%Z	e
d,d-d'd(ZdS ).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eventr5   	pad_eventr"   colorsr|   force_colorsrepr_native_strrd   rc   exception_formatterr   	sort_keys	event_keyr    timestamp_keycolumnslist[Column] | None	pad_levelc                   sX  || _ || _|
d ur~g  d+ fdd}|tkr|d |tkr#|d |d	ur+|d
 |d	ur3|d |d ur;|d |dkrC|d |	dkrK|d  D ]	}tj|dd qMdd |
D }|sdtdt|dkrntd|d j| _	dd |
D | _
d S |rtrtd u r| jj}ttj|d dd|rt  tjd	d nt  t}nt}|| _|d u r| |n| }|D ]}||  |j7  < qtt| dd d | _|| _t|j|j |j!| j"dd!| _	td |j|j# |j!t$d"d#d$}|sdnd }t%|	td |j&|j!t$d%t%d&t'||j!|d't%|td |j|j!t$|d(t%d)|t%d*|g| _
d S ),Nargr    r#   rg   c                   s     d|  d d S )NzThe `z-` argument is ignored when passing `columns`.)append)r   to_warnr(   r)   add_meaningless_arg6  s   
z5ConsoleRenderer.__init__.<locals>.add_meaningless_argr   r   Fr   r   rd   r   r   r5   r      
stacklevelc                 S  s   g | ]	}|j d kr|qS )rJ   ro   .0colr(   r(   r)   
<listcomp>S  s    z,ConsoleRenderer.__init__.<locals>.<listcomp>z>Must pass a default column formatter (a column with `key=''`).r   z*Only one default column formatter allowed.r   c                 S  s   g | ]}|j r|qS r(   ro   r   r(   r(   r)   r   \  s    z with `colors=True`colorama)whopackage)stripc                 S  rh   ri   rj   rk   r(   r(   r)   rm     rn   z*ConsoleRenderer.__init__.<locals>.<lambda>ro   )rZ   r[   rr   rs   )rW   rX   rY   rZ   r\   r]   )rW   rX   rY   rZ   ru   )rY   r[   )rW   rX   rY   rZ   r[   loggerr6   )r   r    r#   rg   )(_exception_formatter
_sort_keys_EVENT_WIDTH_has_colorswarningswarn
ValueErrorr%   rT   _default_column_formatter_columns_IS_WINDOWSr   	__class__r9   SystemError_MISSINGformatdeinitinitr=   rI   _stylesget_default_level_stylescopyr-   r&   rp   _longest_level_repr_native_strrU   r7   r8   r,   _reprr6   r    rS   r5   rb   )rO   r   r   r   r   rd   r   r   r   r   r   r   r   wdefaults	classnamestyleslevel_to_colorrL   logger_name_formatterlevel_widthr(   r   r)   rq   "  s   

		

zConsoleRenderer.__init__valr   r#   c                 C  s@   | j du r	t|S t|trt|h d@ rt|S |S t|S )zj
        Determine representation of *val* depending on its type &
        self._repr_native_str.
        T>   rx   	r$   "'r^   )r   repr
isinstancer    set)rO   r   r(   r(   r)   r     s   

zConsoleRenderer._reprr   r   name
event_dictr   c           	        s    dd }  dd }  dd } fddjD  fddjr)t n D  }t }|ddd	 |D d |d urW|d
|  |sR|d urW|d t|}|rg	|| | S |d ur~j	t
urwtjddd |d
|  | S )Nstack	exceptionrw   c                   s0   g | ]}  |jt tur||jqS r(   )poprL   _NOTHINGrT   r   )r   r   r(   r)   r     s
    z,ConsoleRenderer.__call__.<locals>.<listcomp>c                   s   g | ]
} | | qS r(   )r   )r   rL   )r   rO   r(   r)   r     s    r$   c                 s  s    | ]}|r|V  qd S ri   r(   )r   kvr(   r(   r)   	<genexpr>  s    z+ConsoleRenderer.__call__.<locals>.<genexpr>rx   zR

===============================================================================
zQRemove `format_exc_info` from your processor chain if you want pretty exceptions.r   r   )r   r   r   sortedr   r_   r   rstripr   r   r   r   r   r`   )	rO   r   r   r   r   excrw   kvsra   r(   )r   rO   r   r)   rP     s8   	 

zConsoleRenderer.__call__re   c              	   C  s2   | 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=   rI   r.   r/   r0   r1   r2   r3   r4   )r   r   r(   r(   r)   r     s   z(ConsoleRenderer.get_default_level_styles)r   r"   r   r|   r   r|   r   r|   rd   rc   r   r   r   r|   r   r    r   r    r   r   r   r|   )r   r   r#   r    )r   r   r   r    r   r   r#   r    )T)r   r|   r#   re   )r9   r:   r;   rR   r   r   default_exception_formatterrq   r   rP   staticmethodr   r(   r(   r(   r)   r     s&    q 

'r   r   r   method_namer   r   c                 C  s(   |dks| 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   rw   T)rt   	_SENTINEL)r   r   r   r(   r(   r)   set_exc_info  s
   	r   )r   r    r!   r"   r#   r    r   )r   r   r   r    r   r   r#   r   )MrR   
__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>   r?   rD   Forer@   rE   rF   rG   rA   rB   BackrC   r   _use_colorsr+   Stylesr=   rI   rK   rS   rU   rb   rN   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   <module>   s   ,

	
;8
9


  `