
    df*                       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j8                  d)i ej:                  ddi G d d             Z ej8                  d)i ej:                  ddi G d d             ZerQee eeef   e!eef   ee   f   Z"de#d<   eejH                  e"f   Z%eejL                  e"f   Z' e
de%      Z( e
de'      Z)edddd	 	 	 	 	 	 	 	 	 	 	 d*d       Z*edddd	 	 	 	 	 	 	 	 	 	 	 	 	 d+d       Z*edddd	 	 	 	 	 	 	 	 	 	 	 	 	 d,d       Z*deddd	 	 	 	 	 	 	 	 	 	 	 d-d Z* e
d!e	def         Z+ed.d"       Z,edddd#	 	 	 	 	 	 	 d/d$       Z,	 d0dded#	 	 	 	 	 	 	 	 	 d1d%Z, e
d&      Z-eree-df   Z.y ej8                  d)i ej:                   G d' d(             Z.y)2zEThis 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                  @    e Zd ZU dZded<   eZded<   dZded<   dd	Zy
)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_usedc                    ||      }	 t        j                  | j                  | j                  |j	                               }|t        u rdn|j                  |      }t        j                  | j                  t        j                  | j                  d      || j                        |d<   |S # t
        $ r}t        j                  |      |d}~ww xY w)zGets the Pydantic core schema.

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

        Returns:
            The Pydantic core schema.
        Nplainfunctioninfo_argreturn_schemar   serialization)r   get_function_return_typer   r   _get_types_namespace	NameErrorr   from_name_errorr   generate_schemar   $plain_serializer_function_ser_schemainspect_annotated_serializerr   selfsource_typehandlerschemar   er"   s          X/home/api-vastappli/venv/lib/python3.12/site-packages/pydantic/functional_serializers.py__get_pydantic_core_schema__z,PlainSerializer.__get_pydantic_core_schema__    s     %	H%>>		4++W-I-I-KK
 !,/@ @gF]F]^iFj"-"R"RYY ==diiQ'nn	#
   	H-==a@aG	H   9B. .	C7CCNr-   r   r.   r   returnzcore_schema.CoreSchema	__name__
__module____qualname____doc____annotations__r   r   r   r2        r1   r   r      s)     )((K(NVIKVr=   r   c                  @    e Zd ZU dZded<   eZded<   dZded<   dd	Zy
)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   c                    ||      }	 t        j                  | j                  | j                  |j	                               }|t        u rdn|j                  |      }t        j                  | j                  t        j                  | j                  d      || j                        |d<   |S # t
        $ r}t        j                  |      |d}~ww xY w)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+   s          r1   r2   z+WrapSerializer.__get_pydantic_core_schema__K   s     %	H%>>		4++W-I-I-KK
 !,/@ @gF]F]^iFj"-"Q"QYY ==diiP'nn	#
   	H-==a@aG	Hr3   Nr4   r6   r<   r=   r1   r?   r?   ;   s)     -,(K(NVIKVr=   r?   r   _PartialClsOrStaticMethod_PlainSerializeMethodType)bound_WrapSerializeMethodType.)r   r   check_fieldsc                    y Nr<   )__fieldr   r   rG   fieldss        r1   field_serializerrL   n   s     r=   c                    y rI   r<   rJ   moder   r   rG   rK   s         r1   rL   rL   y        r=   c                    y rI   r<   rN   s         r1   rL   rL      rP   r=   r   r   )rO   r   r   rG   c                ,     	 	 	 	 d f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.
    c                d    t        j                        }t        j                  | |      S )N)rK   rO   r   r   rG   )r   FieldSerializerDecoratorInfoPydanticDescriptorProxy)fdec_inforG   rK   rO   r   r   s     r1   deczfield_serializer.<locals>.dec   s9     ;;#%
 221h??r=   )rV   zHCallable[..., Any] | staticmethod[Any, Any] | classmethod[Any, Any, Any]r5   (_decorators.PydanticDescriptorProxy[Any]r<   )rO   r   r   rG   rK   rX   s   ````` r1   rL   rL      s)    B
@S
@	1
@ 
@ Jr=   FuncTypec                     y rI   r<   )__fs    r1   model_serializerr]      s    r=   rO   r   r   c                     y rI   r<   r^   s      r1   r]   r]      s     r=   c               0    dfd}| |S  ||       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.
    c                `    t        j                        }t        j                  | |      S )N)rO   r   r   )r   ModelSerializerDecoratorInforU   )rV   rW   rO   r   r   s     r1   rX   zmodel_serializer.<locals>.dec   s,    ;;S^jst221h??r=   )rV   zCallable[..., Any]r5   rY   r<   )r\   rO   r   r   rX   s    ``` r1   r]   r]      s    2@ {
3xr=   AnyTypec                  @    e Zd ZddZ	 	 	 	 	 	 ddZej                  Zy)SerializeAsAnyc                (    t         |t               f   S rI   )r   re   )clsitems     r1   __class_getitem__z SerializeAsAny.__class_getitem__  s    T>#3344r=   c                     ||      }|}|d   dk(  r|j                         }|d   }|d   dk(  rt        j                  d t        j                               |d<   |S )Ntypedefinitionsr/   c                     ||       S rI   r<   )xhs     r1   <lambda>z=SerializeAsAny.__get_pydantic_core_schema__.<locals>.<lambda>  s
    QqT r=   )r/   r#   )copyr   rB   
any_schema)r,   r-   r.   r/   schema_to_updates        r1   r2   z+SerializeAsAny.__get_pydantic_core_schema__  sw     [)F%"6*m;#3#8#8#: #3H#=  #6*m; 1<0_0_!+*@*@*B1_- Mr=   N)rh   r   r5   r   r4   )r7   r8   r9   ri   r2   object__hash__r<   r=   r1   re   re     s/    	5	"	-A	#	 ??r=   re   r<   )rJ   strrK   rv   r   r   r   r   rG   bool | Noner5   @Callable[[_PlainSerializeMethodType], _PlainSerializeMethodType])rJ   rv   rK   rv   rO   zLiteral['plain']r   r   r   r   rG   rw   r5   rx   )rJ   rv   rK   rv   rO   zLiteral['wrap']r   r   r   r   rG   rw   r5   z>Callable[[_WrapSerializeMethodType], _WrapSerializeMethodType])rK   rv   rO   Literal['plain', 'wrap']r   r   r   r   rG   rw   r5   Callable[[Any], Any])r\   rZ   r5   rZ   )rO   ry   r   r   r   r   r5   zCallable[[FuncType], FuncType]rI   )
r\   zCallable[..., Any] | NonerO   ry   r   r   r   r   r5   rz   )/r:   
__future__r   dataclasses	functoolsr   typingr   r   r   r   r	   r
   pydantic_corer   r   _core_schematyping_extensionsr   r   r    r   	_internalr   r   annotated_handlersr   	dataclass
slots_truer   r?   classmethodstaticmethodrC   r;   SerializerFunction_PlainSerializationFunctionWrapSerializerFunction_WrapSerializationFunctionrD   rF   rL   rZ   r]   rc   re   r<   r=   r1   <module>r      s   K "  # I I 8 5 ; ; ) 7 4 E,77EE& & F&R E,77EE' ' F'T +0S#s]1K\Z]_bZbMcersvew1w+xyx"'(G(GIb(b"c!&|'J'JLe'e!f '(CKf g&'AIcd 
 NQ #  L	
  F 
 

 NQ #  	
 L  F 
 

 NQ #  	
 L  D 
 &-(NV $--
"- - L	-
 - -` :Xc3h%78 
 
 
 &)NV	
" L 	
 $ 
 &*  &-NV( 	"  #  L	 
    F )
 w|,N [<0;;<# # =#r=   