o
    ¥ÜÓh¶  ã                   @  sh   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 ddlm
Z
mZmZmZ G dd„ dƒZddd„ZdS )z"
Logger wrapper and helper class.
é    )Úannotations)ÚAnyÚIterableÚMappingÚSequence)Ú	DropEventé   )ÚBindableLoggerÚContextÚ	ProcessorÚWrappedLoggerc                   @  s„   e Zd ZU dZded< 	 d,d	d
„Zd-dd„Zd.dd„Zd.dd„Zd/dd„Z	d0dd„Z
d0dd„Zd/dd „Zd1d'd(„Z	)d2d3d*d+„Zd)S )4ÚBoundLoggerBasea  
    Immutable context carrier.

    Doesn't do any actual logging; examples for useful subclasses are:

    - the generic `BoundLogger` that can wrap anything,
    - `structlog.stdlib.BoundLogger`.
    - `structlog.twisted.BoundLogger`,

    See also `custom-wrappers`.
    r   Ú_loggerÚloggerÚ
processorsúIterable[Processor]Úcontextr
   c                 C  s   || _ || _|| _d S ©N)r   Ú_processorsÚ_context)Úselfr   r   r   © r   úE/var/www/html/ai/venv/lib/python3.10/site-packages/structlog/_base.pyÚ__init__+   s   
zBoundLoggerBase.__init__ÚreturnÚstrc                 C  s   d  | jj| j| j¡S )Nz#<{}(context={!r}, processors={!r})>)ÚformatÚ	__class__Ú__name__r   r   )r   r   r   r   Ú__repr__5   s   ÿzBoundLoggerBase.__repr__ÚotherÚobjectÚboolc                 C  s$   z| j |j kW S  ty   Y dS w )NF)r   ÚAttributeError©r   r    r   r   r   Ú__eq__:   s
   ÿzBoundLoggerBase.__eq__c                 C  s   |   |¡ S r   )r%   r$   r   r   r   Ú__ne__@   s   zBoundLoggerBase.__ne__Ú
new_valuesr   c                 K  s$   |   | j| j| jj | jfi |¤Ž¡S )zS
        Return a new logger with *new_values* added to the existing ones.
        )r   r   r   r   ©r   r'   r   r   r   ÚbindC   s
   ýzBoundLoggerBase.bindÚkeysc                 G  s   |   ¡ }|D ]}|j|= q|S )zš
        Return a new logger with *keys* removed from the context.

        Raises:

            KeyError: If the key is not part of the context.
        )r)   r   ©r   r*   ÚblÚkeyr   r   r   ÚunbindM   s   
zBoundLoggerBase.unbindc                 G  s$   |   ¡ }|D ]	}|j |d¡ q|S )zs
        Like :meth:`unbind`, but best effort: missing keys are ignored.

        .. versionadded:: 18.2.0
        N)r)   r   Úpopr+   r   r   r   Ú
try_unbind[   s   zBoundLoggerBase.try_unbindc                 K  s   | j  ¡  | jdi |¤ŽS )zï
        Clear context and binds *new_values* using `bind`.

        Only necessary with dict implementations that keep global state like
        those wrapped by `structlog.threadlocal.wrap_dict` when threads
        are re-used.
        Nr   )r   Úclearr)   r(   r   r   r   Únewg   s   
zBoundLoggerBase.newÚmethod_nameÚeventú
str | NoneÚevent_kwúdict[str, Any]ú'tuple[Sequence[Any], Mapping[str, Any]]c                 C  sŠ   | j  ¡ }|jdi |¤Ž |dur||d< | jD ]	}|| j||ƒ}qt|tttfƒr/|fi fS t|t	ƒr6|S t|t
ƒr?d|fS d}t|ƒ‚)a'  
        Combines creates an ``event_dict`` and runs the chain.

        Call it to combine your *event* and *context* into an event_dict and
        process using the processor chain.

        Arguments:

            method_name:
                The name of the logger method.  Is passed into the processors.

            event:
                The event -- usually the first positional argument to a logger.

            event_kw:
                Additional event keywords.  For example if someone calls
                ``log.info("foo", bar=42)``, *event* would to be ``"foo"`` and
                *event_kw* ``{"bar": 42}``.

        Raises:

            structlog.DropEvent: if log entry should be dropped.

            ValueError:
                if the final processor doesn't return a str, bytes, bytearray,
                tuple, or a dict.

        Returns:
             `tuple` of ``(*args, **kw)``

        .. note::

            Despite underscore available to custom wrapper classes.

            See also `custom-wrappers`.

        .. versionchanged:: 14.0.0
            Allow final processor to return a `dict`.
        .. versionchanged:: 20.2.0
            Allow final processor to return `bytes`.
        .. versionchanged:: 21.2.0
            Allow final processor to return a `bytearray`.
        Nr4   r   zLast processor didn't return an appropriate value.  Valid return values are a dict, a tuple of (args, kwargs), bytes, or a str.)r   ÚcopyÚupdater   r   Ú
isinstancer   ÚbytesÚ	bytearrayÚtupleÚdictÚ
ValueError)r   r3   r4   r6   Ú
event_dictÚprocÚmsgr   r   r   Ú_process_eventu   s   
0



ÿzBoundLoggerBase._process_eventNc                 K  s@   z|   |||¡\}}t| j|ƒ|i |¤ŽW S  ty   Y dS w )aÞ  
        Run processor chain on event & call *method_name* on wrapped logger.

        DRY convenience method that runs :func:`_process_event`, takes care of
        handling :exc:`structlog.DropEvent`, and finally calls *method_name* on
        :attr:`_logger` with the result.

        Arguments:

            method_name:
                The name of the method that's going to get called.  Technically
                it should be identical to the method the user called because it
                also get passed into processors.

            event:
                The event -- usually the first positional argument to a logger.

            event_kw:
                Additional event keywords.  For example if someone calls
                ``log.info("foo", bar=42)``, *event* would to be ``"foo"`` and
                *event_kw* ``{"bar": 42}``.

        .. note::

            Despite underscore available to custom wrapper classes.

            See also `custom-wrappers`.
        N)rD   Úgetattrr   r   )r   r3   r4   r6   ÚargsÚkwr   r   r   Ú_proxy_to_logger¾   s   ÿz BoundLoggerBase._proxy_to_logger)r   r   r   r   r   r
   )r   r   )r    r!   r   r"   )r'   r   r   r   )r*   r   r   r   )r3   r   r4   r5   r6   r7   r   r8   r   )r3   r   r4   r5   r6   r   r   r   )r   Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r%   r&   r)   r.   r0   r2   rD   rH   r   r   r   r   r      s   
 











Jÿr   Úbound_loggerr	   r   r
   c                 C  s   | j S )aK  
    Return *bound_logger*'s context.

    The type of *bound_logger* and the type returned depend on your
    configuration.

    Arguments:

        bound_logger: The bound logger whose context you want.

    Returns:

        The *actual* context from *bound_logger*. It is *not* copied first.

    .. versionadded:: 20.2.0
    )r   )rM   r   r   r   Úget_contextä   s   rN   N)rM   r	   r   r
   )rK   Ú
__future__r   Útypingr   r   r   r   Ústructlog.exceptionsr   r	   r
   r   r   r   rN   r   r   r   r   Ú<module>   s    R