o
    DD©iø  ã                   @  sš   U d Z ddlmZ ddlZddlZddlZzddlmZ W n ey*   e	e
ƒZY nw e d¡Ze d¡Ze d¡Zded	< G d
d„ dejeje ƒZdS )ar  Helper API for setting serialization/deserialization context.

Example usage:

.. code-block:: python

    import typing

    from marshmallow import Schema, fields
    from marshmallow.experimental.context import Context


    class UserContext(typing.TypedDict):
        suffix: str


    UserSchemaContext = Context[UserContext]


    class UserSchema(Schema):
        name_suffixed = fields.Function(
            lambda user: user["name"] + UserSchemaContext.get()["suffix"]
        )


    with UserSchemaContext({"suffix": "bar"}):
        print(UserSchema().dump({"name": "foo"}))
        # {'name_suffixed': 'foobar'}
é    )ÚannotationsN)ÚEllipsisTypeÚ	_ContextTÚ	_DefaultTÚcontextzcontextvars.ContextVarÚ_CURRENT_CONTEXTc                   @  s>   e Zd ZdZddd„Zdd	d
„Zddd„Zedddd„ƒZdS )ÚContextz‚Context manager for setting and retrieving context.

    :param context: The context to use within the context manager scope.
    r   r   ÚreturnÚNonec                 C  s   || _ d | _d S ©N)r   Útoken)Úselfr   © r   úY/var/www/Datamplify/venv/lib/python3.10/site-packages/marshmallow/experimental/context.pyÚ__init__5   s   
zContext.__init__úContext[_ContextT]c                 C  s   t  | j¡| _| S r   )r   Úsetr   r   )r   r   r   r   Ú	__enter__9   s   zContext.__enter__c                 O  s   t  t d| j¡¡ d S )Nzcontextvars.Token)r   ÚresetÚtypingÚcastr   )r   ÚargsÚkwargsr   r   r   Ú__exit__=   s   zContext.__exit__.Údefaultú_DefaultT | EllipsisTypeú_ContextT | _DefaultTc                 C  s   |dur	t  |¡S t  ¡ S )z»Get the current context.

        :param default: Default value to return if no context is set.
            If not provided and no context is set, a :exc:`LookupError` is raised.
        .)r   Úget)Úclsr   r   r   r   r   @   s   
zContext.getN)r   r   r	   r
   )r	   r   )r	   r
   ).)r   r   r	   r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úclassmethodr   r   r   r   r   r   /   s    


r   )r"   Ú
__future__r   Ú
contextlibÚcontextvarsr   Útypesr   ÚImportErrorÚtypeÚEllipsisÚTypeVarr   r   Ú
ContextVarr   Ú__annotations__ÚAbstractContextManagerÚGenericr   r   r   r   r   Ú<module>   s    ÿ

