
    	h                        U d Z ddlmZ ddlZddl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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dS )+aX  
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.

See :doc:`contextvars`.
    )annotationsN)Any	GeneratorMapping   )BindableLogger	EventDictWrappedLogger
structlog_z&dict[str, contextvars.ContextVar[Any]]_CONTEXT_VARSreturndict[str, Any]c                     i } t          j                    }|D ]M}|j                            t                    r,||         t
          ur||         | |j        t          d         <   N| 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      b/var/www/html/web-builder-api.evdpl.com/venv/lib/python3.11/site-packages/structlog/contextvars.pyget_contextvarsr   '   so     
B

"
$
$C ; ;6122 	;s1vX7M7M47FBqv.//01I    bound_loggerr   c                p    t                      }|                    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)r   r   s     r   get_merged_contextvarsr"   7   s1     

CJJy$\22333Jr   loggerr
   method_namestr
event_dictr	   c                    t          j                    }|D ]^}|j                            t                    r=||         t
          ur.|                    |j        t          d         ||                    _|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   )r#   r$   r&   r   r   s        r   merge_contextvarsr)   D   sz     
"
$
$C M M6122 	Ms1vX7M7M!!!&)A)B)B"CSVLLLr   Nonec                     t          j                    } | D ];}|j                            t                    r|                    t                     <dS )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-   Y   sT     
"
$
$C  6122 	EE(OOO r   kwr   $Mapping[str, contextvars.Token[Any]]c                    i }|                                  D ]l\  }}t           | }	 t          |         }n5# t          $ r( t	          j        |t                    }|t          |<   Y nw xY w|                    |          ||<   m|S )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,   )r.   r   r   vstructlog_kvars         r   bind_contextvarsr8   i   s     
B

  1-2q22	-,CC 	- 	- 	-(hGGGC),M+&&&	- 

1Is   6/A('A(contextvars.Token[Any]c                     |                                  D ]2\  }}t           | }t          |         }|                    |           3dS )z\
    Reset contextvars corresponding to the given Tokens.

    .. versionadded:: 21.1.0
    N)r2   r   r   reset)r.   r   r5   r6   r7   s        r   reset_contextvarsr<      sT     

  1-2q22K(		! r   keysc                     | D ];}t            | }|t          v r%t          |                             t                     <dS )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   )r=   r   r6   s      r   unbind_contextvarsr?      sR      5 5-2q22-''+&**84445 5r   Generator[None, None, None]c               +  Z  K   t                      fd                                |                                 z  D             }t          di |  	 dV  t          |                                   t          di | dS # t          |                                   t          di | w xY 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
    c                "    i | ]}||         S  rC   ).0r   contexts     r   
<dictcomp>z%bound_contextvars.<locals>.<dictcomp>   s    ???qQ
???r   NrC   )r   r=   r8   r?   )r.   savedrE   s     @r   bound_contextvarsrH      s       G????GLLNNRWWYY$>???Er"BGGII&&!!5!!!!! 	BGGII&&!!5!!!!s   B )B*)r   r   )r   r   r   r   )r#   r
   r$   r%   r&   r	   r   r	   )r   r*   )r.   r   r   r/   )r.   r9   r   r*   )r=   r%   r   r*   )r.   r   r   r@   )__doc__
__future__r   
contextlibr   typingr   r   r   r    r   r	   r
   r   lenr   r   __annotations__r   r"   r)   r-   r8   r<   r?   contextmanagerrH   rC   r   r   <module>rP      sn  
 
 
 # " " " " "         * * * * * * * * * *     < < < < < < < < < < $ 3344 
 9; : : : :    
 
 
 
   *       :	 	 	 	5 5 5 5  " " " " " "r   