§
    ©	Êj	F  ã                  ó  — U d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
mZmZmZmZmZmZ ddlmZmZ ddlmZmZmZ dd	lmZ d
dlmZ d
dlmZ d
dlmZ d
dl m!Z!  ej"        dd¬¦  «         G d„ d¦  «        ¦   «         Z# ej"        dd¬¦  «         G d„ d¦  «        ¦   «         Z$e
r9dZ%de&d<   dZ'de&d<   	 dZ(de&d<   	 dZ)de&d<   	  ede'¬¦  «        Z* ed e(¬¦  «        Z+ed!d!d!d"œdUd0„¦   «         Z,ed!d!d!d!d1œdVd4„¦   «         Z,d5ed6dd1œdWd9„Z,e
r…eeee         gef         Z-de&d:<   	 eegef         Z.de&d;<   	 d<Z/de&d=<   	 eeeee         gef         Z0de&d><   	 eeegef         Z1de&d?<   	 d@Z2de&dA<   	 dBZ3de&dC<    edDe/¬¦  «        Z4 edEe2¬¦  «        Z5edXdG„¦   «         Z6ed6d!dHœdYdJ„¦   «         Z6ed!d6d!dKœdZdM„¦   «         Z6	 d[d5d6edKœd\dP„Z6 edQ¦  «        Z7e
ree7d!f         Z8dS  ej"        d¬R¦  «         G dS„ dT¦  «        ¦   «         Z8dS )]zEThis module contains related classes and functions for serialization.é    )ÚannotationsN)ÚCallable)ÚpartialÚpartialmethod)ÚTYPE_CHECKINGÚ	AnnotatedÚAnyÚLiteralÚ	TypeAliasÚTypeVarÚoverload)ÚPydanticUndefinedÚcore_schema)ÚSerializationInfoÚSerializerFunctionWrapHandlerÚWhenUsed)ÚTypeFormé   )ÚPydanticUndefinedAnnotation)Ú_decorators)ÚGetCoreSchemaHandler)ÚPydanticUserErrorT)ÚslotsÚfrozenc                  óB   — e Zd ZU dZded<   eZded<   dZded<   dd„ZdS )ÚPlainSerializera  Plain serializers use a function to modify the output of serialization.

    This is particularly helpful when you want to customize the serialization for annotated types.
    Consider an input of `list`, which will be serialized into a space-delimited string.

    ```python
    from typing import Annotated

    from pydantic import BaseModel, PlainSerializer

    CustomStr = Annotated[
        list, PlainSerializer(lambda x: ' '.join(x), return_type=str)
    ]

    class StudentModel(BaseModel):
        courses: CustomStr

    student = StudentModel(courses=['Math', 'Chemistry', 'English'])
    print(student.model_dump())
    #> {'courses': 'Math Chemistry English'}
    ```

    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ÚfuncúTypeForm[Any]Úreturn_typeÚalwaysr   Ú	when_usedÚsource_typer	   Úhandlerr   Úreturnúcore_schema.CoreSchemac                ó¸  —  ||¦  «        }| j         t          ur| j         }n[	 t          j        | j        |                     ¦   «         j        ¬¦  «        }n'# t          $ r}t          j	        |¦  «        |‚d}~ww xY w|t          u rdn| 
                    |¦  «        }t          j        | j        t          j        | j        d¦  «        || j        ¬¦  «        |d<   |S )zÒGets the Pydantic core schema.

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

        Returns:
            The Pydantic core schema.
        ©ÚlocalnsNÚplain©ÚfunctionÚinfo_argÚreturn_schemar!   Úserialization)r   r   r   Úget_callable_return_typer   Ú_get_types_namespaceÚlocalsÚ	NameErrorr   Úfrom_name_errorÚgenerate_schemar   Ú$plain_serializer_function_ser_schemaÚinspect_annotated_serializerr!   ©Úselfr"   r#   Úschemar   Úer-   s          úOC:\Projects\Muse2API\.venv\Lib\site-packages\pydantic/functional_serializers.pyÚ__get_pydantic_core_schema__z,PlainSerializer.__get_pydantic_core_schema__7   s  € ð �˜Ñ%Ô%ˆØÔÕ#4Ð4Ð4ØÔ*ˆKˆKð	Lõ *ÔBØ”IØ#×8Ò8Ñ:Ô:ÔAðñ ô ��øõ ð Lð Lð LÝ1ÔAÀ!ÑDÔDÈ!ÐKøøøøðLøøøð !,Õ/@Ð @Ð @˜˜Àg×F]ÒF]Ð^iÑFjÔFjˆÝ"-Ô"RØ”YÝ Ô=¸d¼iÈÑQÔQØ'Ø”nð	#
ñ #
ô #
ˆˆÑð ˆó   £2A Á
A:Á A5Á5A:N©r"   r	   r#   r   r$   r%   ©	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r!   r<   © ó    r;   r   r      sd   € € € € € € ðð ð: )Ð(Ð(Ñ(Ø!2€KÐ2Ð2Ð2Ñ2Ø"€IÐ"Ð"Ð"Ñ"ð ð  ð  ð  ð  ð  rF   r   c                  óB   — e Zd ZU dZded<   eZded<   dZded<   dd„ZdS )ÚWrapSerializera�  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.

    For example, here's a scenario in which a wrap serializer transforms timezones to UTC **and** utilizes the existing `datetime` serialization logic.

    ```python
    from datetime import datetime, timezone
    from typing import Annotated, Any

    from pydantic import (
        BaseModel,
        SerializationInfo,
        SerializerFunctionWrapHandler,
        WrapSerializer,
    )

    def convert_to_utc(
        value: Any, handler: SerializerFunctionWrapHandler, info: SerializationInfo
    ):
        # Note that `handler` can actually help serialize the `value` for
        # further custom serialization in case it's a subclass.
        serialized = handler(value)
        if info.mode == 'json':
            return datetime.fromisoformat(serialized).astimezone(timezone.utc)
        else:
            return serialized.astimezone(timezone.utc)

    UTCDatetime = Annotated[datetime, WrapSerializer(convert_to_utc)]

    class EventModel(BaseModel):
        event_datetime: UTCDatetime

    event = EventModel(event_datetime='2024-01-01T07:00:00-08:00')
    print(event.model_dump())
    '''
    {
        'event_datetime': datetime.datetime(
            2024, 1, 1, 15, 0, tzinfo=datetime.timezone.utc
        )
    }
    '''

    print(event.model_dump_json())
    #> {"event_datetime":"2024-01-01T15:00:00Z"}
    ```

    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#   r   r$   r%   c                ó¸  —  ||¦  «        }| j         t          ur| j         }n[	 t          j        | j        |                     ¦   «         j        ¬¦  «        }n'# t          $ r}t          j	        |¦  «        |‚d}~ww xY w|t          u rdn| 
                    |¦  «        }t          j        | j        t          j        | j        d¦  «        || j        ¬¦  «        |d<   |S )zïThis 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.
        r'   NÚwrapr*   r.   )r   r   r   r/   r   r0   r1   r2   r   r3   r4   r   Ú#wrap_serializer_function_ser_schemar6   r!   r7   s          r;   r<   z+WrapSerializer.__get_pydantic_core_schema__•   s  € ð �˜Ñ%Ô%ˆØÔÕ#4Ð4Ð4ØÔ*ˆKˆKð	Lõ *ÔBØ”IØ#×8Ò8Ñ:Ô:ÔAðñ ô ��øõ ð Lð Lð LÝ1ÔAÀ!ÑDÔDÈ!ÐKøøøøðLøøøð !,Õ/@Ð @Ð @˜˜Àg×F]ÒF]Ð^iÑFjÔFjˆÝ"-Ô"QØ”YÝ Ô=¸d¼iÈÑPÔPØ'Ø”nð	#
ñ #
ô #
ˆˆÑð ˆr=   Nr>   r?   rE   rF   r;   rH   rH   Z   se   € € € € € € ð3ð 3ðj -Ð,Ð,Ñ,Ø!2€KÐ2Ð2Ð2Ñ2Ø"€IÐ"Ð"Ð"Ñ"ð ð  ð  ð  ð  ð  rF   rH   z!partial[Any] | partialmethod[Any]r   Ú_Partialz)core_schema.SerializerFunction | _PartialÚFieldPlainSerializerz-core_schema.WrapSerializerFunction | _PartialÚFieldWrapSerializerz*FieldPlainSerializer | FieldWrapSerializerÚFieldSerializerÚ_FieldPlainSerializerT)ÚboundÚ_FieldWrapSerializerT.)r   r!   Úcheck_fieldsÚfieldÚstrÚfieldsÚmodeúLiteral['wrap']r   r   r!   r   rS   úbool | Noner$   ú8Callable[[_FieldWrapSerializerT], _FieldWrapSerializerT]c              ó   — d S ©NrE   ©rT   rW   r   r!   rS   rV   s         r;   Úfield_serializerr^   È   s   € ð @C¸srF   )rW   r   r!   rS   úLiteral['plain']ú:Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT]c              ó   — d S r\   rE   r]   s         r;   r^   r^   Ô   s   € ð BEÀrF   r)   r    úLiteral['plain', 'wrap']úuCallable[[_FieldWrapSerializerT], _FieldWrapSerializerT] | Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT]c              óî   ‡‡‡‡‡— t          | ¦  «        st          | t          ¦  «        rt          dd¬¦  «        ‚| g‰¢R Št	          d„ ‰D ¦   «         ¦  «        st          dd¬¦  «        ‚dˆˆˆˆˆfd„}|S )a¹  Decorator that enables custom field serialization.

    In the below example, a field of type `set` is used to mitigate duplication. A `field_serializer` is used to serialize the data as a sorted list.

    ```python
    from pydantic import BaseModel, field_serializer

    class StudentModel(BaseModel):
        name: str = 'Jane'
        courses: set[str]

        @field_serializer('courses', when_used='json')
        def serialize_courses_in_order(self, courses: set[str]):
            return sorted(courses)

    student = StudentModel(courses={'Math', 'Chemistry', 'English'})
    print(student.model_dump_json())
    #> {"name":"Jane","courses":["Chemistry","English","Math"]}
    ```

    See [the usage documentation](../concepts/serialization.md#serializers) for more information.

    Four signatures are supported for the decorated serializer:

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

    Args:
        *fields: The field names the serializer should apply to.
        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.

    Raises:
        PydanticUserError:
            - If the decorator is used without any arguments (at least one field name must be provided).
            - If the provided field names are not strings.
    zŸThe `@field_serializer` decorator cannot be used without arguments, at least one field must be provided. For example: `@field_serializer('<field_name>', ...)`.zdecorator-missing-arguments)Úcodec              3  ó@   K  — | ]}t          |t          ¦  «        V — Œd S r\   )Ú
isinstancerU   )Ú.0rT   s     r;   ú	<genexpr>z#field_serializer.<locals>.<genexpr>!  s,   è è € Ð:Ð:¨%�z˜%¥Ñ%Ô%Ð:Ð:Ð:Ð:Ð:Ð:rF   z›The provided field names to the `@field_serializer` decorator should be strings. For example: `@field_serializer('<field_name_1>', '<field_name_2>', ...).`zdecorator-invalid-fieldsÚfrO   r$   ú(_decorators.PydanticDescriptorProxy[Any]c                ó`   •— t          j        ‰‰‰‰‰¬¦  «        }t          j        | |¦  «        S )N)rV   rW   r   r!   rS   )r   ÚFieldSerializerDecoratorInfoÚPydanticDescriptorProxy)rj   Údec_inforS   rV   rW   r   r!   s     €€€€€r;   Údeczfield_serializer.<locals>.dec(  s>   ø€ ÝÔ;ØØØ#ØØ%ð
ñ 
ô 
ˆõ Ô2°1°hÑ?Ô?Ð?rF   )rj   rO   r$   rk   )Úcallablerg   Úclassmethodr   Úall)rT   rW   r   r!   rS   rV   rp   s    ````` r;   r^   r^   à   sÚ   øøøøø€ õr ��„ð 
�* U­KÑ8Ô8ð 
ÝðEà.ð
ñ 
ô 
ð 	
ð ˆ^�Vˆ^ˆ^€FÝÐ:Ð:°6Ð:Ñ:Ô:Ñ:Ô:ð 
ÝðYà+ð
ñ 
ô 
ð 	
ð@ð @ð @ð @ð @ð @ð @ð @ð @ð @ð €JrF   ÚModelPlainSerializerWithInfoÚModelPlainSerializerWithoutInfoz>ModelPlainSerializerWithInfo | ModelPlainSerializerWithoutInfoÚModelPlainSerializerÚModelWrapSerializerWithInfoÚModelWrapSerializerWithoutInfoz<ModelWrapSerializerWithInfo | ModelWrapSerializerWithoutInfoÚModelWrapSerializerz*ModelPlainSerializer | ModelWrapSerializerÚModelSerializerÚ_ModelPlainSerializerTÚ_ModelWrapSerializerTrj   c               ó   — d S r\   rE   )rj   s    r;   Úmodel_serializerr~   P  s   € ØNQÈcrF   )r!   r   ú8Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT]c                ó   — d S r\   rE   ©rW   r!   r   s      r;   r~   r~   T  s   € ð @C¸srF   r�   ú:Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]c                ó   — d S r\   rE   r�   s      r;   r~   r~   Z  s   € ð BEÀrF   ú5_ModelPlainSerializerT | _ModelWrapSerializerT | NoneúŽ_ModelPlainSerializerT | Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT] | Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]c              ó6   ‡‡‡— dˆˆˆfd„}| €|S  || ¦  «        S )a!  Decorator that enables custom model serialization.

    This is useful when a model need to be serialized in a customized manner, allowing for flexibility beyond just specific fields.

    An example would be to serialize temperature to the same temperature scale, such as degrees Celsius.

    ```python
    from typing import Literal

    from pydantic import BaseModel, model_serializer

    class TemperatureModel(BaseModel):
        unit: Literal['C', 'F']
        value: int

        @model_serializer()
        def serialize_model(self):
            if self.unit == 'F':
                return {'unit': 'C', 'value': int((self.value - 32) / 1.8)}
            return {'unit': self.unit, 'value': self.value}

    temperature = TemperatureModel(unit='F', value=212)
    print(temperature.model_dump())
    #> {'unit': 'C', 'value': 100}
    ```

    Two signatures are supported for `mode='plain'`, which is the default:

    - `(self)`
    - `(self, info: SerializationInfo)`

    And two other signatures for `mode='wrap'`:

    - `(self, nxt: SerializerFunctionWrapHandler)`
    - `(self, nxt: SerializerFunctionWrapHandler, info: SerializationInfo)`

        See [the usage documentation](../concepts/serialization.md#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.
    rj   rz   r$   rk   c                ó\   •— t          j        ‰‰‰¬¦  «        }t          j        | |¦  «        S )N)rW   r   r!   )r   ÚModelSerializerDecoratorInforn   )rj   ro   rW   r   r!   s     €€€r;   rp   zmodel_serializer.<locals>.dec£  s/   ø€ ÝÔ;ÀÐS^ÐjsÐtÑtÔtˆÝÔ2°1°hÑ?Ô?Ð?rF   N)rj   rz   r$   rk   rE   )rj   rW   r!   r   rp   s    ``` r;   r~   r~   c  sO   øøø€ ð@@ð @ð @ð @ð @ð @ð @ð @ð 	€yØˆ
àˆs�1‰vŒvˆrF   ÚAnyType)r   c                  ó0   — e Zd ZdZdd„Zdd
„Zej        ZdS )ÚSerializeAsAnyzÅAnnotation used to mark a type as having duck-typing serialization behavior.

        See [usage documentation](../concepts/serialization.md#serializing-with-duck-typing) for more details.
        Úitemr	   r$   c                ó8   — t           |t          ¦   «         f         S r\   )r   r‹   )ÚclsrŒ   s     r;   Ú__class_getitem__z SerializeAsAny.__class_getitem__¿  s   € Ý˜T¥>Ñ#3Ô#3Ð3Ô4Ð4rF   r"   r#   r   r%   c                ó¶   —  ||¦  «        }|}|d         dk    r(|                      ¦   «         }|d         }|d         dk    °(t          j        d¦  «        |d<   |S )NÚtypeÚdefinitionsr9   Úanyr.   )Úcopyr   Úsimple_ser_schema)r8   r"   r#   r9   Úschema_to_updates        r;   r<   z+SerializeAsAny.__get_pydantic_core_schema__Â  su   € ð �W˜[Ñ)Ô)ˆFØ%ÐØ" 6Ô*¨mÒ;Ð;Ø#3×#8Ò#8Ñ#:Ô#:Ð Ø#3°HÔ#=Ð ð # 6Ô*¨mÒ;Ð;õ 1<Ô0MÈeÑ0TÔ0TÐ˜_Ñ-ØˆMrF   N)rŒ   r	   r$   r	   r>   )r@   rA   rB   rC   r�   r<   ÚobjectÚ__hash__rE   rF   r;   r‹   r‹   ¸  sI   € € € € € ð	ð 	ð
	5ð 	5ð 	5ð 	5ð		ð 		ð 		ð 		ð ”?ˆˆˆrF   r‹   )rT   rU   rV   rU   rW   rX   r   r   r!   r   rS   rY   r$   rZ   )rT   rU   rV   rU   rW   r_   r   r   r!   r   rS   rY   r$   r`   )rT   rU   rV   rU   rW   rb   r   r   r!   r   rS   rY   r$   rc   )rj   r{   r$   r{   )rW   rX   r!   r   r   r   r$   r   )rW   r_   r!   r   r   r   r$   r‚   r\   )
rj   r„   rW   rb   r!   r   r   r   r$   r…   )9rC   Ú
__future__r   ÚdataclassesÚcollections.abcr   Ú	functoolsr   r   Útypingr   r   r	   r
   r   r   r   Úpydantic_corer   r   Úpydantic_core.core_schemar   r   r   Útyping_extensionsr   Ú r   Ú	_internalr   Úannotated_handlersr   Úerrorsr   Ú	dataclassr   rH   rL   rD   rM   rN   rO   rP   rR   r^   rt   ru   rv   rw   rx   ry   rz   r{   r|   r~   r‰   r‹   rE   rF   r;   ú<module>r¦      sN  ðØ KÐ KÐ Kà "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ WÐ Wà 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ø &Ð &Ð &Ð &Ð &Ð &à )Ð )Ð )Ð )Ð )Ð )Ø "Ð "Ð "Ð "Ð "Ð "Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø %Ð %Ð %Ð %Ð %Ð %ð €Ô˜T¨$Ð/Ñ/Ô/ðBð Bð Bð Bð Bñ Bô Bñ 0Ô/ðBðJ €Ô˜T¨$Ð/Ñ/Ô/ðZð Zð Zð Zð Zñ Zô Zñ 0Ô/ðZðz ð XØ=€HÐ=Ð=Ð=Ñ=à&QÐÐQÐQÐQÑQØ@à%TÐÐTÐTÐTÑTØ?à!M€OÐMÐMÐMÑMØ0à$˜WÐ%=ÐEYÐZÑZÔZÐØ#˜GÐ$;ÐCVÐWÑWÔWÐð 
ð "%ØØ #ðCð Cð Cð Cð Cñ 
„ðCð 
ð
 !Ø!$ØØ #ðEð Eð Eð Eð Eñ 
„ðEð &-Ø!2Ø"Ø $ðRð Rð Rð Rð Rð Rðj ð Xð /7¸Ð=NÈsÔ=SÐ7TÐVYÐ7YÔ.ZÐ ÐZÐZÐZÑZØNà19¸3¸%À¸*Ô1EÐ#ÐEÐEÐEÑEØQà&fÐÐfÐfÐfÑfØ4à-5°sÐ<YÐ[lÐmpÔ[qÐ6rÐtwÐ6wÔ-xÐÐxÐxÐxÑxØMà08¸#Ð?\Ð9]Ð_bÐ9bÔ0cÐ"ÐcÐcÐcÑcØPà%cÐÐcÐcÐcÑcØ3à!M€OÐMÐMÐMÑMà$˜WÐ%=ÐEYÐZÑZÔZÐØ#˜GÐ$;ÐCVÐWÑWÔWÐð 
Ø QÐ QÐ Qñ 
„Ø Qð 
à4<Ð[^ðCð Cð Cð Cð Cñ 
„ðCð
 
ð !Ø"Ø!$ð	Eð Eð Eð Eð Eñ 
„ðEð @DðGð &-Ø"Ø!2ðGð Gð Gð Gð Gð GðT ˆ'�)Ñ
Ô
€ð ð #Ø˜w¨˜|Ô,€Nðð ð €[Ô Ð&Ñ&Ô&ð#ð #ð #ð #ð #ñ #ô #ñ 'Ô&ð#ð #ð #rF   