
    	hC                       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 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n# e$ r dZY nw xY w	 ddlZn# e$ r dZY nw xY w	 ddl Z ddl!m"Z" ddl#m$Z$ n# e$ r dZ Y nw xY wg dZ%ej&        dk    Z'dZ(dZ)d9dZ*eyej+        j,        Z,ej+        j-        Z-ej+        j.        Z.ej/        j0        Z0ej/        j1        Z1ej/        j2        Z2ej/        j3        Z3ej/        j4        Z4ej/        j5        Z5ej6        j0        Z7ndZ,dZ-dZ.dZ0dZ1dZ2dZ3dZ4d Z5d!Z7e' peduZ8e8Z9 G d" d#e          Z:ee:ee:         f         Z; G d$ d%          Z< G d& d'          Z=d:d-Z>e G d. d/                      Z? e?            Z@	 d:d0ZAe e@ZBneeAZBne>ZB G d1 d2          ZC eD            ZEd;d8ZFdS )<zw
Helpers that make development with *structlog* more pleasant.

See also the narrative documentation in `development`.
    )annotationsN)	dataclass)StringIO)
ModuleType)AnyIterableLiteralProtocolSequenceTextIOTypeUnion   )_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.     sstrlengthintreturnc                F    |t          |           z
  }| d|dk    r|ndz  z   S )z&
    Pads *s* to length *length*.
     r   len)r   r    missings      Z/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/structlog/dev.py_padr)   E   s/     s1vvoGs1gg!444    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<   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,   o   s         JJJKKKOOOOOONNNKKKMMMMMr*   r,   c                  B    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)r:   r;   r<   	RESET_ALLr-   BRIGHTr.   REDr/   r0   r1   YELLOWr2   GREENr3   r4   RED_BACKr5   DIMr6   BLUEr7   CYANr8   MAGENTAr9   r>   r*   r(   r@   r@      sO        EFNOKJJKLIKFHHHr*   r@   c                  B    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)r:   r;   r<   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r>   r*   r(   rL   rL      sO        EFNOKJJKLIKFHHHr*   rL   sior   exc_infor   Nonec                P    |                      dt          |          z              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)writer   rN   rO   s     r(   r   r      s*     IId&x0001111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dS )%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   r!   
max_framesNz
str | NonethemeF	word_wrap   extra_lineswidthindent_guides
   locals_max_lengthP   locals_max_stringlocals_hide_dunderlocals_hide_sunderr>   zSequence[str | ModuleType]suppressrN   r   rO   r   r"   rP   c                |   | j         dk    rt          j        d          \  | _         }|                    d           t	          || j                                      t          j        || j	        | j
        | j        | j        | j        | j         | j        | j        | j        | j        | j        | j        d           d S )N)re   r   rR   )filerX   )rZ   r\   r]   r^   r`   ra   rb   rd   rf   rg   rh   ri   )ra   shutilget_terminal_sizerS   r   rX   printr   from_exceptionrZ   r\   r]   r^   r`   rb   rd   rf   rg   rh   ri   )selfrN   rO   _s       r(   __call__zRichTracebackFormatter.__call__   s    :"4W==MDJ		$St'8999??$ ,?j. ,j"0"&"8"&"8#'#:#'#:  	
 	
 	
 	
 	
r*   rN   r   rO   r   r"   rP   )r:   r;   r<   __doc__rX   r=   rZ   r\   r]   r^   r`   ra   rb   rd   rf   rg   rh   ri   rs   r>   r*   r(   rV   rV      s$          	      KJEIKEM#####$$$$$+-H----
 
 
 
 
 
r*   rV   c                t    |                      dd                    t          j        |           z              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
    rR   rM   N)rS   joinbetter_exceptionsformat_exceptionrT   s     r(   r   r      s6     IIdRWW.?JKKKLLLLLr*   c            	      X    e Zd ZdZeedddedddf	d!dZd"dZd#dZ	e
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.

    Arguments:

        pad_event: Pad the event to this many characters.

        colors:
            Use colors for a nicer output. `True` by default. On Windows only
            if Colorama_ is installed.

        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.

        repr_native_str:
            When `True`, `repr` is also applied to native strings (i.e. unicode
            on Python 3 and bytes on Python 2). Setting this to `False` is
            useful if you want to have human-readable non-ASCII output on
            Python 2.  The ``event`` key is *never* `repr` -ed.

        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`

        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.

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

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

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

    .. _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*
    FNTeventr6   	pad_eventr!   colorsrY   force_colorsrepr_native_strlevel_stylesStyles | Noneexception_formatterr   	sort_keys	event_keyr   timestamp_keyc
                   |rt           r}t          8| j        j        }
t	          t
                              |
dz   d                    |r)t          j                     t          j        d           nt          j                     t          }nt          }|| _        || _        ||                     |          | _        n|| _        | j        D ]}| j        |xx         |j        z  cc<   t!          t#          | j                                        d                     | _        || _        || _        || _        || _        |	| _        d S )Nz with `colors=True`colorama)whopackageF)stripc                     t          |           S )Nr%   )es    r(   <lambda>z*ConsoleRenderer.__init__.<locals>.<lambda>  s    3q66 r*   )key)_IS_WINDOWSr   	__class__r:   SystemError_MISSINGformatdeinitinitr@   rL   _styles
_pad_eventget_default_level_styles_level_to_colorr.   r&   maxkeys_longest_level_repr_native_str_exception_formatter
_sort_keys
_event_key_timestamp_key)rq   r|   r}   r~   r   r   r   r   r   r   	classnamestylesr   s                r(   __init__zConsoleRenderer.__init__e  sk     	" $# $ 7I%  ),A A$. (       $O%%%M.....MOOO$FF!F##'#@#@#H#HD  #/D ' 	7 	7C %%%6%%%%!$))++1A1ABBB
 
 !0$7!##+r*   valr   r"   c                ~    | 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   )rq   r   s     r(   _reprzConsoleRenderer._repr  sA    
  D((99c3 	JCyyr*   loggerr   name
event_dictr   c                t    t                      }                     j        d           }|?|                     j        j        t          |          z    j        j        z   dz                                  dd           }|W|                    d j        	                    |d          z   t          | j                  z    j        j        z   dz                                   j        d           }t          |t                    st          |          }r&t          | j                   j        j        z   dz   }n| j        j        z  }|                     j        j        |z                                  dd           }|                    dd           }|B|                    d j        j        z    j        j        z   |z    j        j        z   dz                                  dd           }	                    d	d           }
                    d
d           }                                } j        rt'          |          }|                    d                     fd|D                                  |	1|                    d|	z              |s|
|                    d           |r,t+          |          }|dk    r                     ||           n>|
< j        t.          urt1          j        dd           |                    d|
z              |                                S )Nr$   level[rM   z] r   r7   stack	exceptionrO   c              3     K   | ]Y}j         j        |z   j         j        z   d z   j         j        z                       |                   z   j         j        z   V  ZdS )=N)r   r8   r-   r9   r   ).0r   r   rq   s     r(   	<genexpr>z+ConsoleRenderer.__call__.<locals>.<genexpr>  s       	 	  #,$%  ,'	(
 **Z_--. ,$%	 	 	 	 	 	r*   rR   zR

===============================================================================
)NNNzQRemove `format_exc_info` from your processor chain if you want pretty exceptions.   )
stacklevel)r   popr   rS   r   r6   r   r-   r   getr)   r   r   r   r   r.   r7   r   r   sortedrw   r   r   r   warningswarngetvalue)rq   r   r   r   rN   tsr   r{   r7   r   excrO   event_dict_keyss   `  `         r(   rs   zConsoleRenderer.__call__  s    jj^^D/66>II&b'',$%    w--II&**5"556ud1223 ,$% 	   t55%%% 	JJE 	(004<3EEKEET\''E		$,%-... nnXt44$..==K"II,*+,%&  ,$	%
    w--nn[$//>>*d33)3):):? 	6$_55O		HH 	 	 	 	 	 +	 	 	 	 		
 	
 	
 IIdUl### 43?		2333 	"+H55H---))#x888_(??5    
 IIdSj!!!||~~r*   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)

        Arguments:

            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  sQ    ( %+<-/'%(%')	
 	
 		
r*   )r|   r!   r}   rY   r~   rY   r   rY   r   r   r   r   r   rY   r   r   r   r   )r   r   r"   r   )r   r   r   r   r   r   r"   r   )T)r}   rY   r"   r   )r:   r;   r<   ru   _EVENT_WIDTH_has_colorsdefault_exception_formatterr   r   rs   staticmethodr   r>   r*   r(   r   r     s        T Tp &"" %&*1L (6, 6, 6, 6, 6,p   Y Y Y Yv 
 
 
 
 \
 
 
r*   r   r   r   method_namer   r   c                d    |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   rO   T)r   	_SENTINEL)r   r   r   s      r(   set_exc_infor   )  s>     	{"">>*i00	AA!Jzr*   )r   r   r    r!   r"   r   rt   )r   r   r   r   r   r   r"   r   )Gru   
__future__r   rm   sysr   dataclassesr   ior   typesr   typingr   r   r	   r
   r   r   r   r   _framesr   
processorsr   r   r   r   r   r   ImportErrorrx   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   r   rV   r   r   r   r   objectr   r   r>   r*   r(   <module>r      sj    # " " " " "  



  ! ! ! ! ! !            	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ' & & & & & , , , , , , H H H H H H H H H H H HOOOO   HHH   KKK$$$$$$(((((((   DDD   lg%>5 5 5 5 (I^"F
.
C
-
C=D=Dm#G]!FME} HH
 IF
C
CDDGFEH o5!5     h   " 
wW%	&       $       $
2 
2 
2 
2 4
 4
 4
 4
 4
 4
 4
 4
n ('))	
M 
M 
M 
M "0""2"1U
 U
 U
 U
 U
 U
 U
 U
p FHH	     s6   A A#"A#'A, ,A65A6:B BB