+
    7*iB  c            	      sp  a  0 t $ R t^ RIHt ^ RIt^ RIHtHt ^ RIH	t	H
t
HtHtHtHtHt ^ RIHtHt ^ RIHtHtHt ^ RIHt ^RIHt ^R	IHtHt ^R
IHt ]P@                  ! RA/ ]PB                  BRR/B  ! R R4      4       t"]P@                  ! RA/ ]PB                  BRR/B  ! R R4      4       t#]	'       d4   Rt$R]%R&   Rt&R]%R&    Rt'R]%R&    Rt(R]%R&    ]! R]&R7      t)]! R]'R7      t*]RRRRR R/R! R" ll4       t+]R#RRRRRR R/R$ R% ll4       t+R#R&R]RR'R R/R( R) llt+]	'       d   ]]]],          .]3,          t,R]%R*&    ]].]3,          t-R]%R+&    R,t.R]%R-&    ]]]]],          .]3,          t/R]%R.&    ]]].]3,          t0R]%R/&    R0t1R]%R1&    R2t2R]%R3&   ]! R4].R7      t3]! R5]1R7      t4]R6 R7 l4       t5]RR'RR/R8 R9 ll4       t5]R#RRR'RR/R: R; ll4       t5RBR#R&RR'R]/R< R= lllt5]! R>4      t6]	'       d   ]
]6R3,          t7R# ]P@                  ! RA/ ]PB                  B  ! R? R@4      4       t7R# )CzEThis 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)GetCoreSchemaHandlerZfrozenTc                  sN    ] tR t^t$ RtR]R&   ]tR]R&   RtR]R&   R	 R
 lt	Rt
R# )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_usedc               $    V ^8  d   QhRRRRRR/#    source_typer   handlerr   returnzcore_schema.CoreSchema Zformat   "D/usr/lib/python3.14/site-packages/pydantic/functional_serializers.py__annotate__ZPlainSerializer.__annotate__5   #          FZ  _u      c                   V! V4      pV P                   \        Jd   V P                   pM; \        P                  ! V P                  VP                  4       P                  R7      pV\        J d   RMVP                  V4      p\        P                  ! V P                  \        P                  ! V P                  R4      VV P                  R7      VR&   V#   \         d   p\        P                  ! T4      ThRp?ii ; i)zGets the Pydantic core schema.

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

Returns:
    The Pydantic core schema.
ZlocalnsNplainZfunctionZinfo_argreturn_schemar   serialization)r   r
   r   get_callable_return_typer   _get_types_namespacelocals	NameErrorr   from_name_errorgenerate_schemar   Z$plain_serializer_function_ser_schemainspect_annotated_serializerr   selfr   r   schemar   Zer*      &&&    r"   __get_pydantic_core_schema__Z,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   :C C;C66C;r   N__name__
__module____qualname____firstlineno____doc____annotations__r
   r   r   r7   __static_attributes__r   r%   r"   r   r      s-    : )((K("Ix"   r%   r   c                  sN    ] tR t^Xt$ RtR]R&   ]tR]R&   RtR]R&   R	 R
 lt	Rt
R# )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   c               r   r   r   r    r!   r"   r#   ZWrapSerializer.__annotate__   r$   r%   c                r&   )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'   NZwrapr)   r+   )r   r
   r   r,   r   r-   r.   r/   r   r0   r1   r   Z#wrap_serializer_function_ser_schemar2   r   r3   r6   r"   r7   Z+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r8   r   Nr9   r   r%   r"   rA   rA   X   s.    <| -,(K("Ix"   r%   rA   z!partial[Any] | partialmethod[Any]r   _Partialz)core_schema.SerializerFunction | _PartialFieldPlainSerializerz-core_schema.WrapSerializerFunction | _PartialFieldWrapSerializerz*FieldPlainSerializer | FieldWrapSerializerFieldSerializer_FieldPlainSerializerT)Zbound_FieldWrapSerializerTr   .r   check_fieldsc               4    V ^8  d   QhRRRRRRRRRR	R
RRR/# )r   fieldstrfieldsmodeLiteral['wrap']r   r   r   r   rH   bool | Noner   z8Callable[[_FieldWrapSerializerT], _FieldWrapSerializerT]r   r    r!   r"   r#   r#      sY     C CC C 	C
 C C C >Cr%   c                  R # Nr   rJ   rM   r   r   rH   rL      "$$$$*r"   field_serializerrT      s	     @Cr%   rM   c               rI   )r   rJ   rK   rL   rM   Literal['plain']r   r   r   r   rH   rO   r   z:Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT]r   r    r!   r"   r#   r#      sZ     E EE E 	E
 E E E @Er%   c              rP   rQ   r   rR   rS   r"   rT   rT      s	     BEr%   r(   r   c               s0    V ^8  d   QhRRRRRRRRR	R
RR/# )r   rL   rK   rM   Literal['plain', 'wrap']r   r   r   r   rH   rO   r   zuCallable[[_FieldWrapSerializerT], _FieldWrapSerializerT] | Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT]r   r    r!   r"   r#   r#      sM     A AA
"A 	A
 A AAAr%   c                s*   a aaaa R VVV VV3R llpV# )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:

- `(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                    V ^8  d   QhRRRR/# )r   frE   r   (_decorators.PydanticDescriptorProxy[Any]r   r    r!   r"   r#   Z&field_serializer.<locals>.__annotate__  s     @ @ @#K @r%   c                sf   < \         P                  ! SSSSSR 7      p\         P                  ! W4      # ))rL   rM   r   r   rH   )r   ZFieldSerializerDecoratorInfoPydanticDescriptorProxy)rX   dec_inforH   rL   rM   r   r   s   & r"   decZfield_serializer.<locals>.dec  s5    ;;#%
 221??r%   r   )rM   r   r   rH   rL   r\   s   ddddj r"   rT   rT      s    n@ @ Jr%   ModelPlainSerializerWithInfoModelPlainSerializerWithoutInfoz>ModelPlainSerializerWithInfo | ModelPlainSerializerWithoutInfoModelPlainSerializerModelWrapSerializerWithInfoModelWrapSerializerWithoutInfoz<ModelWrapSerializerWithInfo | ModelWrapSerializerWithoutInfoModelWrapSerializerz*ModelPlainSerializer | ModelWrapSerializerModelSerializer_ModelPlainSerializerT_ModelWrapSerializerTc                    V ^8  d   QhRRRR/# )r   rX   rd   r   r   r    r!   r"   r#   r#   G  s     Q Q. Q6L Qr%   c               rP   rQ   r   )rX   r!   r"   model_serializerrg   F  s    NQr%   c               (    V ^8  d   QhRRRRRRRR/# )	r   rM   rN   r   r   r   r   r   z8Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT]r   r    r!   r"   r#   r#   K  s2     C CC)1CKNC=Cr%   c                rP   rQ   r   rM   r   r      $$$r"   rg   rg   J  s	     @Cr%   c               rh   )	r   rM   rU   r   r   r   r   r   z:Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]r   r    r!   r"   r#   r#   Q  s9     E E
E E 	E
 @Er%   c                rP   rQ   r   ri   rj   r"   rg   rg   P  s	     BEr%   c          
     s,    V ^8  d   QhRRRRRRRRR	R
/# )r   rX   z5_ModelPlainSerializerT | _ModelWrapSerializerT | NonerM   rV   r   r   r   r   r   z_ModelPlainSerializerT | Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT] | Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]r   r    r!   r"   r#   r#   Y  sD     G G<G #	G
 G GAGr%   c              s:   aaa R VVV3R llpV f   V# V! V 4      # )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               rW   )r   rX   rc   r   rY   r   r    r!   r"   r#   Z&model_serializer.<locals>.__annotate__  s     @ @ @#K @r%   c                sb   < \         P                  ! SSSR 7      p\         P                  ! W4      # ))rM   r   r   )r   ZModelSerializerDecoratorInforZ   )rX   r[   rM   r   r   s   & r"   r\   Zmodel_serializer.<locals>.dec  s*    ;;S^jst221??r%   r   )rX   rM   r   r   r\   s   "ddd r"   rg   rg   Y  s%    @@ @ 	y
1vr%   AnyTypec                  sJ    ] tR tRtRtR R ltR R lt]P                  tRt	R# )	SerializeAsAnyi  zAnnotation 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               rf   )r   itemr   r   r   r    r!   r"   r#   SerializeAsAny.__annotate__  s     	5 	5 	5 	5r%   c                	s0    \         V\        4       3,          # rQ   )r   rl   )Zclsrm   s   &&r"   __class_getitem__Z SerializeAsAny.__class_getitem__  s    T>#3344r%   c               r   r   r   r    r!   r"   r#   rn     s$     		 		"		-A		#		r%   c                	s    V! V4      pTpVR ,          R8X  d   VP                  4       pVR,          pK)  \        P                  ! R4      VR&   V# )ZtypeZdefinitionsr5   Zanyr+   )Zcopyr   Zsimple_ser_schema)r4   r   r   r5   Zschema_to_updates   &&&  r"   r7   Z+SerializeAsAny.__get_pydantic_core_schema__  sV     [)F%"6*m;#3#8#8#: #3H#= 0;0M0Me0T_-Mr%   r   N)
r:   r;   r<   r=   r>   ro   r7   ZobjectZ__hash__r@   r   r%   r"   rl   rl     s    	
	5		 ??r%   rl   r   rQ   )8__conditional_annotations__r>   Z
__future__r    ZdataclassesZ	functoolsr   r   Ztypingr   r   r   r   r   r   r	   Zpydantic_corer
   r   Zpydantic_core.core_schemar   r   r   Ztyping_extensionsr   Z r   Z	_internalr   r   Zannotated_handlersr   Z	dataclassZ
slots_truer   rA   rB   r?   rC   rD   rE   rF   rG   rT   r]   r^   r_   r`   ra   rb   rc   rd   re   rg   rk   rl   )rp   s   @r"   <module>rq      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 
E !	E
 E E !$E 
EA%,A )	A
 #A !%AH  /7=Ns=S7TVY7Y.Z )ZN193%*1E#YEQ&f)f4-5s<Y[lmp[q6rtw6w-xxM08#?\9]_b9b0c"IcP%cc3!MOYM$%=EYZ#$;CVW 
 Q 
 Q 
C4<CQTC 
C
 
E E #E 	E 
EG &-	G
 #G )G GT )
 w|,N <0;;<# # =#r%   