a
    y{Jh*                  
   @  s  U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZ ddlmZm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 ejf i ejddiG dd dZejf i ejddiG dd dZerTee eeef e!eef ee f Z"de#d< eej$e"f Z%eej&e"f Z'e
de%dZ(e
de'dZ)edddddddddddd d!Z*eddddddd"ddddd#d$d!Z*eddddddd%dddd&d#d'd!Z*d(ed)dd*dd+dddd,d-d.d!Z*e
d/e	def dZ+ed/d/d0d1d2Z,edd)dd3d+ddd4d5d6d2Z,d=d(d)ed3d7d+ddd,d8d9d2Z,e
d:Z-ervee-df Z.n ejf i ejG d;d< d<Z.dS )>zEThis module contains related classes and functions for serialization.    )annotationsN)partialmethod)TYPE_CHECKINGAnyCallableTypeVarUnionoverload)PydanticUndefinedcore_schema)r   )	AnnotatedLiteral	TypeAlias   )PydanticUndefinedAnnotation)_decorators_internal_dataclass)GetCoreSchemaHandlerfrozenTc                   @  sD   e Zd ZU dZded< eZded< dZded< dd	d
dddZdS )PlainSerializera  Plain serializers use a function to modify the output of serialization.

    Attributes:
        func: The serializer function.
        return_type: The return type for the function. If omitted it will be inferred from the type annotation.
        when_used: Determines when this serializer should be used. Accepts a string with values `'always'`,
            `'unless-none'`, `'json'`, and `'json-unless-none'`. Defaults to 'always'.
    zcore_schema.SerializerFunctionfuncr   return_typealways<Literal['always', 'unless-none', 'json', 'json-unless-none']	when_usedr   core_schema.CoreSchemasource_typehandlerreturnc              
   C  s   ||}zt | j| j| }W n0 tyR } zt||W Y d}~n
d}~0 0 |tu r`dn|	|}t
j| jt | jd|| jd|d< |S )zGets the Pydantic core schema.

        Args:
            source_type: The source type.
            handler: The `GetCoreSchemaHandler` instance.

        Returns:
            The Pydantic core schema.
        NplainfunctionZinfo_argreturn_schemar   serialization)r   get_function_return_typer   r   _get_types_namespace	NameErrorr   from_name_errorr
   generate_schemar   Z$plain_serializer_function_ser_schemainspect_annotated_serializerr   selfr   r   schemar   er#    r/   Q/var/www/shaz/venv/lib/python3.9/site-packages/pydantic/functional_serializers.py__get_pydantic_core_schema__    s    
"
z,PlainSerializer.__get_pydantic_core_schema__N	__name__
__module____qualname____doc____annotations__r
   r   r   r1   r/   r/   r/   r0   r      s
   
	r   c                   @  sD   e Zd ZU dZded< eZded< dZded< dd	d
dddZdS )WrapSerializeraS  Wrap serializers receive the raw inputs along with a handler function that applies the standard serialization
    logic, and can modify the resulting value before returning it as the final output of serialization.

    Attributes:
        func: The serializer function to be wrapped.
        return_type: The return type for the function. If omitted it will be inferred from the type annotation.
        when_used: Determines when this serializer should be used. Accepts a string with values `'always'`,
            `'unless-none'`, `'json'`, and `'json-unless-none'`. Defaults to 'always'.
    z"core_schema.WrapSerializerFunctionr   r   r   r   r   r   r   r   r   c              
   C  s   ||}zt | j| j| }W n0 tyR } zt||W Y d}~n
d}~0 0 |tu r`dn|	|}t
j| jt | jd|| jd|d< |S )zThis method is used to get the Pydantic core schema of the class.

        Args:
            source_type: Source type.
            handler: Core schema handler.

        Returns:
            The generated core schema of the class.
        Nwrapr!   r$   )r   r%   r   r   r&   r'   r   r(   r
   r)   r   #wrap_serializer_function_ser_schemar*   r   r+   r/   r/   r0   r1   K   s    
"
z+WrapSerializer.__get_pydantic_core_schema__Nr2   r/   r/   r/   r0   r8   ;   s
   

r8   r   _PartialClsOrStaticMethod_PlainSerializeMethodType)bound_WrapSerializeMethodType.)r   r   check_fieldsstrr   r   zbool | Nonez@Callable[[_PlainSerializeMethodType], _PlainSerializeMethodType])__fieldfieldsr   r   r?   r   c                G  s   d S Nr/   )rA   r   r   r?   rB   r/   r/   r0   field_serializern   s    rD   zLiteral['plain'])rA   rB   moder   r   r?   r   c                G  s   d S rC   r/   rA   rE   r   r   r?   rB   r/   r/   r0   rD   y   s    	zLiteral['wrap']z>Callable[[_WrapSerializeMethodType], _WrapSerializeMethodType]c                G  s   d S rC   r/   rF   r/   r/   r0   rD      s    	r    r   )rE   r   r   r?   zLiteral['plain', 'wrap']zCallable[[Any], Any])rB   rE   r   r   r?   r   c                   s    ddd fdd}|S )a{  Decorator that enables custom field serialization.

    See [Custom serializers](../concepts/serialization.md#custom-serializers) for more information.

    Four signatures are supported:

    - `(self, value: Any, info: FieldSerializationInfo)`
    - `(self, value: Any, nxt: SerializerFunctionWrapHandler, info: FieldSerializationInfo)`
    - `(value: Any, info: SerializationInfo)`
    - `(value: Any, nxt: SerializerFunctionWrapHandler, info: SerializationInfo)`

    Args:
        fields: Which field(s) the method should be called on.
        mode: The serialization mode.

            - `plain` means the function will be called instead of the default serialization logic,
            - `wrap` means the function will be called with an argument to optionally call the
               default serialization logic.
        return_type: Optional return type for the function, if omitted it will be inferred from the type annotation.
        when_used: Determines the serializer will be used for serialization.
        check_fields: Whether to check that the fields actually exist on the model.

    Returns:
        The decorator function.
    zHCallable[..., Any] | staticmethod[Any, Any] | classmethod[Any, Any, Any](_decorators.PydanticDescriptorProxy[Any]fr   c                   s    t j d}t | |S )N)rB   rE   r   r   r?   )r   ZFieldSerializerDecoratorInfoPydanticDescriptorProxyrI   Zdec_infor?   rB   rE   r   r   r/   r0   dec   s    zfield_serializer.<locals>.decr/   )rE   r   r   r?   rB   rM   r/   rL   r0   rD      s    !FuncType)__fr   c                 C  s   d S rC   r/   )rO   r/   r/   r0   model_serializer   s    rP   rE   r   r   zCallable[[FuncType], FuncType])rE   r   r   r   c                 C  s   d S rC   r/   rQ   r/   r/   r0   rP      s    zCallable[..., Any] | None)rO   rE   r   r   r   c                  s0   ddd fdd}| du r$|S || S dS )a  Decorator that enables custom model serialization.

    See [Custom serializers](../concepts/serialization.md#custom-serializers) for more information.

    Args:
        __f: The function to be decorated.
        mode: The serialization mode.

            - `'plain'` means the function will be called instead of the default serialization logic
            - `'wrap'` means the function will be called with an argument to optionally call the default
                serialization logic.
        when_used: Determines when this serializer should be used.
        return_type: The return type for the function. If omitted it will be inferred from the type annotation.

    Returns:
        The decorator function.
    zCallable[..., Any]rG   rH   c                   s   t j d}t | |S )NrE   r   r   )r   ZModelSerializerDecoratorInforJ   rK   rR   r/   r0   rM      s    zmodel_serializer.<locals>.decNr/   )rO   rE   r   r   rM   r/   rR   r0   rP      s    AnyTypec                   @  s4   e Zd ZdddddZdddddd	ZejZd
S )SerializeAsAnyr   )itemr   c                 C  s   t |t f S rC   )r   rT   )clsrU   r/   r/   r0   __class_getitem__  s    z SerializeAsAny.__class_getitem__r   r   r   c                 C  sH   ||}|}|d dkr*|  }|d }qtjdd t d|d< |S )NtypeZdefinitionsr-   c                 S  s   || S rC   r/   )xhr/   r/   r0   <lambda>      z=SerializeAsAny.__get_pydantic_core_schema__.<locals>.<lambda>)r-   r$   )copyr   r:   Z
any_schema)r,   r   r   r-   Zschema_to_updater/   r/   r0   r1     s    

z+SerializeAsAny.__get_pydantic_core_schema__N)r3   r4   r5   rW   r1   object__hash__r/   r/   r/   r0   rT     s   rT   )N)/r6   
__future__r   dataclasses	functoolsr   typingr   r   r   r   r   r	   Zpydantic_corer
   r   Z_core_schematyping_extensionsr   r   r    r   	_internalr   r   Zannotated_handlersr   	dataclassZ
slots_truer   r8   classmethodstaticmethodr;   r7   ZSerializerFunctionZ_PlainSerializationFunctionZWrapSerializerFunctionZ_WrapSerializationFunctionr<   r>   rD   rN   rP   rS   rT   r/   r/   r/   r0   <module>   sx    )*,
  0
 #