
    "h#                       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Z e       Zdd	Zdd
Z ede      ZddZej4                  	 	 	 	 	 	 dd       Z G d d      Z ej:                         ZddZddZ 	 	 	 	 	 	 	 	 d dZ!e!Z"ddZ#d!dZ$d"dZ%ej4                  d#d       Z&ddZ'y)$z
**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WrappedLoggerc                 B    	 ddl m}  | S # t        $ r ddlm} |cY S w xY 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   s     R/var/www/html/sandstorm/venv/lib/python3.12/site-packages/structlog/threadlocal.py_determine_threadlocalr      s+    
0   #s   
 c                 .   d} t        j                  t              5  t        j                         }|j
                  j
                  j                  d   } ddd       | dk(  ryd}| dk(  r|dz  }t        j                  dt        |	       y# 1 sw Y   8xY w)
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   s      r   _deprecatedr(   1   s     H			Y	' 
MMO88??,,

 **J <a
MM	+	#
 
s   8BBc                    t                t        dt        t        j                               z   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.

    Args:
        dict_class: Class used for keeping context.

    .. deprecated:: 22.1.0
    zWrappedDict-)	r(   typestruuiduuid4_ThreadLocalDictWrapperThreadLocal_tl_dict_class)
dict_classWrappeds     r   	wrap_dictr4   P   sF     MTZZ\**-D,FG -GK$GN    TLLogger)boundc                b   t                t        | t              r| j                         } 	 | j                  j
                  j                  j                  | j                  j                        }| j                  | j                  | j                  i       }||_        |S # t        $ r | cY S w xY w)a5  
    Extract the context from a thread local logger into an immutable logger.

    Args:
        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_contextr0   dict_	__class___dict_logger_processorsAttributeError)loggerctxbls      r   as_immutablerG   h   s     M&./oo!!''11OO!!
 NN))  

 	 s   A3B   B.-B.c              +    K   t                t        | t              r| j                         } t	        |       j
                  }	  | j                  di | | j
                  j                          | j
                  j                  |       y# | j
                  j                          | j
                  j                  |       w xY w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
    N )r(   r;   r	   r<   rG   r=   clearupdate)rD   
tmp_valuessaveds      r   tmp_bindrN      s      M&./ ))E&fkk'J''u% 	u%s   A CB 6C7CCc                      e Zd ZU dZded<   ded<   ddZe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y)r.   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   r0   ztype[dict[str, Any]]r1   c                    |r6t        |d   | j                        r | j                  j                  di | y | j                  j                  |i | y)zA
        We cheat.  A context dict gets never recreated.
        r   NrI   )r;   r?   r@   rK   )selfargskws      r   __init__z _ThreadLocalDictWrapper.__init__   sJ     JtAw7 DJJ##DJJt*r*r5   c                   	 | j                   j                  j                  S # t        $ rV | j                   j	                         | j                   j                  _        | j                   j                  j                  cY S w xY w)zB
        Return or create and return the current context.
        )r?   r0   r>   rC   r1   rQ   s    r   r@   z_ThreadLocalDictWrapper._dict   sa    
	,>>%%+++ 	,'+~~'A'A'CDNN$>>%%+++	,s   " AB Bc                P    d| j                   j                   d| j                  dS )N<(z)>)r?   r   r@   rV   s    r   __repr__z _ThreadLocalDictWrapper.__repr__   s&    4>>**+1TZZN"==r5   c                4    | j                   |j                   k(  S N)r?   rQ   others     r   __eq__z_ThreadLocalDictWrapper.__eq__   s    ~~00r5   c                &    | j                  |       S r\   )r_   r]   s     r   __ne__z_ThreadLocalDictWrapper.__ne__   s    ;;u%%%r5   c                6    | j                   j                         S r\   )r@   __iter__rV   s    r   rc   z _ThreadLocalDictWrapper.__iter__   s    zz""$$r5   c                "    || j                   |<   y r\   )r@   )rQ   keyvalues      r   __setitem__z#_ThreadLocalDictWrapper.__setitem__   s    

3r5   c                :    | j                   j                  |       y r\   )r@   __delitem__)rQ   re   s     r   ri   z#_ThreadLocalDictWrapper.__delitem__   s    

s#r5   c                6    | j                   j                         S r\   )r@   __len__rV   s    r   rk   z_ThreadLocalDictWrapper.__len__   s    zz!!##r5   c                .    t        | j                  |      S r\   )getattrr@   )rQ   names     r   __getattr__z#_ThreadLocalDictWrapper.__getattr__   s    tzz4((r5   N)rR   r   rS   r   returnNonerp   r   )rp   r+   )r^   objectrp   bool)rp   zIterator[str])re   r+   rf   r   rp   rq   )re   r+   rp   rq   )rp   int)rn   r+   rp   r   )r   
__module____qualname____doc____annotations__rT   propertyr@   rZ   r_   ra   rc   rg   ri   rk   ro   rI   r5   r   r.   r.      sU    	 
H%%	+ 	, 	,>1&
% $$)r5   r.   c                 F    t                t               j                         S )zu
    Return a copy of the current thread-local context.

    .. versionadded:: 21.2.0
    .. deprecated:: 22.1.0
    )r(   _get_contextcopyrI   r5   r   get_threadlocalr~      s     M>  r5   c                    t                t               j                         }|j                  t	        j
                  |              |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(   r|   r}   rK   	structlogget_context)bound_loggerrE   s     r   get_merged_threadlocalr      s5     M
.


CJJy$$\23Jr5   c                l    t                t               j                         }|j                  |       |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(   r|   r}   rK   )rD   method_name
event_dictr:   s       r   merge_threadlocalr      s*    " Mn!!#GNN:Nr5   c                 .    t                i t        _        y)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:   rI   r5   r   clear_threadlocalr     s     MHr5   c                 J    t                t               j                  |        y)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(   r|   rK   )rS   s    r   bind_threadlocalr   *  s     MN"r5   c                 ^    t                t               }| D ]  }|j                  |d        y)z
    Tries to remove bound *keys* from threadlocal logging context if present.

    .. versionadded:: 20.1.0
    .. deprecated:: 22.1.0
    N)r(   r|   pop)keysr:   re   s      r   unbind_threadlocalr   8  s-     MnG Cr5   c               +  P  K   t                t               }|j                         | j                         z  D ci c]  }|||   
 }}t        di |  	 d t	        | j                           t        di | yc c}w # t	        | j                           t        di | w xY w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
    NrI   )r(   r~   r   r   r   )rS   r:   krM   s       r   bound_threadlocalr   E  s      MG$+LLNRWWY$>?qQ
]?E?r"BGGI&!5! @ 	BGGI&!5!s(   8B&A;B&B  'B& #B##B&c                 x    	 t         j                  S # t        $ r i t         _        t         j                  cY S w xY wr\   )r   r:   rC   rI   r5   r   r|   r|   \  s6        s    $99)rp   z	type[Any])rp   rq   )r2   type[Context]rp   r   )rD   r6   rp   r6   )rD   r6   rL   r   rp   zGenerator[TLLogger, None, None]rr   )r   r
   rp   r   )rD   r   r   r+   r   r   rp   r   )rS   r   rp   rq   )r   r+   rp   rq   )rS   r   rp   zGenerator[None, None, None])(rx   
__future__r   r   r   r   r,   r#   typingr   r   r   r   r   _configr	   r
   r   r   r   r   r/   r(   r4   r6   rG   contextmanagerrN   r.   r   r   r~   r   r   merge_threadlocal_contextr   r   r   r   r|   rI   r5   r   <module>r      s   #  
    4 4  ) E E %&>* :^4B &&$'&$& &.?) ?)D 9??!(+9B2 . 
 " ", r5   