
    "h                        U d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
 ddlZddlmZmZmZ dZ ee      Z ej$                  d	      Zd
ed	<   i 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ej:                  dd       Zy)a  
Primitives to deal with a concurrency supporting context, as introduced in
Python 3.7 as :mod:`contextvars`.

.. versionadded:: 20.1.0
.. versionchanged:: 21.1.0
   Reimplemented without using a single dict as context carrier for improved
   isolation. Every key-value pair is a separate `contextvars.ContextVar` now.
.. versionchanged:: 23.3.0
   Callsite parameters are now also collected under asyncio.

See :doc:`contextvars`.
    )annotationsN)	FrameType)Any	GeneratorMapping   )BindableLogger	EventDictWrappedLogger
structlog__ASYNC_CALLING_STACKz!contextvars.ContextVar[FrameType]z&dict[str, contextvars.ContextVar[Any]]_CONTEXT_VARSc                     i } t        j                         }|D ]G  }|j                  j                  t              s#||   t
        us/||   | |j                  t        d <   I | S )zh
    Return a copy of the *structlog*-specific context-local context.

    .. versionadded:: 21.2.0
    N)contextvarscopy_contextname
startswithSTRUCTLOG_KEY_PREFIXEllipsisSTRUCTLOG_KEY_PREFIX_LEN)rvctxks      R/var/www/html/sandstorm/venv/lib/python3.12/site-packages/structlog/contextvars.pyget_contextvarsr   .   sf     
B

"
"
$C ;6612s1vX7M47FBqvv./01; I    c                b    t               }|j                  t        j                  |              |S )z
    Return a copy of the current context-local context merged with the context
    from *bound_logger*.

    .. versionadded:: 21.2.0
    )r   update	structlogget_context)bound_loggerr   s     r   get_merged_contextvarsr"   >   s(     
CJJy$$\23Jr   c                    t        j                         }|D ]T  }|j                  j                  t              s#||   t
        us/|j                  |j                  t        d ||          V |S )a  
    A processor that merges in a global (context-local) context.

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

    .. versionadded:: 20.1.0
    .. versionchanged:: 21.1.0 See toplevel note.
    N)r   r   r   r   r   r   
setdefaultr   )loggermethod_name
event_dictr   r   s        r   merge_contextvarsr(   K   sj     
"
"
$C M6612s1vX7M!!!&&)A)B"CSVLM r   c                     t        j                         } | D ]7  }|j                  j                  t              s#|j                  t               9 y)z
    Clear the context-local context.

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

    .. versionadded:: 20.1.0
    .. versionchanged:: 21.1.0 See toplevel note.
    N)r   r   r   r   r   setr   )r   r   s     r   clear_contextvarsr+   `   s?     
"
"
$C 6612EE(Or   c                     i }| j                         D ]-  \  }}t         | }	 t        |   }|j                  |      ||<   / |S # t        $ r' t	        j
                  |t              }|t        |<   Y Gw xY w)a  
    Put keys and values into the context-local context.

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

    Return the mapping of `contextvars.Token`\s resulting
    from setting the backing :class:`~contextvars.ContextVar`\s.
    Suitable for passing to :func:`reset_contextvars`.

    .. versionadded:: 20.1.0
    .. versionchanged:: 21.1.0 Return the `contextvars.Token` mapping
        rather than None. See also the toplevel note.
    )default)itemsr   r   KeyErrorr   
ContextVarr   r*   )kwr   r   vstructlog_kvars         r   bind_contextvarsr5   p   s     
B
 1-.qc2	-,C
 
1 I  	-((hGC),M+&	-s   	A-A54A5c                 |    | j                         D ])  \  }}t         | }t        |   }|j                  |       + y)z\
    Reset contextvars corresponding to the given Tokens.

    .. versionadded:: 21.1.0
    N)r.   r   r   reset)r1   r   r2   r3   r4   s        r   reset_contextvarsr8      sA     
 1-.qc2K(		!r   c                 p    | D ]1  }t          | }|t        v st        |   j                  t               3 y)a"  
    Remove *keys* from the context-local context if they are present.

    Use this instead of :func:`~structlog.BoundLogger.unbind` when you want to
    remove keys from a global (context-local) context.

    .. versionadded:: 20.1.0
    .. versionchanged:: 21.1.0 See toplevel note.
    N)r   r   r*   r   )keysr   r3   s      r   unbind_contextvarsr;      s=      5-.qc2-'+&**845r   c               +  <  K   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 context-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
    N )r   r:   r5   r;   )r1   contextr   saveds       r   bound_contextvarsr@      s      G$+LLNRWWY$>?qQ
]?E?r"BGGI&!5! @ 	BGGI&!5!s'   .BA1BA6 'B6#BB)returndict[str, Any])r!   r	   rA   rB   )r%   r   r&   strr'   r
   rA   r
   )rA   None)r1   r   rA   z$Mapping[str, contextvars.Token[Any]])r1   zcontextvars.Token[Any]rA   rD   )r:   rC   rA   rD   )r1   r   rA   zGenerator[None, None, None])__doc__
__future__r   
contextlibr   typesr   typingr   r   r   r   r	   r
   r   r   lenr   r0   r   __annotations__r   r   r"   r(   r+   r5   r8   r;   contextmanagerr@   r=   r   r   <module>rM      s    #    * *  < < $ 34  K12 7  9;5 : 
(+9B* :	5  " "r   