
    2iF                    r   % 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  S	SKJ r   \RB                  " S=0 \RD                  DSS0D6 " S S5      5       r#\RB                  " S=0 \RD                  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,\(       ag  \\
\\
   /\
4   r-S\&S('    \\
/\
4   r.S\&S)'    S*r/S\&S+'    \\
\\\
   /\
4   r0S\&S,'    \\
\/\
4   r1S\&S-'    S.r2S\&S/'    S0r3S\&S1'   \" S2\/S9r4\" S3\2S9r5\SAS4 j5       r6\S&S S5.       SBS6 jj5       r6\S S&S S7.       SCS8 jj5       r6 SDS%S&\S7.         SES9 jjjr6\" S:5      r7\(       a  \	\7S 4   r8g\RB                  " S=0 \RD                  D6 " S; S<5      5       r8g)FzEThis 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                  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          b/var/www/html/motor_solar_iot/venv/lib/python3.13/site-packages/pydantic/functional_serializers.py__get_pydantic_core_schema__,PlainSerializer.__get_pydantic_core_schema__6   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r4   r   r5   r   returnzcore_schema.CoreSchema__name__
__module____qualname____firstlineno____doc____annotations__r   r   r    r9   __static_attributes__r<       r8   r   r      s(    : )((K("Ix" rG   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)WrapSerializerY   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_schemar1   r    r2   s          r8   r9   +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<   rG   r8   rI   rI   Y   s)    <| -,(K("Ix" rG   rI   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    rV   fieldss         r8   field_serializerr]      s	     @CrG   )r[   r   r    rV   c                  g rX   r<   rY   s         r8   r]   r]      s	     BErG   r$   r   c                 ^^^^^ [        U 5      (       d  [        U [        5      (       a
  [        SSS9eU /TQ7m[	        S T 5       5      (       d
  [        SSS9eSUUUUU4S jjnU$ )	a5  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.
zThe `@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  B   #    U  H  n[        U[        5      v   M     g 7frX   )
isinstancestr).0rZ   s     r8   	<genexpr>#field_serializer.<locals>.<genexpr>*  s     :6%z%%%6s   zThe 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                `   > [         R                  " TTTTTS9n[         R                  " X5      $ )N)r\   r[   r   r    rV   )r   FieldSerializerDecoratorInfoPydanticDescriptorProxy)fdec_inforV   r\   r[   r   r    s     r8   decfield_serializer.<locals>.dec1  s5    ;;#%
 221??rG   )rj   rR   r>   (_decorators.PydanticDescriptorProxy[Any])callablerb   classmethodr   all)rZ   r[   r   r    rV   r\   rl   s    ````` r8   r]   r]      sx    t *UK88E.
 	
 ^V^F:6:::Y+
 	
@ @ JrG   ModelPlainSerializerWithInfoModelPlainSerializerWithoutInfoz>ModelPlainSerializerWithInfo | ModelPlainSerializerWithoutInfoModelPlainSerializerModelWrapSerializerWithInfoModelWrapSerializerWithoutInfoz<ModelWrapSerializerWithInfo | ModelWrapSerializerWithoutInfoModelWrapSerializerz*ModelPlainSerializer | ModelWrapSerializerModelSerializer_ModelPlainSerializerT_ModelWrapSerializerTc                   g rX   r<   )rj   s    r8   model_serializerr|   Y  s    NQrG   )r    r   c                    g rX   r<   r[   r    r   s      r8   r|   r|   ]  s	     @CrG   r~   c                    g rX   r<   r~   s      r8   r|   r|   c  s	     BErG   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 [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                \   > [         R                  " TTTS9n[         R                  " X5      $ )N)r[   r   r    )r   ModelSerializerDecoratorInfori   )rj   rk   r[   r   r    s     r8   rl   model_serializer.<locals>.dec  s*    ;;S^jst221??rG   )rj   rx   r>   rn   r<   )rj   r[   r    r   rl   s    ``` r8   r|   r|   l  s%    @@ @ 	y
1vrG   AnyTypec                  P    \ rS rSrSrSS jr      SS jr\R                  rSr	g)	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                (    [         U[        5       4   $ rX   )r   r   )clsitems     r8   __class_getitem__ SerializeAsAny.__class_getitem__  s    T>#3344rG   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5      US'   U$ )Ntypedefinitionsr6   anyr)   )copyr   simple_ser_schema)r3   r4   r5   r6   schema_to_updates        r8   r9   +SerializeAsAny.__get_pydantic_core_schema__  sg     [)F%"6*m;#3#8#8#: #3H#=  #6*m; 1<0M0Me0T_-MrG   r<   N)r   r   r>   r   r=   )
r@   rA   rB   rC   rD   r   r9   object__hash__rF   r<   rG   r8   r   r     s4    	
	5		"		-A		#		 ??rG   r   r<   )rZ   rc   r\   rc   r[   Literal['wrap']r   r   r    r   rV   bool | Noner>   z8Callable[[_FieldWrapSerializerT], _FieldWrapSerializerT])rZ   rc   r\   rc   r[   Literal['plain']r   r   r    r   rV   r   r>   z:Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT])rZ   rc   r\   rc   r[   Literal['plain', 'wrap']r   r   r    r   rV   r   r>   zuCallable[[_FieldWrapSerializerT], _FieldWrapSerializerT] | Callable[[_FieldPlainSerializerT], _FieldPlainSerializerT])rj   ry   r>   ry   )r[   r   r    r   r   r   r>   z8Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT])r[   r   r    r   r   r   r>   z:Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT]rX   )
rj   z5_ModelPlainSerializerT | _ModelWrapSerializerT | Noner[   r   r    r   r   r   r>   z_ModelPlainSerializerT | Callable[[_ModelWrapSerializerT], _ModelWrapSerializerT] | Callable[[_ModelPlainSerializerT], _ModelPlainSerializerT])9rD   
__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   rI   rO   rE   rP   rQ   rR   rS   rU   r]   rr   rs   rt   ru   rv   rw   rx   ry   rz   r|   r   r   r<   rG   r8   <module>r      sG   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 &-(" $SS S #	S S S SASl  /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 
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;;<# # =#rG   