Ë
    ñEj+9  ã                  ó¼  — 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
)ÚPlainSerializeraC  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 List

    from typing_extensions 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Ú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)zÒGets 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          úb/var/www/html/peoplehubportal/venv/lib/python3.12/site-packages/pydantic/functional_serializers.pyÚ__get_pydantic_core_schema__z,PlainSerializer.__get_pydantic_core_schema__6   sÃ   € ñ ˜Ó%ˆð	HÜ%×>Ñ>Ø—	‘	˜4×+Ñ+¨W×-IÑ-IÓ-KóˆKð
 !,Ô/@Ñ @™Àg×F]ÑF]Ð^iÓFjˆÜ"-×"RÑ"RØ—Y‘YÜ ×=Ñ=¸d¿i¹iÈÓQØ'Ø—n‘nô	#
ˆˆÑð ˆøô ò 	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�Ó(ØNV€IÐ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
)Ú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 Any, Dict

    from typing_extensions import Annotated

    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 `helper` 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   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)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.
        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__–   sÃ   € ñ ˜Ó%ˆð	HÜ%×>Ñ>Ø—	‘	˜4×+Ñ+¨W×-IÑ-IÓ-KóˆKð
 !,Ô/@Ñ @™Àg×F]ÑF]Ð^iÓFjˆÜ"-×"QÑ"QØ—Y‘YÜ ×=Ñ=¸d¿i¹iÈÓPØ'Ø—n‘nô	#
ˆˆÑð ˆøô ò 	HÜ-×=Ñ=¸aÓ@ÀaÐGûð	Húr3   Nr4   r6   r<   r=   r1   r?   r?   Q   s*   … ñ=ð~ -Ó,Ø(€K�Ó(ØNV€IÐKÓVôr=   r?   r   Ú_PartialClsOrStaticMethodÚ_PlainSerializeMethodType)ÚboundÚ_WrapSerializeMethodType.)r   r   Úcheck_fieldsc               ó   — y ©Nr<   )Úfieldr   r   rG   Úfieldss        r1   Úfield_serializerrL   ¹   s   € ð r=   c               ó   — y rI   r<   ©rJ   Úmoder   r   rG   rK   s         r1   rL   rL   Å   ó   € ð 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.

    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 typing import Set

    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(courses: Set[str]):
            return sorted(courses)

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

    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Ñ2°1°hÓ?Ð?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)   ü€ ðj
@Ø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.

    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}
    ```

    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>.decg  s,   ø€ Ü×;Ñ;ÀÐS^ÐjsÔtˆÜ×2Ñ2°1°hÓ?Ð?r=   )rV   zCallable[..., Any]r5   rY   r<   )rV   rO   r   r   rX   s    ``` r1   r]   r]   5  s   ú€ ÷d@ð 	€yØˆ
á�1‹vˆ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
   € ™Q˜q›T€ 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Ó#:Ð Ø#3°HÑ#=Ð ð # 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   )
rV   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ð<ð~ €×ÑÑEÐ,×7Ñ7ÑEÀÒE÷\ð \ó Fð\ñ~ Ø+0°¸SÀ#Às¸]Ñ1KÈ\ÐZ]Ð_bÐZbÑMcÐerÐsvÑewÐ1wÑ+xÐ˜yÓxØ"'¨×(GÑ(GÐIbÐ(bÑ"cÐØ!& |×'JÑ'JÐLeÐ'eÑ!fÐÙ 'Ð(CÐKfÔ gÐÙ&Ð'AÐIcÔdÐð 
ð
 ØNQØ #ñØðð ðð ð	ð
 Lðð ðð Fòó 
ðð 
ð ØNQØ #ñ	Øð	ð ð	ð ð		ð
 ð	ð Lð	ð ð	ð Fò	ó 
ð	ð 
ð ØNQØ #ñ	Øð	ð ð	ð ð		ð
 ð	ð Lð	ð ð	ð Dò	ó 
ð	ð &-Ø(ØNVØ $ñAØðAà
"ðAð ðAð Lð	Að
 ðAð óAñH �: X¨c°3¨hÑ%7Ô8€ð 
òó 
ðð 
ð &)ØNVØñ	à
"ðð Lðð ð	ð
 $òó 
ðð $(ð9ð &-ØNVØ(ñ9Ø ð9ð #ð	9ð
 Lð9ð ð9ð ó9ñx �)Ó
€ñ Ø˜w¨˜|Ñ,€Nðð €[×ÑÑ<Ð0×;Ñ;Ñ<÷#ð #ó =ñ#r=   