o
    ȳg$                    @  s^  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZ d dlmZmZmZmZ d dlmZ d dlmZmZ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%m&Z& e
j'rd dl(m)Z* d dl+m,Z,m-Z- g dZ.G dd deZ/G dd de/Z0G dd de/Z1G dd de1Z2G dd de/Z3G dd de/Z4G dd de/Z5G dd de5Z6e
7dZ8G dd  d e/e
j9e8 Z:G d!d" d"e:e; Z<G d#d$ d$e:e= Z>G d%d& d&e:ej? Z?G d'd( d(e/Z@G d)d* d*e/ZAG d+d, d,eAZBG d-d. d.eAZCG d/d0 d0eAZDG d1d2 d2eAZEG d3d4 d4e/ZFG d5d6 d6e/ZG d7d8 d8eZGG d9d: d:e5ZHG d;d< d<e5ZIG d=d> d>e/ZJG d?d@ d@eJZKG dAdB dBeJZLG dCdD dDe/ZMG dEdF dFeMZNG dGdH dHeMZOG dIdJ dJe/Z)G dKdL dLe/ZPG dMdN dNe/ZQG dOdP dPe/ZRG dQdR dRe/ZSeHZTe5ZUe@ZVe<ZWdS )S    )annotationsN)Mapping)class_registrytypesutilsvalidate)FieldABC)FieldInstanceResolutionErrorStringNotCollectionErrorValidationError)is_awareis_collectionresolve_field_instance)missing)AndLength)ChangedInMarshmallow4WarningRemovedInMarshmallow4Warning)Enum)Schema
SchemaMeta)%IPURLUUIDAwareDateTimeBoolBooleanConstantDateDateTimeDecimalDictEmailr   FieldFloatFunctionIPInterfaceIPv4IPv4InterfaceIPv6IPv6InterfaceIntIntegerListr   MethodNaiveDateTimeNestedNumberPluckRawStrStringTime	TimeDeltaTupleUrlc                   @  s(  e Zd ZU dZdZddddZded< eeeed	d	d	d
d	d
d
d	d	ddTd"d#ZdUd%d&Z	d'd( Z
d	efdVd-d.ZdWd0d1ZedXd3d4ZdYd7d8ZdZd9d:Zd[d;d<Z		d\d]d=d>Z				d^d_d@dAZd`dEdFZdadGdHZdbdIdJZedcdLdMZedNdO ZejdPdO ZedQdR ZejdSdR Zd	S )dr#   a  Base field from which other fields inherit.

    :param dump_default: If set, this value will be used during serialization if the
        input value is missing. If not set, the field will be excluded from the
        serialized output if the input value is missing. May be a value or a callable.
    :param load_default: Default deserialization value for the field if the field is not
        found in the input data. May be a value or a callable.
    :param data_key: The name of the dict key in the external representation, i.e.
        the input of `load` and the output of `dump`.
        If `None`, the key will match the name of the field.
    :param attribute: The name of the key/attribute in the internal representation, i.e.
        the output of `load` and the input of `dump`.
        If `None`, the key/attribute will match the name of the field.
        Note: This should only be used for very specific use cases such as
        outputting multiple fields for a single attribute, or using keys/attributes
        that are invalid variable names, unsuitable for field names. In most cases,
        you should use ``data_key`` instead.
    :param validate: Validator or collection of validators that are called
        during deserialization. Validator takes a field's input value as
        its only parameter and returns a boolean.
        If it returns `False`, an :exc:`ValidationError` is raised.
    :param required: Raise a :exc:`ValidationError` if the field value
        is not supplied during deserialization.
    :param allow_none: Set this to `True` if `None` should be considered a valid value during
        validation/deserialization. If set to `False` (the default), `None` is considered invalid input.
        If ``load_default`` is explicitly set to `None` and ``allow_none`` is unset,
        `allow_none` is implicitly set to ``True``.
    :param load_only: If `True` skip this field during serialization, otherwise
        its value will be present in the serialized data.
    :param dump_only: If `True` skip this field during deserialization, otherwise
        its value will be present in the deserialized object. In the context of an
        HTTP API, this effectively marks the field as "read-only".
    :param error_messages: Overrides for `Field.default_error_messages`.
    :param metadata: Extra information to be stored as field metadata.

    .. versionchanged:: 3.0.0b8
        Add ``data_key`` parameter for the specifying the key in the input and
        output data. This parameter replaced both ``load_from`` and ``dump_to``.

    .. versionchanged:: 3.13.0
        Replace ``missing`` and ``default`` parameters with ``load_default`` and ``dump_default``.

    .. versionchanged:: 3.24.0
        `Field <marshmallow.fields.Field>` should no longer be used as a field within a `Schema <marshmallow.Schema>`.
        Use `Raw <marshmallow.fields.Raw>` or another `Field <marshmallow.fields.Field>` subclass instead.
    Tz Missing data for required field.zField may not be null.zInvalid value.)requirednullvalidator_failedzdict[str, str]default_error_messagesNF)load_defaultr   dump_defaultdefaultdata_key	attributer   r:   
allow_none	load_only	dump_onlyerror_messagesmetadatar>   
typing.Anyr   r?   r@   rA   
str | NonerB   r   9types.Validator | typing.Iterable[types.Validator] | Noner:   boolrC   bool | NonerD   rE   rF   dict[str, str] | NonerG   &typing.Mapping[str, typing.Any] | NonereturnNonec                K  s  | j tu rtjdtdd |turtjdtdd |tu r|}|tur1tjdtdd |tu r1|}|| _|| _|| _	|| _
|| _|d u rHg | _nt|rQ|g| _nt|r\t|| _ntd|	d u rh|d u n|	| _|
| _|| _|du r}|tur}td|| _|pi }i ||| _|rtjd	| tdd i }t| j jD ]}|t|d
i  q||pi  || _d | _d | _d | _d S )NzX`Field` should not be instantiated. Use `fields.Raw` or  another field subclass instead.   
stacklevelzKThe 'default' argument to fields is deprecated. Use 'dump_default' instead.zKThe 'missing' argument to fields is deprecated. Use 'load_default' instead.zIThe 'validate' parameter must be a callable or a collection of callables.Tz3'load_default' must not be set for required fields.zPassing field metadata as keyword arguments is deprecated. Use the explicit `metadata=...` argument instead. Additional metadata: r=   )	__class__r#   warningswarnr   missing_r   r?   r>   rB   rA   r   
validatorscallabler   is_iterable_but_not_stringlist
ValueErrorrC   rD   rE   r:   rG   reversed__mro__updategetattrrF   parentnameroot)selfr>   r   r?   r@   rA   rB   r   r:   rC   rD   rE   rF   rG   additional_metadatamessagescls rh   N/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/marshmallow/fields.py__init__   sx   


	
zField.__init__strc                 C  sX   d| j j d| jd| jd| j d| j d| j d| j d| j d	| j	 d
| j
 dS )Nz<fields.z(dump_default=z, attribute=z, validate=z, required=z, load_only=z, dump_only=z, load_default=z, allow_none=z, error_messages=z)>)rT   __name__r?   rB   r   r:   rD   rE   r>   rC   rF   rd   rh   rh   ri   __repr__   s$   zField.__repr__c                 C  s
   t  | S N)copy)rd   memorh   rh   ri   __deepcopy__      
zField.__deepcopy__objattraccessorAtyping.Callable[[typing.Any, str, typing.Any], typing.Any] | Nonec                 C  s*   |pt j}| jdu r|n| j}||||S )aN  Return the value for a given key from an object.

        :param obj: The object to get the value from.
        :param attr: The attribute/key in `obj` to get the value from.
        :param accessor: A callable used to retrieve the value of `attr` from
            the object `obj`. Defaults to `marshmallow.utils.get_value`.
        N)r   	get_valuerB   )rd   rt   ru   rv   r@   accessor_func	check_keyrh   rh   ri   rx      s   
zField.get_valuevaluec                 C  s   |  | dS )zpPerform validation on ``value``. Raise a :exc:`ValidationError` if validation
        does not succeed.
        N)_validate_allrd   r{   rh   rh   ri   	_validate  s   zField._validate#typing.Callable[[typing.Any], None]c                 C  s   t | jd| jd iS )Nerrorr<   )r   rX   rF   rm   rh   rh   ri   r|     s   zField._validate_allkeyr   c              
   K  sr   z| j | }W n ty% } z| jj}d| d| d}t||d}~ww t|ttfr5|jdi |}t	|S )znHelper method to make a `ValidationError` with an error message
        from ``self.error_messages``.
        zValidationError raised by `z`, but error key `z4` does not exist in the `error_messages` dictionary.Nrh   )
rF   KeyErrorrT   rl   AssertionError
isinstancerk   bytesformatr   )rd   r   kwargsmsgr   
class_namemessagerh   rh   ri   
make_error  s   
zField.make_errorc                 K  s,   t jd| dtdd | jdd|i|)zHelper method that raises a `ValidationError` with an error message
        from ``self.error_messages``.

        .. deprecated:: 3.0.0
            Use `make_error <marshmallow.fields.Field.make_error>` instead.
        z8`Field.fail` is deprecated. Use `raise self.make_error("z", ...)` instead.rQ   rR   r   Nrh   )rU   rV   r   r   )rd   r   r   rh   rh   ri   fail+  s   
z
Field.failc                 C  s8   |t u r| jr| d|du r| js| ddS dS )zqValidate missing values. Raise a :exc:`ValidationError` if
        `value` should be considered missing.
        r:   Nr;   )rW   r:   r   rC   r}   rh   rh   ri   _validate_missing9  s
   

zField._validate_missingc                 K  s^   | j r"| j|||d}|tu r| j}t|r| n|}|tu r!|S nd}| j|||fi |S )az  Pulls the value for the given key from the object, applies the
        field's formatting and returns the result.

        :param attr: The attribute/key to get from the object.
        :param obj: The object to access the attribute/key from.
        :param accessor: Function used to access values from ``obj``.
        :param kwargs: Field-specific keyword arguments.
        )rv   N)_CHECK_ATTRIBUTErx   rW   r?   rY   
_serialize)rd   ru   rt   rv   r   r{   r@   rh   rh   ri   	serializeB  s   zField.serializedatac                 K  s`   |  | |tu r| j}t|r| S |S | jr|du rdS | j|||fi |}| | |S )a  Deserialize ``value``.

        :param value: The value to deserialize.
        :param attr: The attribute/key in `data` to deserialize.
        :param data: The raw input data passed to `Schema.load <marshmallow.Schema.load>`.
        :param kwargs: Field-specific keyword arguments.
        :raise ValidationError: If an invalid value is passed or if a required value
            is missing.
        N)r   rW   r>   rY   rC   _deserializer~   )rd   r{   ru   r   r   _missoutputrh   rh   ri   deserialize^  s   

zField.deserialize
field_nameschemaSchema | Fieldc                 C  sD   | j p|| _ | jp
|| _| jpt| j tr| j j| _dS | j | _dS )zUpdate field with values from its parent schema. Called by
        `Schema._bind_field <marshmallow.Schema._bind_field>`.

        :param field_name: Field name set in schema.
        :param schema: Parent object.
        N)ra   rb   rc   r   r   rd   r   r   rh   rh   ri   _bind_to_schema|  s   zField._bind_to_schemac                 K     |S )a  Serializes ``value`` to a basic Python datatype. Noop by default.
        Concrete :class:`Field` classes should implement this method.

        Example: ::

            class TitleCase(Field):
                def _serialize(self, value, attr, obj, **kwargs):
                    if not value:
                        return ""
                    return str(value).title()

        :param value: The value to be serialized.
        :param attr: The attribute or key on the object to be serialized.
        :param obj: The object the value was pulled from.
        :param kwargs: Field-specific keyword arguments.
        :return: The serialized value
        rh   rd   r{   ru   rt   r   rh   rh   ri   r     s   zField._serializec                 K  r   )a1  Deserialize value. Concrete :class:`Field` classes should implement this method.

        :param value: The value to be deserialized.
        :param attr: The attribute/key in `data` to be deserialized.
        :param data: The raw input data passed to the `Schema.load <marshmallow.Schema.load>`.
        :param kwargs: Field-specific keyword arguments.
        :raise ValidationError: In case of formatting or validation failure.
        :return: The deserialized value.

        .. versionchanged:: 3.0.0
            Added ``**kwargs`` to signature.
        rh   rd   r{   ru   r   r   rh   rh   ri   r     s   zField._deserializedict | Nonec                 C  s   | j r| j jS dS )zDThe context dictionary for the parent `Schema <marshmallow.Schema>`.N)ra   contextrm   rh   rh   ri   r     s   zField.contextc                 C     t jdtdd | jS NzLThe 'default' attribute of fields is deprecated. Use 'dump_default' instead.rQ   rR   rU   rV   r   r?   rm   rh   rh   ri   r@        zField.defaultc                 C     t jdtdd || _d S r   r   r}   rh   rh   ri   r@        
c                 C  r   NzLThe 'missing' attribute of fields is deprecated. Use 'load_default' instead.rQ   rR   rU   rV   r   r>   rm   rh   rh   ri   r     r   zField.missingc                 C  r   r   r   r}   rh   rh   ri   r     r   )r>   rH   r   rH   r?   rH   r@   rH   rA   rI   rB   rI   r   rJ   r:   rK   rC   rL   rD   rK   rE   rK   rF   rM   rG   rN   rO   rP   rO   rk   )rt   rH   ru   rk   rv   rw   r@   rH   )r{   rH   )rO   r   )r   rk   rO   r   )r   rk   r{   rH   rO   rP   ro   )ru   rk   rt   rH   rv   rw   NN)r{   rH   ru   rI   r   rN   r   rk   r   r   rO   rP   )r{   rH   ru   rI   rt   rH   rO   rH   )r{   rH   ru   rI   r   rN   rO   rH   )rO   r   )rl   
__module____qualname____doc__r   r=   __annotations__rW   rj   rn   rr   rx   r~   propertyr|   r   r   r   r   r   r   r   r   r   r@   setterr   rh   rh   rh   ri   r#   T   sd   
 2	
]
	







	
	
	r#   c                   @  s   e Zd ZdZdS )r3   z!Field that applies no formatting.N)rl   r   r   r   rh   rh   rh   ri   r3     s    r3   c                      s   e Zd ZdZddiZeedddddd/ fddZed0ddZd1ddZ	d d! Z
d2d$d%Z	d3d4d(d)Z	d3d5d-d.Z  ZS )6r0   a  Allows you to nest a :class:`Schema <marshmallow.Schema>`
    inside a field.

    Examples: ::

        class ChildSchema(Schema):
            id = fields.Str()
            name = fields.Str()
            # Use lambda functions when you need two-way nesting or self-nesting
            parent = fields.Nested(lambda: ParentSchema(only=("id",)), dump_only=True)
            siblings = fields.List(
                fields.Nested(lambda: ChildSchema(only=("id", "name")))
            )


        class ParentSchema(Schema):
            id = fields.Str()
            children = fields.List(
                fields.Nested(ChildSchema(only=("id", "parent", "siblings")))
            )
            spouse = fields.Nested(lambda: ParentSchema(only=("id",)))

    When passing a `Schema <marshmallow.Schema>` instance as the first argument,
    the instance's ``exclude``, ``only``, and ``many`` attributes will be respected.

    Therefore, when passing the ``exclude``, ``only``, or ``many`` arguments to `fields.Nested`,
    you should pass a `Schema <marshmallow.Schema>` class (not an instance) as the first argument.

    ::

        # Yes
        author = fields.Nested(UserSchema, only=("id", "name"))

        # No
        author = fields.Nested(UserSchema(), only=("id", "name"))

    :param nested: `Schema <marshmallow.Schema>` instance, class, class name (string), dictionary, or callable that
        returns a `Schema <marshmallow.Schema>` or dictionary.
        Dictionaries are converted with `Schema.from_dict <marshmallow.Schema.from_dict>`.
    :param exclude: A list or tuple of fields to exclude.
    :param only: A list or tuple of fields to marshal. If `None`, all fields are marshalled.
        This parameter takes precedence over ``exclude``.
    :param many: Whether the field is a collection of objects.
    :param unknown: Whether to exclude, include, or raise an error for unknown
        fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
    :param kwargs: The same keyword arguments that :class:`Field` receives.
    typezInvalid type.Nrh   F)r?   r@   onlyexcludemanyunknownnestedjSchema | SchemaMeta | str | dict[str, Field] | typing.Callable[[], Schema | SchemaMeta | dict[str, Field]]r?   rH   r@   r   types.StrSequenceOrSet | Noner   types.StrSequenceOrSetr   rK   r   rI   c          	        s   |d urt |stdt |std|dkr tjdtdd || _|| _|| _|| _|| _	d | _
t jd||d| d S )	Nz)"only" should be a collection of strings.z,"exclude" should be a collection of strings.rd   zVPassing 'self' to `Nested` is deprecated. Use `Nested(lambda: MySchema(...))` instead.rQ   rR   )r@   r?   rh   )r   r
   rU   rV   r   r   r   r   r   r   _schemasuperrj   )	rd   r   r?   r@   r   r   r   r   r   rT   rh   ri   rj      s&   zNested.__init__rO   r   c              	   C  s  | j st| jdi }t| jrt| jts|  }ntd| j}ddl	m
} t|tr1||}t||rt|| _ | j j| ttt | j j}| jdurn| j jdur]| j j}n| j j }|| j||@ | j _| jr| j j}|| j||B | j _| j   | j S t|trt||r|}n$t|ttfstd|j d|dkrt|| jj}ntj|d	d
}|| j| j| j||  d|  dd| _ | j S )zThe nested `Schema <marshmallow.Schema>` object.

        .. versionchanged:: 1.0.0
            Renamed from ``serializer`` to ``schema``.
        r   r   r   )r   Nz/`Nested` fields must be passed a `Schema`, not .rd   F)allrD   rE   )r   r   r   r   rD   rE   )!r   r`   ra   rY   r   r   r   typingcastmarshmallow.schemar   dict	from_dictrp   r   r_   set	set_classr   fieldskeysr   _init_fields
issubclassrk   r   r\   rT   rc   r   	get_classr   _nested_normalized_option)rd   r   r   r   r   originalschema_classrh   rh   ri   r   H  sT   






zNested.schemaoption_namerk   	list[str]c                   s*   | j  d  fddt| j|t D S )Nr   c                   s&   g | ]}|  r| d d  qS    )
startswithsplit).0fieldnested_fieldrh   ri   
<listcomp>  s    z4Nested._nested_normalized_option.<locals>.<listcomp>)rb   r`   rc   r   )rd   r   rh   r   ri   r     s   
z Nested._nested_normalized_optionc                 K  s,   | j }|d u r	d S |jp| j}|j||dS )N)r   )r   r   dump)rd   
nested_objru   rt   r   r   r   rh   rh   ri   r     s
   zNested._serializer{   rP   c                 C  s8   | j jp| j}|rt|s| jd||jjdd S d S )Nr   )inputr   )r   r   r   r   r   rT   rl   )rd   r{   r   rh   rh   ri   _test_collection  s   zNested._test_collectionpartial$bool | types.StrSequenceOrSet | Nonec              
   C  sF   z| j j|| j|d}W |S  ty" } z	t|j|jd|d }~ww )N)r   r   
valid_data)r   loadr   r   rf   r   )rd   r{   r   r   r   rh   rh   ri   _load  s   zNested._loadru   r   rN   c                 K  s   |  | | j||dS )a  Same as :meth:`Field._deserialize` with additional ``partial`` argument.

        :param partial: For nested schemas, the ``partial``
            parameter passed to `marshmallow.Schema.load`.

        .. versionchanged:: 3.0.0
            Add ``partial`` parameter.
        r   )r   r   rd   r{   ru   r   r   r   rh   rh   ri   r     s   
zNested._deserialize)r   r   r?   rH   r@   rH   r   r   r   r   r   rK   r   rI   )rO   r   )r   rk   rO   r   r   ro   )r{   rH   r   r   )
r{   rH   ru   rI   r   rN   r   r   rO   rH   )rl   r   r   r   r=   rW   rj   r   r   r   r   r   r   r   __classcell__rh   rh   r   ri   r0     s&    1(
8
	r0   c                      sN   e Zd ZdZdddd fddZedddZ fddZdddZ  Z	S )r2   a
  Allows you to replace nested data with one of the data's fields.

    Example: ::

        from marshmallow import Schema, fields


        class ArtistSchema(Schema):
            id = fields.Int()
            name = fields.Str()


        class AlbumSchema(Schema):
            artist = fields.Pluck(ArtistSchema, "id")


        in_data = {"artist": 42}
        loaded = AlbumSchema().load(in_data)  # => {'artist': {'id': 42}}
        dumped = AlbumSchema().dump(loaded)  # => {'artist': 42}

    :param nested: The Schema class or class name (string)
        to nest, or ``"self"`` to nest the `Schema <marshmallow.Schema>` within itself.
    :param field_name: The key to pluck a value from.
    :param kwargs: The same keyword arguments that :class:`Nested` receives.
    FN)r   r   r   7Schema | SchemaMeta | str | typing.Callable[[], Schema]r   rk   r   rK   r   rI   c                  s(   t  j|f|f||d| || _d S )N)r   r   r   )r   rj   r   )rd   r   r   r   r   r   r   rh   ri   rj     s   	
zPluck.__init__rO   c                 C  s   | j j| j }|jp| jS ro   )r   r   r   rA   )rd   
only_fieldrh   rh   ri   _field_data_key  s   zPluck._field_data_keyc                   sD   t  j|||fi |}|d u rd S | jrtj|| jdS || j S )N)r   )r   r   r   r   pluckr   )rd   r   ru   rt   r   retr   rh   ri   r     s   
zPluck._serializec                   s<     |  jr fdd|D }n j|i} j||dS )Nc                   s   g | ]} j |iqS rh   )r   )r   vrm   rh   ri   r     s    z&Pluck._deserialize.<locals>.<listcomp>r   )r   r   r   r   r   rh   rm   ri   r     s
   

zPluck._deserialize)r   r   r   rk   r   rK   r   rI   r   ro   )
rl   r   r   r   rj   r   r   r   r   r   rh   rh   r   ri   r2     s    r2   c                      L   e Zd ZdZddiZd fddZd fddZdddZdddZ  Z	S )r-   al  A list field, composed with another `Field` class or
    instance.

    Example: ::

        numbers = fields.List(fields.Float())

    :param cls_or_instance: A field class or instance.
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    .. versionchanged:: 3.0.0rc9
        Does not serialize scalar values to single-item lists.
    invalidzNot a valid list.cls_or_instanceField | type[Field]c              
     sl   t  jdi | zt|| _W n ty! } ztd|d }~ww t| jtr4| jj| _| jj	| _	d S d S )NzNThe list elements must be a subclass or instance of marshmallow.base.FieldABC.rh   )
r   rj   r   innerr	   r\   r   r0   r   r   )rd   r   r   r   r   rh   ri   rj     s   
zList.__init__r   rk   r   r   rO   rP   c                   sR   t  || t| j| _| j||  t| jtr'| j| j_| j| j_d S d S ro   )	r   r   rp   deepcopyr   r   r0   r   r   r   r   rh   ri   r     s   
zList._bind_to_schemalist[typing.Any] | Nonec                   s$   |d u rd S  fdd|D S )Nc                   s$   g | ]}j j| fi qS rh   )r   r   r   eachru   r   rt   rd   rh   ri   r     s   $ z#List._serialize.<locals>.<listcomp>rh   r   rh   r   ri   r     s   zList._serializelist[typing.Any]c           
      K  s   t |s
| dg }i }t|D ]8\}}z|| jj|fi | W q tyJ }	 z|	jd ur8||	j |	||	j
i W Y d }	~	qd }	~	ww |rSt||d|S Nr   r   )r   r   r   	enumerateappendr   r   r   r   r_   rf   )
rd   r{   ru   r   r   resulterrorsidxr   r   rh   rh   ri   r   !  s    


zList._deserialize)r   r   r   )rO   r   )rO   r   
rl   r   r   r   r=   rj   r   r   r   r   rh   rh   r   ri   r-     s    
r-   c                      r   )r8   aG  A tuple field, composed of a fixed number of other `Field` classes or
    instances

    Example: ::

        row = Tuple((fields.String(), fields.Integer(), fields.Float()))

    .. note::
        Because of the structured nature of `collections.namedtuple` and
        `typing.NamedTuple`, using a Schema within a Nested field for them is
        more appropriate than using a `Tuple` field.

    :param tuple_fields: An iterable of field classes or
        instances.
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    .. versionadded:: 3.0.0rc4
    r   zNot a valid tuple.tuple_fields5typing.Iterable[Field] | typing.Iterable[type[Field]]c              
     sr   t  jdi | t|stdz
dd |D | _W n ty- } ztd|d }~ww tt| jd| _	d S )Nz?tuple_fields must be an iterable of Field classes or instances.c                 S  s   g | ]}t |qS rh   )r   )r   r   rh   rh   ri   r   V  s    z"Tuple.__init__.<locals>.<listcomp>zXElements of "tuple_fields" must be subclasses or instances of marshmallow.base.FieldABC.)equalrh   )
r   rj   r   r   r\   r   r	   r   lenvalidate_length)rd   r   r   r   r   rh   ri   rj   J  s$   
zTuple.__init__r   rk   r   r   rO   rP   c                   sH   t  || g }| jD ]}t|}|||  || q|| _d S ro   )r   r   r   rp   r   r   )rd   r   r   new_tuple_fieldsr   	new_fieldr   rh   ri   r   b  s   


zTuple._bind_to_schematuple | Nonec                   s.   |d u rd S t  fddt| j|D S )Nc                 3  s*    | ]\}}|j | fi V  qd S ro   )r   )r   r   r   ru   r   rt   rh   ri   	<genexpr>p  s
    
z#Tuple._serialize.<locals>.<genexpr>)tuplezipr   r   rh   r  ri   r   l  s
   
zTuple._serializer	  c                 K  s   t |s
| d| | g }i }tt| j|D ]9\}\}}	z||j|	fi | W q t	yT }
 z|
j
d urB||
j
 |||
ji W Y d }
~
qd }
~
ww |r]t	||dt|S r   )r   r   r   r  r   r
  r   r   r   r   r   r_   rf   r	  )rd   r{   ru   r   r   r   r   r   r   r   r   rh   rh   ri   r   u  s"   



zTuple._deserialize)r   r   r   )rO   r  )rO   r	  r   rh   rh   r   ri   r8   3  s    

	r8   c                   @  s.   e Zd ZdZdddZdddZdd
dZdS )r5   zaA string field.

    :param kwargs: The same keyword arguments that :class:`Field` receives.
    zNot a valid string.zNot a valid utf-8 string.)r   invalid_utf8rO   rI   c                 K  s   |d u rd S t |S ro   )r   ensure_text_typer   rh   rh   ri   r     s   
zString._serializerH   c              
   K  sJ   t |ttfs| dzt|W S  ty$ } z| d|d }~ww )Nr   r  )r   rk   r   r   r   r  UnicodeDecodeErrorrd   r{   ru   r   r   r   rh   rh   ri   r     s   
zString._deserializeNrO   rI   )rO   rH   )rl   r   r   r   r=   r   r   rh   rh   rh   ri   r5     s    
r5   c                   @  s,   e Zd ZdZddiZdddZddd	Zd
S )r   zA UUID field.invalid_uuidzNot a valid UUID.rO   uuid.UUID | Nonec              
   C  sx   |du rdS t |tjr|S zt |tr!t|dkr!tj|dW S t|W S  tttfy; } z| d|d}~ww )FFormat the value or raise a :exc:`ValidationError` if an error occurs.N   )r   r  )	r   uuidr   r   r  r\   AttributeError	TypeErrorr   rd   r{   r   rh   rh   ri   
_validated  s   zUUID._validatedc                 K  
   |  |S ro   r  r   rh   rh   ri   r     rs   zUUID._deserializeN)rO   r  )rl   r   r   r   r=   r  r   rh   rh   rh   ri   r     s
    
r   _NumTypec                      sr   e Zd ZU dZeZded< dddZddd fddZdddZ	d ddZ
d!ddZd"ddZd#ddZ  ZS )$r1   a  Base class for number fields.

    :param as_string: If `True`, format the serialized value as a string.
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    .. versionchanged:: 3.24.0
        `Number <marshmallow.fields.Number>` should no longer be used as a field within a `Schema <marshmallow.Schema>`.
        Use `Integer <marshmallow.fields.Integer>`, `Float <marshmallow.fields.Float>`, or `Decimal <marshmallow.fields.Decimal>` instead.
    r   num_typezNot a valid number.zNumber too large.)r   	too_largeF)	as_stringr  rK   c                  s6   | j tu rtjdtdd || _t jdi | d S )NzX`Number` field should not be instantiated. Use `Integer`, `Float`, or `Decimal` instead.rQ   rR   rh   )rT   r1   rU   rV   r   r  r   rj   )rd   r  r   r   rh   ri   rj     s   
zNumber.__init__rO   r  c                 C  r  )zAReturn the number value for value, given this field's `num_type`.)r  r}   rh   rh   ri   _format_num  s   
zNumber._format_numr{   rH   c              
   C  s~   |du s|du r| j d|dz| |W S  ttfy+ } z| j d|d|d}~w ty> } z| j d|d|d}~ww )r  TFr   r   Nr  )r   r  r  r\   OverflowErrorr  rh   rh   ri   r    s   zNumber._validatedrk   c                 C  s   t |S ro   )rk   r}   rh   rh   ri   
_to_string  s   zNumber._to_stringstr | _NumType | Nonec                 K  s*   |du rdS |  |}| jr| |S |S )zSReturn a string if `self.as_string=True`, otherwise return this field's `num_type`.N)r  r  r"  )rd   r{   ru   rt   r   r   rh   rh   ri   r     s   
zNumber._serialize_NumType | Nonec                 K  r  ro   r  r   rh   rh   ri   r     rs   zNumber._deserialize)r  rK   )rO   r  )r{   rH   rO   r  )r{   r  rO   rk   )rO   r#  )rO   r$  )rl   r   r   r   floatr  r   r=   rj   r  r  r"  r   r   r   rh   rh   r   ri   r1     s   
 





r1   c                      sB   e Zd ZdZeZddiZddd fdd	Zd fddZ  Z	S )r,   zAn integer field.

    :param strict: If `True`, only integer types are valid.
        Otherwise, any value castable to `int` is valid.
    :param kwargs: The same keyword arguments that :class:`Number` receives.
    r   zNot a valid integer.F)strictr&  rK   c                  s   || _ t jdi | d S Nrh   )r&  r   rj   )rd   r&  r   r   rh   ri   rj     s   zInteger.__init__r{   rH   rO   intc                   s,   | j rt|tjs| jd|dt |S )Nr   r   )r&  r   numbersIntegralr   r   r  r}   r   rh   ri   r    s   zInteger._validated)r&  rK   )r{   rH   rO   r(  )
rl   r   r   r   r(  r  r=   rj   r  r   rh   rh   r   ri   r,     s    r,   c                      sD   e Zd ZdZeZddiZdddd fd	d
Zd fddZ  Z	S )r$   a\  A double as an IEEE-754 double precision string.

    :param allow_nan: If `True`, `NaN`, `Infinity` and `-Infinity` are allowed,
        even though they are illegal according to the JSON specification.
    :param as_string: If `True`, format the value as a string.
    :param kwargs: The same keyword arguments that :class:`Number` receives.
    special;Special numeric values (nan or infinity) are not permitted.F	allow_nanr  r.  rK   r  c                  s    || _ t jdd|i| d S )Nr  rh   )r.  r   rj   )rd   r.  r  r   r   rh   ri   rj   "  s   zFloat.__init__r{   rH   rO   r%  c                   sF   t  |}| jdu r!t|s|tdks|tdkr!| d|S )NFinfz-infr+  )r   r  r.  mathisnanr%  r   rd   r{   numr   rh   ri   r  &  s
   
"
zFloat._validated)r.  rK   r  rK   )r{   rH   rO   r%  )
rl   r   r   r   r%  r  r=   rj   r  r   rh   rh   r   ri   r$     s    r$   c                      s^   e Zd ZdZejZddiZ		ddddd fddZdd Z	d fddZ
dddZ  ZS )r    a  A field that (de)serializes to the Python ``decimal.Decimal`` type.
    It's safe to use when dealing with money values, percentages, ratios
    or other numbers where precision is critical.

    .. warning::

        This field serializes to a `decimal.Decimal` object by default. If you need
        to render your data as JSON, keep in mind that the `json` module from the
        standard library does not encode `decimal.Decimal`. Therefore, you must use
        a JSON library that can handle decimals, such as `simplejson`, or serialize
        to a string by passing ``as_string=True``.

    .. warning::

        If a JSON `float` value is passed to this field for deserialization it will
        first be cast to its corresponding `string` value before being deserialized
        to a `decimal.Decimal` object. The default `__str__` implementation of the
        built-in Python `float` type may apply a destructive transformation upon
        its input data and therefore cannot be relied upon to preserve precision.
        To avoid this, you can instead pass a JSON `string` to be deserialized
        directly.

    :param places: How many decimal places to quantize the value. If `None`, does
        not quantize the value.
    :param rounding: How to round the value during quantize, for example
        `decimal.ROUND_UP`. If `None`, uses the rounding value from
        the current thread's context.
    :param allow_nan: If `True`, `NaN`, `Infinity` and `-Infinity` are allowed,
        even though they are illegal according to the JSON specification.
    :param as_string: If `True`, serialize to a string instead of a Python
        `decimal.Decimal` type.
    :param kwargs: The same keyword arguments that :class:`Number` receives.

    .. versionadded:: 1.2.0
    r+  r,  NFr-  places
int | NoneroundingrI   r.  rK   r  c                  sF   |d urt dd| fnd | _|| _|| _t jdd|i| d S )Nr   r   r  rh   )decimalr    r4  r6  r.  r   rj   )rd   r4  r6  r.  r  r   r   rh   ri   rj   Z  s
   
zDecimal.__init__c                 C  sN   t t|}| jr| rt dS | jd ur%| r%|j| j| jd}|S )NNaN)r6  )	r7  r    rk   r.  is_nanr4  	is_finitequantizer6  r2  rh   rh   ri   r  k  s   
zDecimal._format_numr{   rH   rO   decimal.Decimalc              
     s\   zt  |}W n tjy } z| d|d }~ww | js,| s'| r,| d|S )Nr   r+  )r   r  r7  InvalidOperationr   r.  r9  is_infinite)rd   r{   r3  r   r   rh   ri   r  u  s   
zDecimal._validatedrk   c                 C  s
   t |dS )Nf)r   r}   rh   rh   ri   r"    rs   zDecimal._to_stringr   )r4  r5  r6  rI   r.  rK   r  rK   )r{   rH   rO   r<  )r{   r<  rO   rk   )rl   r   r   r   r7  r    r  r=   rj   r  r  r"  r   rh   rh   r   ri   r    .  s    $

r    c                      sT   e Zd ZdZh dZh dZddiZdddd fddZdddZdd Z	  Z
S )r   a  A boolean field.

    :param truthy: Values that will (de)serialize to `True`. If an empty
        set, any non-falsy value will deserialize to `True`. If `None`,
        `marshmallow.fields.Boolean.truthy` will be used.
    :param falsy: Values that will (de)serialize to `False`. If `None`,
        `marshmallow.fields.Boolean.falsy` will be used.
    :param kwargs: The same keyword arguments that :class:`Field` receives.
    >   1TYtyONOnonYESYesyesTRUETruetruer   >   0FNr?  nNONonoOFFOffoffFALSEFalsefalser   r   zNot a valid boolean.N)truthyfalsyr[  typing.Iterable | Noner\  c                  s>   t  jdi | |d urt|| _|d urt|| _d S d S r'  )r   rj   r   r[  r\  )rd   r[  r\  r   r   rh   ri   rj     s   
zBoolean.__init__r{   rH   ru   rI   rt   c                 K  sP   |d u rd S z|| j v rW dS || jv rW dS W t|S  ty'   Y t|S w )NTF)r[  r\  r  rK   r   rh   rh   ri   r     s   

zBoolean._serializec              
   K  sj   | j st|S z|| j v rW dS || jv rW dS W n ty- } z| jd|d|d }~ww | jd|d)NTFr   r   )r[  rK   r\  r  r   r  rh   rh   ri   r     s   

zBoolean._deserialize)r[  r]  r\  r]  )r{   rH   ru   rI   rt   rH   )rl   r   r   r   r[  r\  r=   rj   r   r   r   rh   rh   r   ri   r     s    
r   c                      s   e Zd ZU dZejejejejejejdZ	de
d< ejejejejejejdZde
d< dZdZd	Zd
dddZdd  fddZ fddZd!ddZd"ddZed"ddZ  ZS )#r   a  A formatted datetime string.

    Example: ``'2014-12-22T03:12:58.019077+00:00'``

    :param format: Either ``"rfc"`` (for RFC822), ``"iso"`` (for ISO8601),
        ``"timestamp"``, ``"timestamp_ms"`` (for a POSIX timestamp) or a date format string.
        If `None`, defaults to "iso".
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    .. versionchanged:: 3.0.0rc9
        Does not modify timezone information on (de)serialization.
    .. versionchanged:: 3.19
        Add timestamp as a format.
    )isoiso8601rfcrfc822	timestamptimestamp_msz5dict[str, typing.Callable[[typing.Any], str | float]]SERIALIZATION_FUNCSz-dict[str, typing.Callable[[str], typing.Any]]DESERIALIZATION_FUNCSr^  datetimedatetimeformatzNot a valid {obj_type}.z#Not a valid {awareness} {obj_type}.z."{input}" cannot be formatted as a {obj_type}.)r   invalid_awarenessr   Nr   rI   rO   rP   c                   s   t  jdi | || _d S r'  )r   rj   r   )rd   r   r   r   rh   ri   rj     s   
zDateTime.__init__c                   s0   t  || | jpt| jj| jp| j| _d S ro   )r   r   r   r`   rc   optsSCHEMA_OPTS_VAR_NAMEDEFAULT_FORMATr   r   rh   ri   r     s   zDateTime._bind_to_schemastr | float | Nonec                 K  s:   |d u rd S | j p| j}| j|}|r||S ||S ro   )r   rk  rd  getstrftime)rd   r{   ru   rt   r   data_formatformat_funcrh   rh   ri   r   $  s   
zDateTime._serializedt.datetimec              
   K  sh   | j p| j}| j|}z|r||W S | ||W S  tttfy3 } z
| jd|| j	d|d }~ww )Nr   )r   obj_type)
r   rk  re  rm  _make_object_from_formatr  r  r\   r   OBJ_TYPE)rd   r{   ru   r   r   ro  funcr   rh   rh   ri   r   -  s   
zDateTime._deserializec                 C  s   t j| |S ro   )dtrf  strptimer{   ro  rh   rh   ri   rs  9  s   z!DateTime._make_object_from_formatro   )r   rI   rO   rP   )rO   rl  rO   rq  )rl   r   r   r   r   	isoformat	rfcformatrb  rc  rd  r   from_iso_datetimefrom_rfcfrom_timestampfrom_timestamp_msre  rk  rt  rj  r=   rj   r   r   r   staticmethodrs  r   rh   rh   r   ri   r     s:   
 
	

	r   c                      >   e Zd ZdZdZ	dddd fddZd fddZ  ZS )r/   a  A formatted naive datetime string.

    :param format: See :class:`DateTime`.
    :param timezone: Used on deserialization. If `None`,
        aware datetimes are rejected. If not `None`, aware datetimes are
        converted to this timezone before their timezone information is
        removed.
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    .. versionadded:: 3.0.0rc9
    naiveN)timezoner   rI   r  dt.timezone | NonerO   rP   c                      t  jdd|i| || _d S Nr   rh   )r   rj   r  )rd   r   r  r   r   rh   ri   rj   M     
zNaiveDateTime.__init__rq  c                   sV   t  j|||fi |}t|r)| jd u r| jd| j| jd|| jjd d}|S Nrh  )	awarenessrr  )tzinfo)	r   r   r   r  r   	AWARENESSrt  
astimezonereplacerd   r{   ru   r   r   r   r   rh   ri   r   W  s   
zNaiveDateTime._deserializero   )r   rI   r  r  rO   rP   ry  rl   r   r   r   r  rj   r   r   rh   rh   r   ri   r/   >  s    
r/   c                      r  )r   ac  A formatted aware datetime string.

    :param format: See :class:`DateTime`.
    :param default_timezone: Used on deserialization. If `None`, naive
        datetimes are rejected. If not `None`, naive datetimes are set this
        timezone.
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    .. versionadded:: 3.0.0rc9
    awareN)default_timezoner   rI   r  dt.tzinfo | NonerO   rP   c                  r  r  )r   rj   r  )rd   r   r  r   r   rh   ri   rj   r  r  zAwareDateTime.__init__rq  c                   sP   t  j|||fi |}t|s&| jd u r| jd| j| jd|j| jd}|S r  )r   r   r   r  r   r  rt  r  r  r   rh   ri   r   |  s   
zAwareDateTime._deserializero   )r   rI   r  r  rO   rP   ry  r  rh   rh   r   ri   r   d  s    
r   c                   @  sD   e Zd ZdZejejdZejejdZdZ	dZ
dZedd ZdS )	r6   zA formatted time string.

    Example: ``'03:12:58.019077'``

    :param format: Either ``"iso"`` (for ISO8601) or a date format string.
        If `None`, defaults to "iso".
    :param kwargs: The same keyword arguments that :class:`Field` receives.
    r^  r_  r^  time
timeformatc                 C     t j| | S ro   )rv  rf  rw  r  rx  rh   rh   ri   rs       zTime._make_object_from_formatN)rl   r   r   r   r   to_iso_timerd  from_iso_timere  rk  rt  rj  r  rs  rh   rh   rh   ri   r6     s    	r6   c                   @  sN   e Zd ZdZdddZejejdZejejdZ	dZ
dZdZed	d
 ZdS )r   zISO8601-formatted date string.

    :param format: Either ``"iso"`` (for ISO8601) or a date format string.
        If `None`, defaults to "iso".
    :param kwargs: The same keyword arguments that :class:`Field` receives.
    zNot a valid date.z("{input}" cannot be formatted as a date.r   r   r  r^  date
dateformatc                 C  r  ro   )rv  rf  rw  r  rx  rh   rh   ri   rs    r  zDate._make_object_from_formatN)rl   r   r   r   r=   r   to_iso_daterd  from_iso_datere  rk  rt  rj  r  rs  rh   rh   rh   ri   r     s    	r   c                      s^   e Zd ZdZdZdZdZdZdZdZ	dZ
d	d
dZeefd fddZdd Zdd Z  ZS )r7   a  A field that (de)serializes a :class:`datetime.timedelta` object to an
    integer or float and vice versa. The integer or float can represent the
    number of days, seconds or microseconds.

    :param precision: Influences how the integer or float is interpreted during
        (de)serialization. Must be 'days', 'seconds', 'microseconds',
        'milliseconds', 'minutes', 'hours' or 'weeks'.
    :param serialization_type: Whether to (de)serialize to a `int` or `float`.
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    Integer Caveats
    ---------------
    Any fractional parts (which depends on the precision used) will be truncated
    when serializing using `int`.

    Float Caveats
    -------------
    Use of `float` when (de)serializing may result in data precision loss due
    to the way machines handle floating point values.

    Regardless of the precision chosen, the fractional part when using `float`
    will always be truncated to microseconds.
    For example, `1.12345` interpreted as microseconds will result in `timedelta(microseconds=1)`.

    .. versionchanged:: 3.17.0
        Allow (de)serialization to `float` through use of a new `serialization_type` parameter.
        `int` is the default to retain previous behaviour.
    dayssecondsmicrosecondsmillisecondsminuteshoursweekszNot a valid period of time.z-{input!r} cannot be formatted as a timedelta.r  	precisionrk   serialization_typetype[int | float]c                   s   |  }| j| j| j| j| j| j| jf}||vr0dd	dd |d d D |d }t
||ttfvr:t
d|| _|| _t jdi | d S )Nz!The precision must be {} or "{}"., c                 S  s   g | ]}d | d qS )"rh   r   rh   rh   ri   r     s    z&TimeDelta.__init__.<locals>.<listcomp>z2The serialization type must be one of int or floatrh   )lowerDAYSSECONDSMICROSECONDSMILLISECONDSMINUTESHOURSWEEKSr   joinr\   r(  r%  r  r  r   rj   )rd   r  r  r   unitsr   r   rh   ri   rj     s&   
 zTimeDelta.__init__c                 K  sf   |d u rd S t jdi | jdi}| jtu r$t|}t|}|| S | jtu s+J | |  S )Nr   rh   )	rv  	timedeltar  r  r(  r   timedelta_to_microsecondsr%  total_seconds)rd   r{   ru   rt   r   	base_unitdeltaunitrh   rh   ri   r   	  s   


zTimeDelta._serializec              
   K  sz   z|  |}W n ttfy } z| d|d }~ww | j|i}z	tjdi |W S  ty< } z| d|d }~ww )Nr   rh   )r  r  r\   r   r  rv  r  r!  r  rh   rh   ri   r     s   
zTimeDelta._deserialize)r  rk   r  r  )rl   r   r   r   r  r  r  r  r  r  r  r=   r(  rj   r   r   r   rh   rh   r   ri   r7     s"    r7   c                      sP   e Zd ZdZeZddiZ		dd fdd	Z fd
dZdd Z	dd Z
  ZS )r   a  An abstract class for objects with key-value pairs. This class should not be used within schemas.

    :param keys: A field class or instance for dict keys.
    :param values: A field class or instance for dict values.
    :param kwargs: The same keyword arguments that :class:`Field` receives.

    .. note::
        When the structure of nested data is not known, you may omit the
        `keys` and `values` arguments to prevent content validation.

    .. versionadded:: 3.0.0rc4
    .. versionchanged:: 3.24.0
        `Mapping <marshmallow.fields.Mapping>` should no longer be used as a field within a `Schema <marshmallow.Schema>`.
        Use `Dict <marshmallow.fields.Dict>` instead.
    r   zNot a valid mapping type.Nr   Field | type[Field] | Nonevaluesc              
     s   | j tu rtjdtdd t jdi | |d u rd | _nzt|| _W n t	y6 } zt
d|d }~ww |d u r@d | _d S zt|| _W n t	yX } zt
d|d }~ww t| jtrk| jj| _| jj| _d S d S )Nz?`Mapping` field should not be instantiated. Use `Dict` instead.rQ   rR   zC"keys" must be a subclass or instance of marshmallow.base.FieldABC.zE"values" must be a subclass or instance of marshmallow.base.FieldABC.rh   )rT   r   rU   rV   r   r   rj   	key_fieldr   r	   r\   value_fieldr   r0   r   r   )rd   r   r  r   r   r   rh   ri   rj   :  sF   


zMapping.__init__c                   sz   t  || | jrt| j| _| j||  t| jtr(| j| j_| j| j_| j	r;t| j	| _	| j	||  d S d S ro   )
r   r   r  rp   r   r   r0   r   r   r  r   r   rh   ri   r   `  s   

zMapping._bind_to_schemac           	        s   |d u rd S j sjs|S jd u rdd |D }n
 fdd|D } }j d u rF| D ]\}}||v rC|||| < q5|S | D ]\}}j j|d d fi  ||| < qJ|S )Nc                 S     i | ]}||qS rh   rh   r   krh   rh   ri   
<dictcomp>t      z&Mapping._serialize.<locals>.<dictcomp>c                   s&   i | ]}|j j|d d fi  qS ro   )r  r   r  r   rd   rh   ri   r  v  s    )r  r  mapping_typeitemsr   )	rd   r{   ru   rt   r   r   r   r  r   rh   r  ri   r   l  s&   


"zMapping._serializec                 K  s  t |ts
| d| js| js| |S tt}| jd u r'dd |D }n.i }|D ])}z| jj	|fi |||< W q+ t
yT } z|j|| d< W Y d }~q+d }~ww |  }	| jd u rr| D ]\}
}|
|v rp||	||
 < qbnI| D ]D\}}z| jj	|fi |}W n) t
y } z|j|| d< |jd ur||v r|j|	|| < W Y d }~qvd }~ww ||v r||	|| < qv|rt
||	d|	S )Nr   c                 S  r  rh   rh   r  rh   rh   ri   r    r  z(Mapping._deserialize.<locals>.<dictcomp>r   r{   r   )r   _Mappingr   r  r  r  collectionsdefaultdictr   r   r   rf   r  r   )rd   r{   ru   r   r   r   r   r   r   r   r  r   val	deser_valrh   rh   ri   r     sJ   





zMapping._deserializer   )r   r  r  r  )rl   r   r   r   r   r  r=   rj   r   r   r   r   rh   rh   r   ri   r   $  s    &r   c                   @  s   e Zd ZdZeZdS )r!   a1  A dict field. Supports dicts and dict-like objects. Extends
    Mapping with dict as the mapping_type.

    Example: ::

        numbers = fields.Dict(keys=fields.Str(), values=fields.Float())

    :param kwargs: The same keyword arguments that :class:`Mapping` receives.

    .. versionadded:: 2.1.0
    N)rl   r   r   r   r   r  rh   rh   rh   ri   r!     s    r!   c                      s6   e Zd ZdZddiZdddddd fddZ  ZS )r9   a  An URL field.

    :param default: Default value for the field if the attribute is not set.
    :param relative: Whether to allow relative URLs.
    :param absolute: Whether to allow absolute URLs.
    :param require_tld: Whether to reject non-FQDN hostnames.
    :param schemes: Valid schemes. By default, ``http``, ``https``,
        ``ftp``, and ``ftps`` are allowed.
    :param kwargs: The same keyword arguments that :class:`String` receives.
    r   zNot a valid URL.FTN)relativeabsoluteschemesrequire_tldr  rK   r  r  r   r  c                  sV   t  jdi | || _|| _|| _tj| j| j|| j| jd d}| j	d| d S )Nr   )r  r  r  r  r   r   rh   )
r   rj   r  r  r  r   r   rF   rX   insert)rd   r  r  r  r  r   	validatorr   rh   ri   rj     s   	zUrl.__init__)r  rK   r  rK   r  r   r  rK   rl   r   r   r   r=   rj   r   rh   rh   r   ri   r9     s    r9   c                      s*   e Zd ZdZddiZd fddZ  ZS )	r"   zAn email field.

    :param args: The same positional arguments that :class:`String` receives.
    :param kwargs: The same keyword arguments that :class:`String` receives.
    r   zNot a valid email address.rO   rP   c                   s6   t  j|i | tj| jd d}| jd| d S )Nr   )r   r   )r   rj   r   r"   rF   rX   r  )rd   argsr   r  r   rh   ri   rj     s   zEmail.__init__)rO   rP   r  rh   rh   r   ri   r"     s    r"   c                      sP   e Zd ZU dZddiZdZded< dd fd	d

ZdddZdddZ	  Z
S )r   zA IP address field.

    :param exploded: If `True`, serialize ipv6 address in long form, ie. with groups
        consisting entirely of zeros included.

    .. versionadded:: 3.8.0
    
invalid_ipzNot a valid IP address.Ntype | NoneDESERIALIZATION_CLASSFexplodedc                     t  j|i | || _d S ro   r   rj   r  rd   r  r  r   r   rh   ri   rj        
zIP.__init__rO   rI   c                 K     |d u rd S | j r|j S |jS ro   r  
compressedr   rh   rh   ri   r     
   zIP._serialize4ipaddress.IPv4Address | ipaddress.IPv6Address | Nonec              
   K  N   |d u rd S z| j ptjt|W S  ttfy& } z| d|d }~ww )Nr  )r  	ipaddress
ip_addressr   r  r\   r  r   r  rh   rh   ri   r        
zIP._deserializer  )rO   r  rl   r   r   r   r=   r  r   rj   r   r   r   rh   rh   r   ri   r     s   
 
r   c                   @     e Zd ZdZddiZejZdS )r'   z7A IPv4 address field.

    .. versionadded:: 3.8.0
    r  zNot a valid IPv4 address.N)rl   r   r   r   r=   r  IPv4Addressr  rh   rh   rh   ri   r'         
r'   c                   @  r  )r)   z7A IPv6 address field.

    .. versionadded:: 3.8.0
    r  zNot a valid IPv6 address.N)rl   r   r   r   r=   r  IPv6Addressr  rh   rh   rh   ri   r)   *  r  r)   c                      sR   e Zd ZU dZddiZdZded< ddd fddZdddZdddZ	  Z
S )r&   a  A IPInterface field.

    IP interface is the non-strict form of the IPNetwork type where arbitrary host
    addresses are always accepted.

    IPAddress and mask e.g. '192.168.0.2/24' or '192.168.0.2/255.255.255.0'

    see https://python.readthedocs.io/en/latest/library/ipaddress.html#interface-objects

    :param exploded: If `True`, serialize ipv6 interface in long form, ie. with groups
        consisting entirely of zeros included.
    invalid_ip_interfacezNot a valid IP interface.Nr  r  Fr  r  rK   c                  r  ro   r  r  r   rh   ri   rj   G  r  zIPInterface.__init__rO   rI   c                 K  r  ro   r  r   rh   rh   ri   r   K  r  zIPInterface._serialize:None | (ipaddress.IPv4Interface | ipaddress.IPv6Interface)c              
   K  r  )Nr  )r  r  ip_interfacer   r  r\   r  r   r  rh   rh   ri   r   R  r  zIPInterface._deserialize)r  rK   r  )rO   r  r  rh   rh   r   ri   r&   5  s   
 
r&   c                   @  r  )r(   zA IPv4 Network Interface field.r  zNot a valid IPv4 interface.N)rl   r   r   r   r=   r  r(   r  rh   rh   rh   ri   r(   _      
r(   c                   @  r  )r*   zA IPv6 Network Interface field.r  zNot a valid IPv6 interface.N)rl   r   r   r   r=   r  r*   r  rh   rh   rh   ri   r*   g  r  r*   c                      s@   e Zd ZdZddiZddd fd
dZdd Zdd Z  ZS )r   a#  An Enum field (de)serializing enum members by symbol (name) or by value.

    :param enum: Enum class
    :param by_value: Whether to (de)serialize by value or by name,
        or Field class or instance to use to (de)serialize by value. Defaults to False.

    If `by_value` is `False` (default), enum members are (de)serialized by symbol (name).
    If it is `True`, they are (de)serialized by value using :class:`Raw`.
    If it is a field instance or class, they are (de)serialized by value using this field.

    .. versionadded:: 3.18.0
    r   zMust be one of: {choices}.F)by_valueenumtype[EnumType]r  bool | Field | type[Field]c             
     s   t  jdi | | _| _|du r't  _d fdd|jD  _d S |du r0t	  _nzt
| _W n tyH } ztd|d }~ww d fdd|D  _d S )	NFr  c                 3  s$    | ]}t  j|d d V  qd S ro   )rk   r   r   r   mrm   rh   ri   r    s    
z Enum.__init__.<locals>.<genexpr>TzX"by_value" must be either a bool or a subclass or instance of marshmallow.base.FieldABC.c                 3  s&    | ]}t  j|jd d V  qd S ro   )rk   r   r   r{   r  rm   rh   ri   r    s    
rh   )r   rj   r  r  r5   r   r  __members__choices_textr3   r   r	   r\   )rd   r  r  r   r   r   rm   ri   rj     s.   
zEnum.__init__c                 K  s8   |d u rd S | j r|j}n|j}| jj|||fi |S ro   )r  r{   rb   r   r   )rd   r{   ru   rt   r   r  rh   rh   ri   r     s   zEnum._serializec              
   K  s   | j j|||fi |}| jr+z| |W S  ty* } z	| jd| jd|d }~ww zt| j|W S  tyG } z	| jd| jd|d }~ww )Nr   )choices)	r   r   r  r  r\   r   r  r`   r  )rd   r{   ru   r   r   r  r   rh   rh   ri   r     s   zEnum._deserialize)r  r  r  r  )	rl   r   r   r   r=   rj   r   r   r   rh   rh   r   ri   r   o  s    !	r   c                      sH   e Zd ZdZdZ		dd fddZ fd	d
Zdd Zdd Z  Z	S )r.   a  A field that takes the value returned by a `Schema <marshmallow.Schema>` method.

    :param serialize: The name of the Schema method from which
        to retrieve the value. The method must take an argument ``obj``
        (in addition to self) that is the object to be serialized.
    :param deserialize: Optional name of the Schema method for deserializing
        a value The method must take a single argument ``value``, which is the
        value to deserialize.

    .. versionchanged:: 2.3.0
        Deprecated ``method_name`` parameter in favor of ``serialize`` and allow
        ``serialize`` to not be passed at all.

    .. versionchanged:: 3.0.0
        Removed ``method_name`` parameter.
    FNr   rI   r   c                   sZ   t |ot | |d< t |ot | |d< t jdi | || _|| _d | _d | _d S NrE   rD   rh   )rK   r   rj   serialize_method_namedeserialize_method_name_serialize_method_deserialize_methodrd   r   r   r   r   rh   ri   rj     s   
zMethod.__init__c                   sF   | j rtt|| j | _| jrtt|| j| _t || d S ro   )	r  r   callable_or_raiser`   r  r  r  r   r   r   r   rh   ri   r     s   

zMethod._bind_to_schemac                 K  s   | j d ur
|  |S tS ro   )r  rW   r   rh   rh   ri   r        

zMethod._serializec                 K  s   | j d ur
|  |S |S ro   )r  r   rh   rh   ri   r     r   zMethod._deserializer   )r   rI   r   rI   )
rl   r   r   r   r   rj   r   r   r   r   rh   rh   r   ri   r.     s    r.   c                      sD   e Zd ZdZdZ		dd fddZd	d
 Zdd Zdd Z  Z	S )r%   a  A field that takes the value returned by a function.

    :param serialize: A callable from which to retrieve the value.
        The function must take a single argument ``obj`` which is the object
        to be serialized. It can also optionally take a ``context`` argument,
        which is a dictionary of context variables passed to the serializer.
        If no callable is provided then the ```load_only``` flag will be set
        to True.
    :param deserialize: A callable from which to retrieve the value.
        The function must take a single argument ``value`` which is the value
        to be deserialized. It can also optionally take a ``context`` argument,
        which is a dictionary of context variables passed to the deserializer.
        If no callable is provided then ```value``` will be passed through
        unchanged.

    .. versionchanged:: 2.3.0
        Deprecated ``func`` parameter in favor of ``serialize``.

    .. versionchanged:: 3.0.0a1
        Removed ``func`` parameter.
    FNr   btyping.Callable[[typing.Any], typing.Any] | typing.Callable[[typing.Any, dict], typing.Any] | Noner   c                   sb   t |ot | |d< t |ot | |d< t jdi | |o%t|| _|o-t|| _d S r  )rK   r   rj   r   r  serialize_funcdeserialize_funcr  r   rh   ri   rj     s
   zFunction.__init__c                 K  s   |  | j||S ro   )_call_or_raiser  r   rh   rh   ri   r   !  s   zFunction._serializec                 K  s   | j r| | j ||S |S ro   )r  r  r   rh   rh   ri   r   $  s   zFunction._deserializec                 C  sF   t t|dkr| jjd u rd|}t|||| jjS ||S )Nr   z(No context available for Function field )r  r   get_func_argsra   r   r   )rd   ru  r{   ru   r   rh   rh   ri   r  )  s   
zFunction._call_or_raiser   )r   r  r   r  )
rl   r   r   r   r   rj   r   r   r  r   rh   rh   r   ri   r%     s    r%   c                      s6   e Zd ZdZdZd fddZdd Zd	d
 Z  ZS )r   a  A field that (de)serializes to a preset constant.  If you only want the
    constant added for serialization or deserialization, you should use
    ``dump_only=True`` or ``load_only=True`` respectively.

    :param constant: The constant to return for the field attribute.
    FconstantrH   c                   s(   t  jdi | || _|| _|| _d S r'  )r   rj   r  r>   r?   )rd   r  r   r   rh   ri   rj   <  s   
zConstant.__init__c                 O     | j S ro   r  rd   r{   r  r   rh   rh   ri   r   B     zConstant._serializec                 O  r  ro   r  r	  rh   rh   ri   r   E  r
  zConstant._deserialize)r  rH   )	rl   r   r   r   r   rj   r   r   r   rh   rh   r   ri   r   2  s    r   c                      s,   e Zd ZdZ fddZ fddZ  ZS )InferredzA field that infers how to serialize, based on the value type.

    .. warning::

        This class is treated as private API.
        Users should not need to use this class directly.
    c                   s   t    i | _d S ro   )r   rj   _field_cacherm   r   rh   ri   rj   R  s   

zInferred.__init__c                   sl   | j jt|}|d u rt }n| j|}|d u r+| }|| j| j || j|< |j	|||fi |S ro   )
rc   TYPE_MAPPINGrm  r   r   r  r   rb   ra   r   )rd   r{   ru   rt   r   	field_clsr   r   rh   ri   r   X  s   
zInferred._serialize)rl   r   r   r   rj   r   r   rh   rh   r   ri   r  I  s    r  )X
__future__r   r  rp   rf  rv  r7  r  r0  r)  r   r  rU   collections.abcr   r  marshmallowr   r   r   r   marshmallow.baser   marshmallow.exceptionsr	   r
   r   marshmallow.utilsr   r   r   r   rW   marshmallow.validater   r   marshmallow.warningsr   r   TYPE_CHECKINGr  r   EnumTyper   r   r   __all__r#   r3   r0   r2   r-   r8   r5   r   TypeVarr  Genericr1   r(  r,   r%  r$   r    r   r   r/   r   r6   r   r7   r!   r9   r"   r   r'   r)   r&   r(   r*   r.   r%   r   r  r   r4   r   r+   rh   rh   rh   ri   <module>   s   )    K?>X
;UcX&%e (%*I;?