§
    9ˆtjÅF  ã                  ó&  — U d Z ddlmZ ddl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mZ d	dlmZ d	dlm Z   ej!        dSi ej"        ¤ddi¤Ž G d„ d¦  «        ¦   «         Z# ej!        dSi ej"        ¤ddi¤Ž 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!œdTd/„¦   «         Z,ed d d d d0œdUd3„¦   «         Z,d4ed5dd0œdVd8„Z,er…ee
ee
         ge
f         Z-de&d9<   	 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&d@<   	 dAZ3de&dB<    edCe/¬¦  «        Z4 edDe2¬¦  «        Z5edWdF„¦   «         Z6ed5d dGœdXdI„¦   «         Z6ed d5d dJœdYdL„¦   «         Z6	 dZd4d5edJœd[dO„Z6 edP¦  «        Z7ere	e7d f         Z8dS  ej!        dSi ej"        ¤Ž G dQ„ dR¦  «        ¦   «         Z8dS )\zEThis module contains related classes and functions for serialization.é    )ÚannotationsN)ÚpartialÚpartialmethod)ÚTYPE_CHECKINGÚ	AnnotatedÚAnyÚCallableÚLiteralÚTypeVarÚoverload)ÚPydanticUndefinedÚcore_schema)ÚSerializationInfoÚSerializerFunctionWrapHandlerÚWhenUsed)Ú	TypeAliasé   )ÚPydanticUndefinedAnnotation)Ú_decoratorsÚ_internal_dataclass)ÚGetCoreSchemaHandler)ÚPydanticUserErrorÚfrozenTc                  ó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Úfuncr   Úreturn_typeÚalwaysr   Ú	when_usedÚsource_typeÚ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          ú]/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/pydantic/functional_serializers.pyÚ__get_pydantic_core_schema__z,PlainSerializer.__get_pydantic_core_schema__6   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:   © ó    r9   r   r      sd   € € € € € € ðð ð: )Ð(Ð(Ñ(Ø(€KÐ(Ð(Ð(Ñ(Ø"€IÐ"Ð"Ð"Ñ"ð ð  ð  ð  ð  ð  rD   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, WrapSerializer

    class EventDatetime(BaseModel):
        start: datetime
        end: datetime

    def convert_to_utc(value: Any, handler, info) -> dict[str, datetime]:
        # Note that `handler` can actually help serialize the `value` for
        # further custom serialization in case it's a subclass.
        partial_result = handler(value, info)
        if info.mode == 'json':
            return {
                k: datetime.fromisoformat(v).astimezone(timezone.utc)
                for k, v in partial_result.items()
            }
        return {k: v.astimezone(timezone.utc) for k, v in partial_result.items()}

    UTCEventDatetime = Annotated[EventDatetime, WrapSerializer(convert_to_utc)]

    class EventModel(BaseModel):
        event_datetime: UTCEventDatetime

    dt = EventDatetime(
        start='2024-01-01T07:00:00-08:00', end='2024-01-03T20:00:00+06:00'
    )
    event = EventModel(event_datetime=dt)
    print(event.model_dump())
    '''
    {
        'event_datetime': {
            'start': datetime.datetime(
                2024, 1, 1, 15, 0, tzinfo=datetime.timezone.utc
            ),
            'end': datetime.datetime(
                2024, 1, 3, 14, 0, tzinfo=datetime.timezone.utc
            ),
        }
    }
    '''

    print(event.model_dump_json())
    '''
    {"event_datetime":{"start":"2024-01-01T15:00:00Z","end":"2024-01-03T14: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#   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   r.   r/   r0   r   r1   r2   r   Ú#wrap_serializer_function_ser_schemar4   r   r5   s          r9   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=   rC   rD   r9   rF   rF   Y   se   € € € € € € ð<ð <ð| -Ð,Ð,Ñ,Ø(€KÐ(Ð(Ð(Ñ(Ø"€IÐ"Ð"Ð"Ñ"ð ð  ð  ð  ð  ð  rD   rF   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   rQ   úbool | Noner"   ú8Callable[[_FieldWrapSerializerT], _FieldWrapSerializerT]c              ó   — d S ©NrC   ©rR   rU   r   r   rQ   rT   s         r9   Úfield_serializerr\   Ð   s   € ð @C¸srD   )rU   r   r   rQ   úLiteral['plain']ú:Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT]c              ó   — d S rZ   rC   r[   s         r9   r\   r\   Ü   s   € ð BEÀrD   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 rZ   )Ú
isinstancerS   )Ú.0rR   s     r9   ú	<genexpr>z#field_serializer.<locals>.<genexpr>*  s,   è è € Ð:Ð:¨%�z˜%¥Ñ%Ô%Ð:Ð:Ð:Ð:Ð:Ð:rD   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ÚfrM   r"   ú(_decorators.PydanticDescriptorProxy[Any]c                ó`   •— t          j        ‰‰‰‰‰¬¦  «        }t          j        | |¦  «        S )N)rT   rU   r   r   rQ   )r   ÚFieldSerializerDecoratorInfoÚPydanticDescriptorProxy)rh   Údec_inforQ   rT   rU   r   r   s     €€€€€r9   Údeczfield_serializer.<locals>.dec1  s>   ø€ ÝÔ;ØØØ#ØØ%ð
ñ 
ô 
ˆõ Ô2°1°hÑ?Ô?Ð?rD   )rh   rM   r"   ri   )Úcallablere   Úclassmethodr   Úall)rR   rU   r   r   rQ   rT   rn   s    ````` r9   r\   r\   è   sÚ   øøøøø€ õt ��„ð 
�* U­KÑ8Ô8ð 
ÝðEà.ð
ñ 
ô 
ð 	
ð ˆ^�Vˆ^ˆ^€FÝÐ:Ð:°6Ð:Ñ:Ô:Ñ:Ô:ð 
ÝðYà+ð
ñ 
ô 
ð 	
ð@ð @ð @ð @ð @ð @ð @ð @ð @ð @ð €JrD   ÚModelPlainSerializerWithInfoÚModelPlainSerializerWithoutInfoz>ModelPlainSerializerWithInfo | ModelPlainSerializerWithoutInfoÚModelPlainSerializerÚModelWrapSerializerWithInfoÚModelWrapSerializerWithoutInfoz<ModelWrapSerializerWithInfo | ModelWrapSerializerWithoutInfoÚModelWrapSerializerz*ModelPlainSerializer | ModelWrapSerializerÚModelSerializerÚ_ModelPlainSerializerTÚ_ModelWrapSerializerTrh   c               ó   — d S rZ   rC   )rh   s    r9   Úmodel_serializerr|   Y  s   € ØNQÈcrD   )r   r   ú8Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT]c                ó   — d S rZ   rC   ©rU   r   r   s      r9   r|   r|   ]  s   € ð @C¸srD   r   ú:Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]c                ó   — d S rZ   rC   r   s      r9   r|   r|   c  s   € ð BEÀrD   ú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.
    rh   rx   r"   ri   c                ó\   •— t          j        ‰‰‰¬¦  «        }t          j        | |¦  «        S )N)rU   r   r   )r   ÚModelSerializerDecoratorInforl   )rh   rm   rU   r   r   s     €€€r9   rn   zmodel_serializer.<locals>.dec¬  s/   ø€ ÝÔ;ÀÐS^ÐjsÐtÑtÔtˆÝÔ2°1°hÑ?Ô?Ð?rD   N)rh   rx   r"   ri   rC   )rh   rU   r   r   rn   s    ``` r9   r|   r|   l  sO   øøø€ ð@@ð @ð @ð @ð @ð @ð @ð @ð 	€yØˆ
àˆs�1‰vŒvˆrD   ÚAnyTypec                  ó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 rZ   )r   r‰   )ÚclsrŠ   s     r9   Ú__class_getitem__z SerializeAsAny.__class_getitem__È  s   € Ý˜T¥>Ñ#3Ô#3Ð3Ô4Ð4rD   r    r!   r   r#   c                ó¶   —  ||¦  «        }|}|d         dk    r(|                      ¦   «         }|d         }|d         dk    °(t          j        d¦  «        |d<   |S )NÚtypeÚdefinitionsr7   Úanyr,   )Úcopyr   Úsimple_ser_schema)r6   r    r!   r7   Úschema_to_updates        r9   r:   z+SerializeAsAny.__get_pydantic_core_schema__Ë  su   € ð �W˜[Ñ)Ô)ˆFØ%ÐØ" 6Ô*¨mÒ;Ð;Ø#3×#8Ò#8Ñ#:Ô#:Ð Ø#3°HÔ#=Ð ð # 6Ô*¨mÒ;Ð;õ 1<Ô0MÈeÑ0TÔ0TÐ˜_Ñ-ØˆMrD   N)rŠ   r   r"   r   r<   )r>   r?   r@   rA   r�   r:   ÚobjectÚ__hash__rC   rD   r9   r‰   r‰   Á  sI   € € € € € ð	ð 	ð
	5ð 	5ð 	5ð 	5ð		ð 		ð 		ð 		ð ”?ˆˆˆrD   r‰   rC   )rR   rS   rT   rS   rU   rV   r   r   r   r   rQ   rW   r"   rX   )rR   rS   rT   rS   rU   r]   r   r   r   r   rQ   rW   r"   r^   )rR   rS   rT   rS   rU   r`   r   r   r   r   rQ   rW   r"   ra   )rh   ry   r"   ry   )rU   rV   r   r   r   r   r"   r}   )rU   r]   r   r   r   r   r"   r€   rZ   )
rh   r‚   rU   r`   r   r   r   r   r"   rƒ   )9rA   Ú
__future__r   ÚdataclassesÚ	functoolsr   r   Útypingr   r   r   r	   r
   r   r   Úpydantic_corer   r   Úpydantic_core.core_schemar   r   r   Útyping_extensionsr   Ú r   Ú	_internalr   r   Úannotated_handlersr   Úerrorsr   Ú	dataclassÚ
slots_truer   rF   rJ   rB   rK   rL   rM   rN   rP   r\   rr   rs   rt   ru   rv   rw   rx   ry   rz   r|   r‡   r‰   rC   rD   r9   ú<module>r¤      sk  ðØ KÐ KÐ Kà "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ VÐ Và 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ð `Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à )Ð )Ð )Ð )Ð )Ð )Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø %Ð %Ð %Ð %Ð %Ð %ð €ÔÐEÐEÐ,Ô7ÐEÐEÀÐEÐEÐEðBð Bð Bð Bð Bñ Bô Bñ FÔEðBðJ €ÔÐEÐEÐ,Ô7ÐEÐEÀÐEÐEÐEðcð cð cð cð cñ cô cñ FÔEðcðL ð 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ð &-à(Ø"Ø $ðSð Sð Sð Sð Sð Sðl ð 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<ÐQTðCð Cð Cð Cð Cñ 
„ðCð
 
ð !Ø"Øð	Eð Eð Eð Eð Eñ 
„ðEð @DðGð &-Ø"Ø(ðGð Gð Gð Gð Gð GðT ˆ'�)Ñ
Ô
€ð ð #Ø˜w¨˜|Ô,€Nðð ð €[ÔÐ<Ð<Ð0Ô;Ð<Ð<ð#ð #ð #ð #ð #ñ #ô #ñ =Ô<ð#ð #ð #rD   