
    "h                        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\  rdd	lmZ ndd	lmZ  G d
 d      ZddZy)z"
Logger wrapper and helper class.
    )annotationsN)AnyIterableMappingSequence)	DropEvent   )BindableLoggerContext	ProcessorWrappedLogger)      )Selfc                      e Zd ZU dZded<   	 	 	 	 	 	 	 ddZddZddZddZddZ	dd	Z
dd
ZddZ	 	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZy)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   _loggerc                .    || _         || _        || _        y N)r   _processors_context)selflogger
processorscontexts       L/var/www/html/sandstorm/venv/lib/python3.12/site-packages/structlog/_base.py__init__zBoundLoggerBase.__init__3   s     %    c                j    d| j                   j                   d| j                  d| j                  dS )N<z	(context=z, processors=z)>)	__class____name__r   r   )r   s    r   __repr__zBoundLoggerBase.__repr__=   s6    4>>**+9T]]4E]SWScScRffhiir   c                T    	 | j                   |j                   k(  S # t        $ r Y yw xY w)NF)r   AttributeErrorr   others     r   __eq__zBoundLoggerBase.__eq__@   s,    	==ENN22 		s    	''c                &    | j                  |       S r   )r(   r&   s     r   __ne__zBoundLoggerBase.__ne__F   s    ;;u%%%r   c           	         | j                  | 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   
new_valuess     r   bindzBoundLoggerBase.bindI   sB     ~~LL#DMM##DMM@Z@
 	
r   c                N    | j                         }|D ]  }|j                  |=  |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   keysblkeys       r   unbindzBoundLoggerBase.unbindS   s1     YY[ 	!CC 	! 	r   c                l    | j                         }|D ]  }|j                  j                  |d         |S )zs
        Like :meth:`unbind`, but best effort: missing keys are ignored.

        .. versionadded:: 18.2.0
        N)r.   r   popr0   s       r   
try_unbindzBoundLoggerBase.try_unbind`   s7     YY[ 	'CKKOOC&	' 	r   c                Z    | j                   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.
         )r   clearr.   r,   s     r   newzBoundLoggerBase.newl   s(     	tyy&:&&r   c                X   | j                   j                         } |j                  di | |||d<   | j                  D ]  } || j                  ||      } t        |t        t        t        f      r|fi fS t        |t              r|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`.
        eventr9   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   
isinstancestrbytes	bytearraytupledict
ValueError)r   method_namer=   event_kw
event_dictprocmsgs          r   _process_eventzBoundLoggerBase._process_eventz   s    Z --,,.

%H%"'Jw$$ 	EDdllKDJ	E j3y"9:="$$j%( j$'z>!Z 	 or   Nc                    	 | j                  |||      \  }} t        | j                  |      |i |S # t        $ r Y yw xY 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)rL   getattrr   r   )r   rG   r=   rH   argskws         r   _proxy_to_loggerz BoundLoggerBase._proxy_to_logger   sN    :	**;xHHD"574<<5tBrBB 		s   14 	A A )r   r   r   zIterable[Processor]r   r   )returnrA   )r'   objectrR   bool)r-   r   rR   r   )r1   rA   rR   r   )rG   rA   r=   
str | NonerH   zdict[str, Any]rR   z'tuple[Sequence[Any], Mapping[str, Any]]r   )rG   rA   r=   rU   rH   r   rR   r   )r"   
__module____qualname____doc____annotations__r   r#   r(   r*   r.   r4   r7   r;   rL   rQ   r9   r   r   r   r      s    
    (  	 j&


'DD'1D=KD	0DN 59!!'1!FI!	!r   r   c                    | 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   )bound_loggers    r   get_contextr\      s         r   )r[   r
   rR   r   )rX   
__future__r   systypingr   r   r   r   structlog.exceptionsr   r
   r   r   r   version_infor   typing_extensionsr   r\   r9   r   r   <module>rc      sI    # 
 3 3 * E E w&F FR!r   