Ë
    oPê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jD                  dd¬«       G d„ d«      «       Z# ejD                  dd¬«       G d„ d«      «       Z$e
r3d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"œ	 	 	 	 	 	 	 	 	 	 	 	 	 d?d#„«       Z,ed!d!d!d!d$œ	 	 	 	 	 	 	 	 	 	 	 	 	 d@d%„«       Z,d&ed'dd$œ	 	 	 	 	 	 	 	 	 	 	 	 	 dAd(„Z,e
rme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&d0<   	 d1Z3de&d2<    ed3e/¬«      Z4 ed4e2¬«      Z5edBd5„«       Z6ed'd!d6œ	 	 	 	 	 	 	 dCd7„«       Z6ed!d'd!d8œ	 	 	 	 	 	 	 dDd9„«       Z6	 dEd&d'ed8œ	 	 	 	 	 	 	 	 	 dFd:„Z6 ed;«      Z7e
ree7d!f   Z8y ejD                  d¬<«       G d=„ d>«      «       Z8y)GzEThis 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                  ó@   — 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.

    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_usedc                óè  —  ||«      }| j                   t        ur| j                   }n:	 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)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!   ©ÚselfÚsource_typeÚhandlerÚschemar   Úer)   s          úd/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/pydantic/functional_serializers.pyÚ__get_pydantic_core_schema__z,PlainSerializer.__get_pydantic_core_schema__7   sÞ   € ñ ˜Ó%ˆØ×ÑÔ#4Ñ4Ø×*Ñ*‰Kð	Lô *×BÑBØ—I‘IØ#×8Ñ8Ó:×AÑAô�ð !,Ô/@Ñ @™Àg×F]ÑF]Ð^iÓFjˆÜ"-×"RÑ"RØ—Y‘YÜ ×=Ñ=¸d¿i¹iÈÓQØ'Ø—n‘nô	#
ˆˆÑð ˆøô ò LÜ1×AÑAÀ!ÓDÈ!ÐKûðLúó   ©9C Ã	C1ÃC,Ã,C1N©r5   r	   r6   r   Úreturnzcore_schema.CoreSchema©	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   r!   r:   © ó    r9   r   r      s(   … ñð: )Ó(Ø!2€K�Ó2Ø"€IˆxÓ"ô rE   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
)Ú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!   c                óè  —  ||«      }| j                   t        ur| j                   }n:	 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)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-   r.   r   r/   r0   r   Ú#wrap_serializer_function_ser_schemar2   r!   r3   s          r9   r:   z+WrapSerializer.__get_pydantic_core_schema__•   sÞ   € ñ ˜Ó%ˆØ×ÑÔ#4Ñ4Ø×*Ñ*‰Kð	Lô *×BÑBØ—I‘IØ#×8Ñ8Ó:×AÑAô�ð !,Ô/@Ñ @™Àg×F]ÑF]Ð^iÓFjˆÜ"-×"QÑ"QØ—Y‘YÜ ×=Ñ=¸d¿i¹iÈÓPØ'Ø—n‘nô	#
ˆˆÑð ˆøô ò LÜ1×AÑAÀ!ÓDÈ!ÐKûðLúr;   Nr<   r>   rD   rE   r9   rG   rG   Z   s)   … ñ3ðj -Ó,Ø!2€K�Ó2Ø"€IˆxÓ"ô rE   rG   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_fieldsc               ó   — y ©NrD   ©ÚfieldÚmoder   r!   rR   Úfieldss         r9   Úfield_serializerrY   È   s	   € ð @CrE   )rW   r   r!   rR   c               ó   — y rT   rD   rU   s         r9   rY   rY   Ô   s	   € ð BErE   r%   r    c              ó¾   ‡‡‡‡‡— t        | «      st        | t        «      rt        dd¬«      ‚| g‰¢­Š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        «      –— Œ y ­wrT   )Ú
isinstanceÚstr)Ú.0rV   s     r9   ú	<genexpr>z#field_serializer.<locals>.<genexpr>!  s   è ø€ Ò:¨%Œz˜%¤×%Ñ:ùs   ‚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-fieldsc                ód   •— t        j                  ‰‰‰‰‰¬«      }t        j                  | |«      S )N)rX   rW   r   r!   rR   )r   ÚFieldSerializerDecoratorInfoÚPydanticDescriptorProxy)ÚfÚdec_inforR   rX   rW   r   r!   s     €€€€€r9   Údeczfield_serializer.<locals>.dec(  s7   ø€ Ü×;Ñ;ØØØ#ØØ%ô
ˆô ×2Ñ2°1°hÓ?Ð?rE   )re   rN   r=   ú(_decorators.PydanticDescriptorProxy[Any])Úcallabler^   Úclassmethodr   Úall)rV   rW   r   r!   rR   rX   rg   s    ````` r9   rY   rY   à   sp   ü€ ôr �„œ* U¬KÔ8ÜðEà.ô
ð 	
ð ˆ^�V‰^€FÜÑ:°6Ô:Ô:ÜðYà+ô
ð 	
÷@ñ @ð €JrE   ÚModelPlainSerializerWithInfoÚModelPlainSerializerWithoutInfoz>ModelPlainSerializerWithInfo | ModelPlainSerializerWithoutInfoÚModelPlainSerializerÚModelWrapSerializerWithInfoÚModelWrapSerializerWithoutInfoz<ModelWrapSerializerWithInfo | ModelWrapSerializerWithoutInfoÚModelWrapSerializerz*ModelPlainSerializer | ModelWrapSerializerÚModelSerializerÚ_ModelPlainSerializerTÚ_ModelWrapSerializerTc                ó   — y rT   rD   )re   s    r9   Úmodel_serializerrv   P  s   € ØNQrE   )r!   r   c                 ó   — y rT   rD   ©rW   r!   r   s      r9   rv   rv   T  s	   € ð @CrE   rx   c                 ó   — y rT   rD   rx   s      r9   rv   rv   Z  s	   € ð BErE   c              ó0   ‡‡‡— 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.
    c                ó`   •— t        j                  ‰‰‰¬«      }t        j                  | |«      S )N)rW   r   r!   )r   ÚModelSerializerDecoratorInford   )re   rf   rW   r   r!   s     €€€r9   rg   zmodel_serializer.<locals>.dec£  s,   ø€ Ü×;Ñ;ÀÐS^ÐjsÔtˆÜ×2Ñ2°1°hÓ?Ð?rE   )re   rr   r=   rh   rD   )re   rW   r!   r   rg   s    ``` r9   rv   rv   c  s   ú€ ÷@@ð 	€yØˆ
á�1‹vˆrE   ÚAnyType)r   c                  óD   — e Zd ZdZdd„Z	 	 	 	 	 	 dd„Zej                  Zy)Ú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.
        c                ó(   — t         |t        «       f   S rT   )r   r   )ÚclsÚitems     r9   Ú__class_getitem__z SerializeAsAny.__class_getitem__¿  s   € Ü˜T¤>Ó#3Ð3Ñ4Ð4rE   c                ó–   —  ||«      }|}|d   dk(  r|j                  «       }|d   }|d   dk(  rŒt        j                  d«      |d<   |S )NÚtypeÚdefinitionsr7   Úanyr*   )Úcopyr   Úsimple_ser_schema)r4   r5   r6   r7   Úschema_to_updates        r9   r:   z+SerializeAsAny.__get_pydantic_core_schema__Â  sg   € ñ ˜[Ó)ˆFØ%ÐØ" 6Ñ*¨mÒ;Ø#3×#8Ñ#8Ó#:Ð Ø#3°HÑ#=Ð ð # 6Ñ*¨mÓ;ô 1<×0MÑ0MÈeÓ0TÐ˜_Ñ-ØˆMrE   N)r‚   r	   r=   r	   r<   )r?   r@   rA   rB   rƒ   r:   ÚobjectÚ__hash__rD   rE   r9   r   r   ¸  s4   „ ñ	ó
	5ð		Ø"ð		Ø-Að		à#ó		ð —?‘?‰rE   r   )rV   r_   rX   r_   rW   úLiteral['wrap']r   r   r!   r   rR   úbool | Noner=   z8Callable[[_FieldWrapSerializerT], _FieldWrapSerializerT])rV   r_   rX   r_   rW   úLiteral['plain']r   r   r!   r   rR   rŽ   r=   z:Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT])rV   r_   rX   r_   rW   úLiteral['plain', 'wrap']r   r   r!   r   rR   rŽ   r=   zuCallable[[_FieldWrapSerializerT], _FieldWrapSerializerT] | Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT])re   rs   r=   rs   )rW   r�   r!   r   r   r   r=   z8Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT])rW   r�   r!   r   r   r   r=   z:Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]rT   )
re   z5_ModelPlainSerializerT | _ModelWrapSerializerT | NonerW   r�   r!   r   r   r   r=   zŽ_ModelPlainSerializerT | Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT] | Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT])9rB   Ú
__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   rG   rK   rC   rL   rM   rN   rO   rQ   rY   rl   rm   rn   ro   rp   rq   rr   rs   rt   rv   r}   r   rD   rE   r9   ú<module>rž      s*  ðÚ Kå "ã Ý $ß ,ß W× WÑ Wç 8ß `Ñ `Ý &å )Ý "Ý 4Ý %ð €×Ñ˜T¨$Ô/÷Bð Bó 0ðBðJ €×Ñ˜T¨$Ô/÷Zð Zó 0ðZñz Ø=€HˆiÓ=à&QÐ˜)ÓQØ@à%TÐ˜ÓTØ?à!M€O�YÓMØ0á$Ð%=ÐEYÔZÐÙ#Ð$;ÐCVÔWÐð 
ð "%ØØ #ñCØðCð ðCð ð	Cð
 ðCð ðCð ðCð >òCó 
ðCð 
ð
 !Ø!$ØØ #ñEØðEð ðEð ð	Eð
 ðEð ðEð ðEð @òEó 
ðEð &-Ø!2Ø"Ø $ñRØðRð ðRð #ð	Rð
 ðRð ðRð ðRðAóRñj ð /7¸Ð=NÈsÑ=SÐ7TÐVYÐ7YÑ.ZÐ  )ÓZØNà19¸3¸%À¸*Ñ1EÐ# YÓEØQà&fÐ˜)ÓfØ4à-5°sÐ<YÐ[lÐmpÑ[qÐ6rÐtwÐ6wÑ-xÐ ÓxØMà08¸#Ð?\Ð9]Ð_bÐ9bÑ0cÐ" IÓcØPà%cÐ˜ÓcØ3à!M€O�YÓMá$Ð%=ÐEYÔZÐÙ#Ð$;ÐCVÔWÐð 
Ú Qó 
Ø Qð 
à4<Ð[^ñCØðCØ)1ðCØKXðCà=òCó 
ðCð
 
ð !Ø"Ø!$ñ	Eà
ðEð ðEð ð	Eð
 @òEó 
ðEð @DðGð &-Ø"Ø!2ñGØ<ðGð #ð	Gð
 ðGð ðGðAóGñT �)Ó
€ñ Ø˜w¨˜|Ñ,€Nðð €[×Ñ Ô&÷#ð #ó 'ñ#rE   