o
    ADi                     @  s   d Z ddlmZ ddl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 ejdkr6dd	lmZ ndd	lmZ G d
d dZdddZdS )z"
Logger wrapper and helper class.
    )annotationsN)AnyIterableMappingSequence)	DropEvent   )BindableLoggerContext	ProcessorWrappedLogger)      )Selfc                   @  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d0ddZ	d1ddZ
d1ddZd0d d!Zd2d(d)Z	*d3d4d+d,Zd*S )5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   H/var/www/Datamplify/venv/lib/python3.10/site-packages/structlog/_base.py__init__3   s   
zBoundLoggerBase.__init__returnstrc                 C  s    d| j j d| jd| jdS )N<z	(context=z, processors=z)>)	__class____name__r   r   )r   r   r   r   __repr__=   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__F   s   zBoundLoggerBase.__ne__
new_valuesr   r   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   bindI   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   unbindS   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 reused.
        Nr   )r   clearr,   r+   r   r   r   newl   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.

        Args:
            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`.
        Nr7   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   r6   r7   r9   
event_dictprocmsgr   r   r   _process_eventz   s   
-



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.

        Args:
            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)rG   getattrr   r   )r   r6   r7   r9   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   )r6   r   r7   r8   r9   r:   r   r;   r   )r6   r   r7   r8   r9   r   r   r   )r!   
__module____qualname____doc____annotations__r   r"   r(   r)   r,   r1   r3   r5   rG   rK   r   r   r   r   r      s   
 











Gr   bound_loggerr	   r   r
   c                 C  s   | j S )aD  
    Return *bound_logger*'s context.

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

    Args:
        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   )rP   r   r   r   get_context   s   rQ   )rP   r	   r   r
   )rN   
__future__r   systypingr   r   r   r   structlog.exceptionsr   r	   r
   r   r   version_infor   typing_extensionsr   rQ   r   r   r   r   <module>   s   
 J