o
    h#                     @  s:  d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZ ddlZddlmZ ddlmZmZmZmZ d:d
dZe Zd;ddZd<ddZededZd=ddZejd>ddZG dd dZe Zd?d d!Zd@d$d%Z dAd+d,Z!e!Z"d;d-d.Z#dBd0d1Z$dCd3d4Z%ejdDd6d7Z&d?d8d9Z'dS )Ez
**Deprecated** primitives to keep context global but thread (and greenlet)
local.

See `thread-local`, but please use :doc:`contextvars` instead.

.. deprecated:: 22.1.0
    )annotationsN)Any	GeneratorIteratorTypeVar   )BoundLoggerLazyProxy)BindableLoggerContext	EventDictWrappedLoggerreturn	type[Any]c                  C  s6   z	ddl m}  W | S  ty   ddlm} | Y S w )zg
    Return a dict-like threadlocal storage depending on whether we run with
    greenlets or not.
    r   )GreenThreadLocalr   )local)
_greenletsr   ImportError	threadingr   )r   r    r   K/var/www/html/ai/venv/lib/python3.10/site-packages/structlog/threadlocal.py_determine_threadlocal   s   r   Nonec                  C  sx   d} t t t }|jjjd } W d   n1 sw   Y  | dkr(dS d}| dkr2|d7 }tjdt	|d	 dS )
zA
    Raise a warning with best-effort stacklevel adjustment.
     __name__Nzstructlog.threadlocal   
contextlib   zR`structlog.threadlocal` is deprecated, please use `structlog.contextvars` instead.)
stacklevel)
r   suppress	Exceptionsys	_getframef_back	f_globalswarningswarnDeprecationWarning)callsitefr   r   r   r   _deprecated1   s"   
r)   
dict_classtype[Context]c                 C  s2   t   tdtt  tfi }t |_| |_|S )z
    Wrap a dict-like class and return the resulting class.

    The wrapped class and used to keep global in the current thread.

    Arguments:

        dict_class: Class used for keeping context.

    .. deprecated:: 22.1.0
    zWrappedDict-)	r)   typestruuiduuid4_ThreadLocalDictWrapperThreadLocal_tl_dict_class)r*   Wrappedr   r   r   	wrap_dictP   s   r5   TLLogger)boundloggerc                 C  sd   t   t| tr|  } z| jjj| jj}| j| j	| j
i d}||_|W S  ty1   |  Y S w )a<  
    Extract the context from a thread local logger into an immutable logger.

    Arguments:

        logger (structlog.typing.BindableLogger):
            A logger with *possibly* thread local state.

    Returns:

        :class:`~structlog.BoundLogger` with an immutable context.

    .. deprecated:: 22.1.0
    )
processorscontext)r)   
isinstancer   bind_contextr2   dict_	__class___dict_logger_processorsAttributeError)r8   ctxblr   r   r   as_immutablei   s"   

rF   
tmp_valuesr   Generator[TLLogger, None, None]c              	   k  sZ    t   t| j}z| jdi |V  W | j  | j| dS | j  | j| w )z
    Bind *tmp_values* to *logger* & memorize current state. Rewind afterwards.

    Only works with `structlog.threadlocal.wrap_dict`-based contexts.
    Use :func:`~structlog.threadlocal.bound_threadlocal` for new code.

    .. deprecated:: 22.1.0
    Nr   )r)   rF   r=   r<   clearupdate)r8   rG   savedr   r   r   tmp_bind   s   


rL   c                   @  s   e Zd ZU dZded< ded< d)d
dZed*ddZd+ddZd,ddZ	d,ddZ
d-ddZd.ddZd/d d!Zd0d#d$Zd1d&d'Zd(S )2r0   aI  
    Wrap a dict-like class and keep the state *global* but *thread-local*.

    Attempts to re-initialize only updates the wrapped dictionary.

    Useful for short-lived threaded applications like requests in web app.

    Use :func:`wrap` to instantiate and use
    :func:`structlog.BoundLogger.new` to clear the context.
    r   r2   ztype[dict[str, Any]]r3   argskwr   r   c                 O  s@   |rt |d | jr| jjdi | dS | jj|i | dS )zA
        We cheat.  A context dict gets never recreated.
        r   Nr   )r;   r?   r@   rJ   )selfrM   rN   r   r   r   __init__   s   z _ThreadLocalDictWrapper.__init__r
   c                 C  s:   z| j jjW S  ty   | j  | j j_| j jj Y S w )zB
        Return or create and return the current context.
        )r?   r2   r>   rC   r3   rO   r   r   r   r@      s   z_ThreadLocalDictWrapper._dictr-   c                 C  s   d| j j d| jdS )N<(z)>)r?   r   r@   rQ   r   r   r   __repr__   s   z _ThreadLocalDictWrapper.__repr__otherobjectboolc                 C  s   | j |j kS N)r?   rO   rU   r   r   r   __eq__   s   z_ThreadLocalDictWrapper.__eq__c                 C  s   |  | S rX   )rZ   rY   r   r   r   __ne__      z_ThreadLocalDictWrapper.__ne__Iterator[str]c                 C  
   | j  S rX   )r@   __iter__rQ   r   r   r   r_         
z _ThreadLocalDictWrapper.__iter__keyvaluec                 C  s   || j |< d S rX   )r@   )rO   ra   rb   r   r   r   __setitem__   s   z#_ThreadLocalDictWrapper.__setitem__c                 C  s   | j | d S rX   )r@   __delitem__)rO   ra   r   r   r   rd      s   z#_ThreadLocalDictWrapper.__delitem__intc                 C  r^   rX   )r@   __len__rQ   r   r   r   rf      r`   z_ThreadLocalDictWrapper.__len__namec                 C  s   t | j|S rX   )getattrr@   )rO   rg   r   r   r   __getattr__   r\   z#_ThreadLocalDictWrapper.__getattr__N)rM   r   rN   r   r   r   r   r
   )r   r-   )rU   rV   r   rW   )r   r]   )ra   r-   rb   r   r   r   )ra   r-   r   r   )r   re   )rg   r-   r   r   )r   
__module____qualname____doc____annotations__rP   propertyr@   rT   rZ   r[   r_   rc   rd   rf   ri   r   r   r   r   r0      s   
 







r0   r
   c                   C  s   t   t  S )zu
    Return a copy of the current thread-local context.

    .. versionadded:: 21.2.0
    .. deprecated:: 22.1.0
    )r)   _get_contextcopyr   r   r   r   get_threadlocal   s   
rr   bound_loggerr	   c                 C  s$   t   t  }|t|  |S )z
    Return a copy of the current thread-local context merged with the context
    from *bound_logger*.

    .. versionadded:: 21.2.0
    .. deprecated:: 22.1.0
    )r)   rp   rq   rJ   	structlogget_context)rs   rD   r   r   r   get_merged_threadlocal   s   
rv   r   method_namer-   
event_dictr   c                 C  s   t   t  }|| |S )a  
    A processor that merges in a global (thread-local) context.

    Use this as your first processor in :func:`structlog.configure` to ensure
    thread-local context is included in all log calls.

    .. versionadded:: 19.2.0

    .. versionchanged:: 20.1.0
       This function used to be called ``merge_threadlocal_context`` and that
       name is still kept around for backward compatibility.

    .. deprecated:: 22.1.0
    )r)   rp   rq   rJ   )r8   rw   rx   r:   r   r   r   merge_threadlocal   s   

ry   c                   C  s   t   i t_dS )z
    Clear the thread-local context.

    The typical use-case for this function is to invoke it early in
    request-handling code.

    .. versionadded:: 19.2.0
    .. deprecated:: 22.1.0
    N)r)   _CONTEXTr:   r   r   r   r   clear_threadlocal  s   

r{   rN   c                  K  s   t   t |  dS )z
    Put keys and values into the thread-local context.

    Use this instead of :func:`~structlog.BoundLogger.bind` when you want some
    context to be global (thread-local).

    .. versionadded:: 19.2.0
    .. deprecated:: 22.1.0
    N)r)   rp   rJ   )rN   r   r   r   bind_threadlocal*  s   
r|   keysc                  G  s&   t   t }| D ]}||d qdS )z
    Tries to remove bound *keys* from threadlocal logging context if present.

    .. versionadded:: 20.1.0
    .. deprecated:: 22.1.0
    N)r)   rp   pop)r}   r:   ra   r   r   r   unbind_threadlocal8  s
   r   Generator[None, None, None]c               
   +  s~    t   t   fdd  |  @ D }tdi |  zdV  W t|    tdi | dS t|    tdi | w )z
    Bind *kw* to the current thread-local context. Unbind or restore *kw*
    afterwards. Do **not** affect other keys.

    Can be used as a context manager or decorator.

    .. versionadded:: 21.4.0
    .. deprecated:: 22.1.0
    c                   s   i | ]}| | qS r   r   ).0kr:   r   r   
<dictcomp>R  s    z%bound_threadlocal.<locals>.<dictcomp>Nr   )r)   rr   r}   r|   r   )rN   rK   r   r   r   bound_threadlocalE  s   r   c                   C  s(   zt jW S  ty   i t _t j Y S w rX   )rz   r:   rC   r   r   r   r   rp   \  s   
rp   )r   r   )r   r   )r*   r+   r   r+   )r8   r6   r   r6   )r8   r6   rG   r   r   rH   rj   )rs   r	   r   r
   )r8   r   rw   r-   rx   r   r   r   )rN   r   r   r   )r}   r-   r   r   )rN   r   r   r   )(rm   
__future__r   r   r    r   r.   r$   typingr   r   r   r   rt   _configr   r	   r
   r   r   r   r1   r)   r5   r6   rF   contextmanagerrL   r0   r   rz   rr   rv   ry   merge_threadlocal_contextr{   r|   r   r   rp   r   r   r   r   <module>   s>   	



#B





