
    hB                    V   % S r SSKJr  SSKrSSKJrJr  SSKJrJ	r	J
r
JrJrJrJr  SSKJrJr  SSKJrJrJr  SSKJr  S	S
KJr  S	SKJrJr  S	SKJr  \R>                  " S<0 \R@                  DSS0D6 " S S5      5       r!\R>                  " S<0 \R@                  DSS0D6 " S S5      5       r"\(       a-  Sr#S\$S'   Sr%S\$S'    Sr&S\$S'    Sr'S\$S'    \" S\%S9r(\" S\&S9r)\SSSS .             S=S! jj5       r*\SSSSS".             S>S# jj5       r*S$\S%SS".           S?S& jjr*\(       aa  \\
\/\
4   r+S\$S''    \\
/\
4   r,S\$S('    S)r-S\$S*'    \\
\\/\
4   r.S\$S+'    \\
\/\
4   r/S\$S,'    S-r0S\$S.'    S/r1S\$S0'   \" S1\-S9r2\" S2\0S9r3\S@S3 j5       r4\S%SS4.       SAS5 jj5       r4\SS%SS6.       SBS7 jj5       r4 SCS$S%\S6.         SDS8 jjjr4\" S95      r5\(       a  \	\5S4   r6g\R>                  " S<0 \R@                  D6 " S: S;5      5       r6g)EzEThis 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frozenTc                  J    \ rS rSr% SrS\S'   \rS\S'   SrS\S	'   SS
 jr	Sr
g)PlainSerializer   a  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_usedc                   U" U5      nU R                   [        La  U R                   nO8 [        R                  " U R                  UR                  5       R                  S9nU[        L a  SOUR                  U5      n[        R                  " U R                  [        R                  " U R                  S5      UU R                  S9US'   U$ ! [         a  n[        R                  " U5      UeSnAff = f)zGets 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          Q/var/www/html/env/lib/python3.13/site-packages/pydantic/functional_serializers.py__get_pydantic_core_schema__,PlainSerializer.__get_pydantic_core_schema__5   s     %#44**K	L *BBII#88:AA !,/@ @gF]F]^iFj"-"R"RYY ==diiQ'nn	#
   L1AA!D!KL   7C 
C2C--C2 Nr3   r   r4   r   returnzcore_schema.CoreSchema__name__
__module____qualname____firstlineno____doc____annotations__r   r   r   r8   __static_attributes__r;       r7   r   r      s(    : )((K("Ix" rF   r   c                  J    \ rS rSr% SrS\S'   \rS\S'   SrS\S	'   SS
 jr	Sr
g)WrapSerializerX   a*  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   c                   U" U5      nU R                   [        La  U R                   nO8 [        R                  " U R                  UR                  5       R                  S9nU[        L a  SOUR                  U5      n[        R                  " U R                  [        R                  " U R                  S5      UU R                  S9US'   U$ ! [         a  n[        R                  " U5      UeSnAff = f)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.
r!   Nwrapr$   r(   )r   r   r   r)   r   r*   r+   r,   r   r-   r.   r   #wrap_serializer_function_ser_schemar0   r   r1   s          r7   r8   +WrapSerializer.__get_pydantic_core_schema__   s     %#44**K	L *BBII#88:AA !,/@ @gF]F]^iFj"-"Q"QYY ==diiP'nn	#
   L1AA!D!KLr:   r;   Nr<   r>   r;   rF   r7   rH   rH   X   s)    <| -,(K("Ix" 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_fieldsc                  g Nr;   fieldmoder   r   rU   fieldss         r7   field_serializerr\      s	     @CrF   )rZ   r   r   rU   c                  g rW   r;   rX   s         r7   r\   r\      s	     BErF   r#   r   c                (   ^ ^^^^ SUUU UU4S jjnU$ )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(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 [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                `   > [         R                  " TTTTTS9n[         R                  " X5      $ )N)r[   rZ   r   r   rU   )r   FieldSerializerDecoratorInfoPydanticDescriptorProxy)fdec_inforU   r[   rZ   r   r   s     r7   decfield_serializer.<locals>.dec  s5    ;;#%
 221??rF   )rb   rQ   r=   (_decorators.PydanticDescriptorProxy[Any]r;   )rZ   r   r   rU   r[   rd   s   ````` r7   r\   r\      s    p@ @ JrF   ModelPlainSerializerWithInfoModelPlainSerializerWithoutInfoz>ModelPlainSerializerWithInfo | ModelPlainSerializerWithoutInfoModelPlainSerializerModelWrapSerializerWithInfoModelWrapSerializerWithoutInfoz<ModelWrapSerializerWithInfo | ModelWrapSerializerWithoutInfoModelWrapSerializerz*ModelPlainSerializer | ModelWrapSerializerModelSerializer_ModelPlainSerializerT_ModelWrapSerializerTc                   g rW   r;   )rb   s    r7   model_serializerrq   G  s    NQrF   )r   r   c                    g rW   r;   rZ   r   r   s      r7   rq   rq   K  s	     @CrF   rs   c                    g rW   r;   rs   s      r7   rq   rq   Q  s	     BErF   c              6   ^^^ SUUU4S jjnU c  U$ U" U 5      $ )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 [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                \   > [         R                  " TTTS9n[         R                  " X5      $ )N)rZ   r   r   )r   ModelSerializerDecoratorInfora   )rb   rc   rZ   r   r   s     r7   rd   model_serializer.<locals>.dec  s*    ;;S^jst221??rF   )rb   rm   r=   rf   r;   )rb   rZ   r   r   rd   s    ``` r7   rq   rq   Z  s%    @@ @ 	y
1vrF   AnyTypec                  L    \ rS rSrSS jr      SS jr\R                  rSrg)SerializeAsAnyi  c                (    [         U[        5       4   $ rW   )r   r{   )clsitems     r7   __class_getitem__ SerializeAsAny.__class_getitem__  s    T>#3344rF   c                    U" U5      nUnUS   S:X  a   UR                  5       nUS   nUS   S:X  a  M   [        R                  " S [        R                  " 5       S9US'   U$ )Ntypedefinitionsr5   c                    U" U 5      $ rW   r;   )xhs     r7   <lambda>=SerializeAsAny.__get_pydantic_core_schema__.<locals>.<lambda>  s    QqTrF   )r5   r(   )copyr   rL   
any_schema)r2   r3   r4   r5   schema_to_updates        r7   r8   +SerializeAsAny.__get_pydantic_core_schema__  sw     [)F%"6*m;#3#8#8#: #3H#=  #6*m; 1<0_0_!+*@*@*B1_- MrF   r;   N)r~   r   r=   r   r<   )	r?   r@   rA   rB   r   r8   object__hash__rE   r;   rF   r7   r{   r{     s/    	5	"	-A	#	 ??rF   r{   r;   )rY   strr[   r   rZ   Literal['wrap']r   r   r   r   rU   bool | Noner=   z8Callable[[_FieldWrapSerializerT], _FieldWrapSerializerT])rY   r   r[   r   rZ   Literal['plain']r   r   r   r   rU   r   r=   z:Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT])r[   r   rZ   Literal['plain', 'wrap']r   r   r   r   rU   r   r=   zuCallable[[_FieldWrapSerializerT], _FieldWrapSerializerT] | Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT])rb   rn   r=   rn   )rZ   r   r   r   r   r   r=   z8Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT])rZ   r   r   r   r   r   r=   z:Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]rW   )
rb   z5_ModelPlainSerializerT | _ModelWrapSerializerT | NonerZ   r   r   r   r   r   r=   z_ModelPlainSerializerT | Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT] | Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT])7rC   
__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   	dataclass
slots_truer   rH   rN   rD   rO   rP   rQ   rR   rT   r\   rg   rh   ri   rj   rk   rl   rm   rn   ro   rq   ry   r{   r;   rF   r7   <module>r      s,   K "  , V V V 8 ` ` ' ) 7 4 E,77EEB B FBJ E,77EEc c FcL =Hi=&Q)Q@%TT?!MOYM0$%=EYZ#$;CVW 
  #CC C 	C
 C C C >C 
C 

 ! #EE E 	E
 E E E @E 
E &-(" $BB
"B B 	B
 BABJ  /7=N7OQT7T.U )UN193%*1E#YEQ&f)f4-5s<Y[l6mor6r-ssM08#?\9]_b9b0c"IcP%cc3!MOYM$%=EYZ#$;CVW 
 Q 
 Q 
4<QTCC)1CKNC=C 
C
 
 !"	E
E E 	E
 @E 
E @DG &-"(G<G #	G
 G GAGT )
 w|,N <0;;<# # =#rF   