o
    i                     @   s   d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
mZ ddlmZ ddlZddlmZmZmZmZmZ eG d	d
 d
ZG dd deZG dd deZeedZdS )a'  A data converter for Pydantic v2.

To use, pass ``pydantic_data_converter`` as the ``data_converter`` argument to
:py:class:`temporalio.client.Client`:

.. code-block:: python

    client = Client(
        data_converter=pydantic_data_converter,
        ...
    )

Pydantic v1 is not supported.
    )	dataclass)AnyOptionalType)TypeAdapter)SchemaSerializerto_json)
any_schemaN)CompositePayloadConverterDataConverterDefaultPayloadConverterEncodingPayloadConverterJSONPlainPayloadConverterc                   @   s   e Zd ZU dZdZeed< dS )ToJsonOptionsz-Options for converting to JSON with pydantic.Fexclude_unsetN)__name__
__module____qualname____doc__r   bool__annotations__ r   r   a/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/temporalio/contrib/pydantic.pyr   $   s   
 r   c                   @   sz   e Zd ZdZddee fddZedefddZ	d	e
deejjjj fd
dZ	ddejjjjdee de
fddZdS )!PydanticJSONPlainPayloadConvertera  Pydantic JSON payload converter.

    Supports conversion of all types supported by Pydantic to and from JSON.

    In addition to Pydantic models, these include all `json.dump`-able types,
    various non-`json.dump`-able standard library types such as dataclasses,
    types from the datetime module, sets, UUID, etc, and custom types composed
    of any of these.

    See https://docs.pydantic.dev/latest/api/standard_library_types/
    Nto_json_optionsc                 C   s   t t | _|| _dS )zCreate a new payload converter.N)r   r	   _schema_serializer_to_json_optionsselfr   r   r   r   __init__8   s   
z*PydanticJSONPlainPayloadConverter.__init__returnc                 C   s   dS )zSee base class.z
json/plainr   )r   r   r   r   encoding=   s   z*PydanticJSONPlainPayloadConverter.encodingvaluec                 C   s@   | j r| jj|| j jdnt|}tjjjjd| j	
 i|dS )zSee base class.

        Uses ``pydantic_core.to_json`` to serialize ``value`` to JSON.

        See
        https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core.to_json.
        )r   r!   )metadatadata)r   r   r   r   
temporalioapicommonv1Payloadr!   encode)r   r"   r$   r   r   r   
to_payloadB   s   
z,PydanticJSONPlainPayloadConverter.to_payloadpayload	type_hintc                 C   s    |dur|nt }t||jS )a%  See base class.

        Uses ``pydantic.TypeAdapter.validate_json`` to construct an
        instance of the type specified by ``type_hint`` from the JSON payload.

        See
        https://docs.pydantic.dev/latest/api/type_adapter/#pydantic.type_adapter.TypeAdapter.validate_json.
        N)r   r   validate_jsonr$   )r   r,   r-   
_type_hintr   r   r   from_payloadU   s   z.PydanticJSONPlainPayloadConverter.from_payloadN)r   r   r   r   r   r   r   propertystrr!   r   r%   r&   r'   r(   r)   r+   r   r0   r   r   r   r   r   +   s    
r   c                       s0   e Zd ZdZddee ddf fddZ  ZS )PydanticPayloadConverterzPayload converter for payloads containing pydantic model instances.

    JSON conversion is replaced with a converter that uses
    :py:class:`PydanticJSONPlainPayloadConverter`.
    Nr   r    c                    s(   t | t j fddtjD   dS )zInitialize objectc                 3   s"    | ]}t |ts|n V  qd S r1   )
isinstancer   ).0cjson_payload_converterr   r   	<genexpr>q   s    
z4PydanticPayloadConverter.__init__.<locals>.<genexpr>N)r   superr   r   #default_encoding_payload_convertersr   	__class__r8   r   r   m   s   
z!PydanticPayloadConverter.__init__r1   )r   r   r   r   r   r   r   __classcell__r   r   r=   r   r4   f   s    $r4   )payload_converter_class)r   dataclassesr   typingr   r   r   pydanticr   pydantic_corer   r   pydantic_core.core_schemar	   temporalio.api.common.v1r%   temporalio.converterr
   r   r   r   r   r   r   r4   pydantic_data_converterr   r   r   r   <module>   s     ;