o
    hr                     @  s   d 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
mZmZ ddlmZ ddlmZmZ g d	ZG d
d dZedddZG dd dZG dd dZG dd deZG dd dZG dd dZdS )ze
Helpers to test your application's logging behavior.

.. versionadded:: 20.1.0

See :doc:`testing`.
    )annotations)contextmanager)Any	Generator
NamedTupleNoReturn   )	configure
get_config)	DropEvent)	EventDictWrappedLogger)CapturedCallCapturingLoggerCapturingLoggerFactory
LogCaptureReturnLoggerReturnLoggerFactorycapture_logsc                   @  s.   e Zd ZU dZded< dddZdddZdS )r   a;  
    Class for capturing log messages in its entries list.
    Generally you should use `structlog.testing.capture_logs`,
    but you can use this class if you want to capture logs with other patterns.

    :ivar List[structlog.typing.EventDict] entries: The captured log entries.

    .. versionadded:: 20.1.0
    zlist[EventDict]entriesreturnNonec                 C  
   g | _ d S N)r   self r   G/var/www/html/ai/venv/lib/python3.10/site-packages/structlog/testing.py__init__0      
zLogCapture.__init___r   method_namestr
event_dictr   r   c                 C  s   ||d< | j | t)N	log_level)r   appendr   )r   r    r!   r#   r   r   r   __call__3   s   zLogCapture.__call__Nr   r   )r    r   r!   r"   r#   r   r   r   __name__
__module____qualname____doc____annotations__r   r&   r   r   r   r   r   #   s
   
 

r   r   &Generator[list[EventDict], None, None]c               	   c  s    t  } t d }| }z#|  ||  t|d | jV  W |  || t|d dS |  || t|d w )a  
    Context manager that appends all logging statements to its yielded list
    while it is active. Disables all configured processors for the duration
    of the context manager.

    Attention: this is **not** thread-safe!

    .. versionadded:: 20.1.0
    
processors)r/   N)r   r
   copyclearr%   r	   r   extend)capr/   old_processorsr   r   r   r   <   s   





r   c                   @  sF   e Zd ZdZd	ddZe Z Z Z ZZ	e Z
 Z Z Z ZZdS )
r   aU  
    Return the arguments that it's called with.

    >>> from structlog import ReturnLogger
    >>> ReturnLogger().info("hello")
    'hello'
    >>> ReturnLogger().info("hello", when="again")
    (('hello',), {'when': 'again'})

    .. versionchanged:: 0.3.0
        Allow for arbitrary arguments and keyword arguments to be passed in.
    argsr   kwr   c                 O  s    t |dkr|s|d S ||fS )zY
        Return tuple of ``args, kw`` or just ``args[0]`` if only one arg passed
        r   r   )len)r   r5   r6   r   r   r   msgh   s   zReturnLogger.msgN)r5   r   r6   r   r   r   )r)   r*   r+   r,   r8   logdebuginfowarnwarningfatalfailureerrerrorcritical	exceptionr   r   r   r   r   Z   s
    

r   c                   @  s$   e Zd ZdZdddZdd	d
ZdS )r   z
    Produce and cache `ReturnLogger`\ s.

    To be used with `structlog.configure`\ 's *logger_factory*.

    Positional arguments are silently ignored.

    .. versionadded:: 0.4.0
    r   r   c                 C     t  | _d S r   )r   _loggerr   r   r   r   r         zReturnLoggerFactory.__init__r5   r   r   c                 G     | j S r   )rE   r   r5   r   r   r   r&         zReturnLoggerFactory.__call__Nr'   )r5   r   r   r   )r)   r*   r+   r,   r   r&   r   r   r   r   r   v   s    

r   c                   @  s*   e Zd ZU dZded< ded< ded< dS )	r   a%  
    A call as captured by `CapturingLogger`.

    Can also be unpacked like a tuple.

    Arguments:

        method_name: The method name that got called.

        args: A tuple of the positional arguments.

        kwargs: A dict of the keyword arguments.

    .. versionadded:: 20.2.0
    r"   r!   ztuple[Any, ...]r5   zdict[str, Any]kwargsN)r)   r*   r+   r,   r-   r   r   r   r   r      s
   
 r   c                   @  s8   e Zd ZU dZded< dddZdd	d
ZdddZdS )r   z
    Store the method calls that it's been called with.

    This is nicer than `ReturnLogger` for unit tests because the bound logger
    doesn't have to cooperate.

    **Any** method name is supported.

    .. versionadded:: 20.2.0
    zlist[CapturedCall]callsr   r   c                 C  r   r   )rK   r   r   r   r   r      r   zCapturingLogger.__init__r"   c                 C  s   dt | j dS )Nz<CapturingLogger with z	 call(s)>)r7   rK   r   r   r   r   __repr__   s   zCapturingLogger.__repr__namer   c                   s   d	 fdd}|S )
z)
        Capture call to `calls`
        r5   r   r6   r   r   c                    s   j t | | d S r   )rK   r%   r   )r5   r6   rM   r   r   r   r9      s   z(CapturingLogger.__getattr__.<locals>.logN)r5   r   r6   r   r   r   r   )r   rM   r9   r   rN   r   __getattr__   s   zCapturingLogger.__getattr__Nr'   )r   r"   )rM   r"   r   r   )r)   r*   r+   r,   r-   r   rL   rO   r   r   r   r   r      s   
 

r   c                   @  s.   e Zd ZU dZded< dddZdd
dZdS )r   a1  
    Produce and cache `CapturingLogger`\ s.

    Each factory produces and re-uses only **one** logger.

    You can access it via the ``logger`` attribute.

    To be used with `structlog.configure`\ 's *logger_factory*.

    Positional arguments are silently ignored.

    .. versionadded:: 20.2.0
    r   loggerr   r   c                 C  rD   r   )r   rP   r   r   r   r   r      rF   zCapturingLoggerFactory.__init__r5   r   c                 G  rG   r   )rP   rH   r   r   r   r&      rI   zCapturingLoggerFactory.__call__Nr'   )r5   r   r   r   r(   r   r   r   r   r      s
   
 
r   N)r   r.   )r,   
__future__r   
contextlibr   typingr   r   r   r   _configr	   r
   
exceptionsr   r   r   __all__r   r   r   r   r   r   r   r   r   r   r   <module>   s    