o
    ȳg                     @  s  d Z 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 ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZmZ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+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ej8rddl9m:Z: dddZ;d ddZ<G dd deZ=G dd dZ>G dd dej?e=dZ@e@ZAdS )!zvThe `Schema <marshmallow.Schema>` class, including its metaclass and options (`class Meta <marshmallow.Schema.Meta>`).    )annotationsN)ABCMeta)OrderedDictdefaultdict)Mapping)zip_longest)baseclass_registrytypes)fields)	POST_DUMP	POST_LOADPRE_DUMPPRE_LOAD	VALIDATESVALIDATES_SCHEMA)
ErrorStore)SCHEMAStringNotCollectionErrorValidationError)
OrderedSet)	EXCLUDEINCLUDERAISE	get_valueis_collectionis_instance_or_subclassmissing	set_value validate_unknown_parameter_value)RemovedInMarshmallow4Warning)Fieldreturnlist[tuple[str, Field]]c                 C  s   dd |   D S )zKGet fields from a class

    :param attrs: Mapping of class attributes
    c                 S  s$   g | ]\}}t |tjr||fqS  )r   r   FieldABC).0
field_namefield_valuer$   r$   N/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/marshmallow/schema.py
<listcomp>7   s    
z_get_fields.<locals>.<listcomp>)items)attrsr$   r$   r)   _get_fields2   s   r-   klass
SchemaMetac                 C  s.   t | }ttjdd |ddd D g S )a  Collect fields from a class, following its method resolution order. The
    class itself is excluded from the search; only its parents are checked. Get
    fields from ``_declared_fields`` if available, else use ``__dict__``.

    :param klass: Class whose fields to retrieve
    c                 s  s"    | ]}t t|d |jV  qdS )_declared_fieldsN)r-   getattr__dict__)r&   r   r$   r$   r)   	<genexpr>M   s    
z%_get_fields_by_mro.<locals>.<genexpr>Nr   )inspectgetmro	functoolsreduceoperatoriadd)r.   mror$   r$   r)   _get_fields_by_mro@   s   
r<   c                      sl   e Zd ZU dZded< ded< ded< ded< d fddZeefd ddZ fddZ	d!ddZ
  ZS )"r/   a#  Metaclass for the Schema class. Binds the declared fields to
    a ``_declared_fields`` attribute, which is a dictionary mapping attribute
    names to field objects. Also sets the ``opts`` class attribute, which is
    the Schema class's `class Meta <marshmallow.Schema.Meta>` options.
    typeMeta
typing.AnyoptsOPTIONS_CLASSdict[str, Field]r0   namestrbasestuple[type, ...]r,   dict[str, typing.Any]r"   c                   s   | d}t|dd}|s%|D ]}t|dr"t|jdr"|jj} nqd}t|}|D ]\}}	||= q+t | |||}
t|
}|
j}|
j	||d|
_
|t|
j
j 7 }| j|
||td|
_|
S )Nr>   orderedF)rH   )r.   
cls_fieldsinherited_fieldsdict_cls)getr1   hasattrr>   rH   r-   super__new__r<   rA   r@   listincluder+   get_declared_fieldsdictr0   )mcsrC   rE   r,   metarH   base_rI   r'   _r.   rJ   	__class__r$   r)   rO   c   s0   
zSchemaMeta.__new__r.   rI   r#   rJ   rK   
type[dict]c                 C  s   ||| S )aA  Returns a dictionary of field_name => `Field` pairs declared on the class.
        This is exposed mainly so that plugins can add additional fields, e.g. fields
        computed from `class Meta <marshmallow.Schema.Meta>` options.

        :param klass: The class object.
        :param cls_fields: The fields declared on the class, including those added
            by the ``include`` `class Meta <marshmallow.Schema.Meta>` option.
        :param inherited_fields: Inherited fields.
        :param dict_cls: dict-like class to use for dict output Default to ``dict``.
        r$   )rT   r.   rI   rJ   rK   r$   r$   r)   rR      s   zSchemaMeta.get_declared_fieldsc                   s6   t  ||| |r| jjrt||  |  | _d S N)rN   __init__r@   registerr	   resolve_hooks_hooks)clsrC   rE   r,   rX   r$   r)   r\      s   zSchemaMeta.__init__'dict[str, list[tuple[str, bool, dict]]]c              
     s   t | }tt}t| D ]@ |D ]}z|j  }W n	 ty#   Y qw  nqz|j}W n	 ty5   Y qw |	 D ]\}}|| 
 fdd|D  q:q|S )zAdd in the decorated processors

        By doing this after constructing the class, we let standard inheritance
        do all the hard work.
        c                 3  s    | ]
\}} ||fV  qd S r[   r$   )r&   manykwargs	attr_namer$   r)   r3      s    
z+SchemaMeta.resolve_hooks.<locals>.<genexpr>)r5   r6   r   rP   dirr2   KeyError__marshmallow_hook__AttributeErrorr+   extend)r`   r;   hooksparentattrhook_configtagconfigr$   rd   r)   r^      s.   

zSchemaMeta.resolve_hooks)rC   rD   rE   rF   r,   rG   r"   r/   )
r.   r/   rI   r#   rJ   r#   rK   rZ   r"   rB   )r"   ra   )__name__
__module____qualname____doc____annotations__rO   classmethodrS   rR   r\   r^   __classcell__r$   r$   rX   r)   r/   W   s   
 +c                   @  s   e Zd ZdZd
dddZd	S )
SchemaOptsz/Defines defaults for `marshmallow.Schema.Meta`.FrU   r=   rH   boolc                 C  s|  t |dd| _t| jttfstdt |dd| _t| jttfs&td| jr0| jr0tdt |dd| _t| jttfsCtdt |d	d | _t |d
d | _	t |dd | _
t|drltjdtdd t |dt}nt}t |d|| _t|drtjdtdd t |d|| _t |dd| _t |di | _t |dd| _t |dd| _tt |dt| _t |dd| _t |dd| _d S )Nr   r$   z(`fields` option must be a list or tuple.
additionalz,`additional` option must be a list or tuple.zFCannot set both `fields` and `additional` options for the same Schema.excludez"`exclude` must be a list or tuple.
dateformatdatetimeformat
timeformatjson_modulezKThe json_module class Meta option is deprecated. Use render_module instead.   
stacklevelrender_modulerH   zThe `ordered` `class Meta` option is deprecated. Field order is already preserved by default. Set `Schema.dict_class` to OrderedDict to maintain the previous behavior.index_errorsTrQ   	load_only	dump_onlyunknownr]   rb   F)r1   r   
isinstancerP   tuple
ValueErrorrz   r{   r|   r}   r~   rM   warningswarnr    jsonr   rH   r   rQ   r   r   r   r   r   r]   rb   )selfrU   rH   r   r$   r$   r)   r\      sN   

zSchemaOpts.__init__N)F)rU   r=   rH   ry   )rq   rr   rs   rt   r\   r$   r$   r$   r)   rx      s    rx   c                   @  sf  e Zd ZU dZeejeejej	ej
eejeejeejeejeejeejejejejejejejejejejejiZde d< i Z!de d< dddZ"de d	< e#Z$d
e d< e%Z&de d< i Z'de d< i Z(de d< G dd dZ)ddddddddddd%d&Z*dd)d*Z+e,dd,d-Z-e.d.d/dd3d4Z/dd9d:Z0dd>d?Z1e2dd@dAdBZ3dCdDddEdFZ4ddDddGdHZ5ddDddIdJZ6dCde7ddKddPdQZ8ddddRddSdTZ9ddddRddWdXZ:dd@dd^d_Z;ddd`ddbdcZ<ddddddeddgdhZ=ddjdkZ>ddldmZ?ddndoZ@ddsdtZAddudvZBddwddydzZCdd{d|ZDdd}d~ZEdCddddZFddwdddZGdS )Schemaa  Base schema class with which to define schemas.

    Example usage:

    .. code-block:: python

        import datetime as dt
        from dataclasses import dataclass

        from marshmallow import Schema, fields


        @dataclass
        class Album:
            title: str
            release_date: dt.date


        class AlbumSchema(Schema):
            title = fields.Str()
            release_date = fields.Date()


        album = Album("Beggars Banquet", dt.date(1968, 12, 6))
        schema = AlbumSchema()
        data = schema.dump(album)
        data  # {'release_date': '1968-12-06', 'title': 'Beggars Banquet'}

    :param only: Whitelist of the declared fields to select when
        instantiating the Schema. If None, all fields are used. Nested fields
        can be represented with dot delimiters.
    :param exclude: Blacklist of the declared fields to exclude
        when instantiating the Schema. If a field appears in both `only` and
        `exclude`, it is not used. Nested fields can be represented with dot
        delimiters.
    :param many: Should be set to `True` if ``obj`` is a collection
        so that the object will be serialized to a list.
    :param context: Optional context passed to :class:`fields.Method` and
        :class:`fields.Function` fields.
    :param load_only: Fields to skip during serialization (write-only fields)
    :param dump_only: Fields to skip during deserialization (read-only fields)
    :param partial: Whether to ignore missing fields and not require
        any fields declared. Propagates down to ``Nested`` fields as well. If
        its value is an iterable, only missing fields listed in that iterable
        will be ignored. Use dot delimiters to specify nested fields.
    :param unknown: Whether to exclude, include, or raise an error for unknown
        fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.

    .. versionchanged:: 3.0.0
        `prefix` parameter removed.
    zdict[type, type[Field]]TYPE_MAPPINGzdict[str, str]error_messageszInvalid input type.zUnknown field.)r=   r   _default_error_messagesr=   rA   r?   r@   rB   r0   ra   r_   c                   @  s   e Zd ZU dZded< 	 ded< 	 ded< 	 ded< 	 ded	< 	 d
ed< 	 d
ed< 	 d
ed< 	 ded< 	 ded< 	 ded< 	 ded< 	 ded< 	 d
ed< 	 ded< dS )zSchema.Metaa)  Options object for a Schema.

        Example usage: ::

            from marshmallow import Schema


            class MySchema(Schema):
                class Meta:
                    fields = ("id", "email", "date_created")
                    exclude = ("password", "secret_attribute")

        .. admonition:: A note on type checking

            Type checkers will only check the attributes of the `Meta <marshmallow.Schema.Meta>`
            class if you explicitly subclass `marshmallow.Schema.Meta`.

            .. code-block:: python

                from marshmallow import Schema


                class MySchema(Schema):
                    # Not checked by type checkers
                    class Meta:
                        additional = True


                class MySchema2(Schema):
                    # Type checkers will check attributes
                    class Meta(Schema.Opts):
                        additional = True  # Incompatible types in assignment

        .. versionremoved:: 3.0.0b7 Remove ``strict``.
        .. versionadded:: 3.0.0b12 Add `unknown`.
        .. versionchanged:: 3.0.0b17 Rename ``dateformat`` to `datetimeformat`.
        .. versionadded:: 3.9.0 Add `timeformat`.
        .. versionchanged:: 3.26.0 Deprecate `ordered`. Field order is preserved by default.
        z,typing.ClassVar[tuple[str, ...] | list[str]]r   rz   z!typing.ClassVar[dict[str, Field]]rQ   r{   ztyping.ClassVar[bool]rb   ztyping.ClassVar[str]r|   r}   r~   r?   r   rH   r   r   r   r   r]   N)rq   rr   rs   rt   ru   r$   r$   r$   r)   r>   Z  s@   
 (r>   Nr$   )onlyr{   rb   contextr   r   partialr   r   types.StrSequenceOrSet | Noner{   types.StrSequenceOrSetrb   bool | Noner   dict | Noner   r   r   $bool | types.StrSequenceOrSet | Noner   
str | Nonec                C  sL  |d urt |stdt |stdt| j| _|d u r#| jjn|| _|| _t	| jj
t	|B | _
| jj| _t	|pBt	| jj| _t	|pMt	| jj| _|| _|d u rZ| jjnt|| _|ritjdtdd |pli | _|   i | _i | _i | _|   i }	|	| j t| jjD ]}
|	t|
di  q|	| j pi  |	| _ d S )Nz""only" should be a list of stringsz%"exclude" should be a list of stringszThe `context` parameter is deprecated and will be removed in marshmallow 4.0. Use `contextvars.ContextVar` to pass context instead.r   r   r   )!r   r   copydeepcopyr0   declared_fieldsr@   rb   r   setr{   rH   r   r   r   r   r   r   r   r    r   _normalize_nested_optionsr   load_fieldsdump_fields_init_fieldsupdater   reversedrY   __mro__r1   r   )r   r   r{   rb   r   r   r   r   r   messagesr`   r$   r$   r)   r\     sL   


zSchema.__init__r"   rD   c                 C  s   d| j j d| j dS )N<z(many=z)>)rY   rq   rb   r   r$   r$   r)   __repr__  s   zSchema.__repr__rZ   c                 C  s   | j rtS tS )z'`dict` type to return when serializing.)rH   r   rS   r   r$   r$   r)   
dict_class  s   zSchema.dict_classGeneratedSchema)rC   r   rC   type[Schema]c                C  s8   t dt| dtfddi}t || fi | d|iS )a  Generate a `Schema <marshmallow.Schema>` class given a dictionary of fields.

        .. code-block:: python

            from marshmallow import Schema, fields

            PersonSchema = Schema.from_dict({"name": fields.Str()})
            print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

        Generated schemas are not added to the class registry and therefore cannot
        be referred to by name in `Nested` fields.


        :param fields: Dictionary mapping field names to field instances.
        :param name: Optional name for the class, which will appear in
            the ``repr`` for the class.

        .. versionadded:: 3.0.0
        GeneratedMetar>   r]   F)r=   r1   objectr   )r`   r   rC   r>   r$   r$   r)   	from_dict  s   zSchema.from_dicterrorr   datary   c                K     dS )a  Custom error handler function for the schema.

        :param error: The `ValidationError` raised during (de)serialization.
        :param data: The original input data.
        :param many: Value of ``many`` on dump or load.
        :param partial: Value of ``partial`` on load.

        .. versionchanged:: 3.0.0rc9
            Receives `many` and `partial` (on deserialization) as keyword arguments.
        Nr$   )r   r   r   rb   rc   r$   r$   r)   handle_error  s    zSchema.handle_errorobjrm   defaultc                 C  s   t |||S )zDefines how to pull values from an object to serialize.

        .. versionchanged:: 3.0.0a1
            Changed position of ``obj`` and ``attr``.
        )r   )r   r   rm   r   r$   r$   r)   get_attribute$  s   zSchema.get_attributeindexc             
   C  sP   z| |}W |S  t y' } z|j|j||d |jptW  Y d}~S d}~ww )a  Call ``getter_func`` with ``data`` as its argument, and store any `ValidationErrors`.

        :param getter_func: Function for getting the serialized/deserialized
            value from ``data``.
        :param data: The data passed to ``getter_func``.
        :param field_name: Field name.
        :param index: Index of the item being validated, if validating a collection,
            otherwise `None`.
        r   N)r   store_errorr   
valid_datar   )getter_funcr   r'   error_storer   valuer   r$   r$   r)   _call_and_store.  s   
zSchema._call_and_storeFrb   c                  sv   |r|dur fdd|D S    } j D ] \}}|j|| jd}|tu r*q|jdur2|jn|}|||< q|S )zSerialize ``obj``.

        :param obj: The object(s) to serialize.
        :param many: `True` if ``data`` should be serialized as a collection.
        :return: A dictionary of the serialized data
        Nc                   s   g | ]	} j |d dqS )Fr   )
_serialize)r&   dr   r$   r)   r*   J      z%Schema._serialize.<locals>.<listcomp>)accessor)r   r   r+   	serializer   r   data_key)r   r   rb   retre   	field_objr   keyr$   r   r)   r   B  s   
zSchema._serializec                C  sf   |du r| j nt|}| jt r| jt|||d}n|}| j||d}| jt r1| jt|||d}|S )a  Serialize an object to native Python data types according to this
        Schema's fields.

        :param obj: The object to serialize.
        :param many: Whether to serialize `obj` as a collection. If `None`, the value
            for `self.many` is used.
        :return: Serialized data

        .. versionadded:: 1.0.0
        .. versionchanged:: 3.0.0b7
            This method returns the serialized data rather than a ``(data, errors)`` duple.
            A :exc:`ValidationError <marshmallow.exceptions.ValidationError>` is raised
            if ``obj`` is invalid.
        .. versionchanged:: 3.0.0rc9
            Validation no longer occurs upon serialization.
        N)rb   original_datar   )rb   ry   r_   r   _invoke_dump_processorsr   r   )r   r   rb   processed_objresultr$   r$   r)   dumpT  s   

zSchema.dumpc                O  s*   | j ||d}| jjj|g|R i |S )a+  Same as :meth:`dump`, except return a JSON-encoded string.

        :param obj: The object to serialize.
        :param many: Whether to serialize `obj` as a collection. If `None`, the value
            for `self.many` is used.
        :return: A ``json`` string

        .. versionadded:: 1.0.0
        .. versionchanged:: 3.0.0b7
            This method returns the serialized data rather than a ``(data, errors)`` duple.
            A :exc:`ValidationError <marshmallow.exceptions.ValidationError>` is raised
            if ``obj`` is invalid.
        r   )r   r@   r   dumps)r   r   rb   argsrc   
serializedr$   r$   r)   r   v  s   zSchema.dumps)rb   r   r   r   Rtyping.Mapping[str, typing.Any] | typing.Iterable[typing.Mapping[str, typing.Any]]r   r   typing.Any | list[typing.Any]c                  s  j j}|r|nd}|r/t sjjd g|d g }|S fddt D }|S  }	t tsEjjd g|d |	S t}
j	
 D ]i\}}|jdurZ|jn|} |t}|tu rqdu sp|
rq|v rqqNi }|
r|d tfddD }||d	< ndur|d	< |||f fd
d	}j||||d}|tur|jp|}t|	|| qNtkrdd j	
 D }t | D ]"} | }tkr||	|< q̈tkrjd g||r|nd q|	S )a  Deserialize ``data``.

        :param data: The data to deserialize.
        :param error_store: Structure to store errors.
        :param many: `True` if ``data`` should be deserialized as a collection.
        :param partial: Whether to ignore missing fields and not require
            any fields declared. Propagates down to ``Nested`` fields as well. If
            its value is an iterable, only missing fields listed in that iterable
            will be ignored. Use dot delimiters to specify nested fields.
        :param unknown: Whether to exclude, include, or raise an error for unknown
            fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
        :param index: Index of the item being serialized (for storing errors) if
            serializing a collection, otherwise `None`.
        :return: The deserialized data as `dict_class` instance or list of `dict_class`
        instances if `many` is `True`.
        Nr=   r   c              
     s.   g | ]\}}j tt| d |dqS )F)r   rb   r   r   r   )_deserializetypingcastrS   )r&   idxr   )r   r   r   r   r$   r)   r*     s    	
z'Schema._deserialize.<locals>.<listcomp>T.c                   s"   g | ]}| r| d  qS r[   )
startswith)r&   f)
len_prefixprefixr$   r)   r*     s
    

r   c                   s   |j | | fi |S r[   )deserialize)valr   r'   d_kwargs)r   r$   r)   getter  s   z#Schema._deserialize.<locals>.getterr   r   r'   r   r   c                 S  s$   h | ]\}}|j d ur|j n|qS r[   r   )r&   r'   r   r$   r$   r)   	<setcomp>      z&Schema._deserialize.<locals>.<setcomp>r   )r@   r   r   r   r   	enumerater   r   r   r   r+   r   rL   r   lenr   	attributer   r   r   r   r   )r   r   r   rb   r   r   r   r   ret_lret_dpartial_is_collectionre   r   r'   	raw_valuer   sub_partialr   r   r   r   r$   )r   r   r   r   r   r   r   r)   r     s   	
=





zSchema._deserializerb   r   r   c                C  s   | j ||||ddS )aR  Deserialize a data structure to an object defined by this Schema's fields.

        :param data: The data to deserialize.
        :param many: Whether to deserialize `data` as a collection. If `None`, the
            value for `self.many` is used.
        :param partial: Whether to ignore missing fields and not require
            any fields declared. Propagates down to ``Nested`` fields as well. If
            its value is an iterable, only missing fields listed in that iterable
            will be ignored. Use dot delimiters to specify nested fields.
        :param unknown: Whether to exclude, include, or raise an error for unknown
            fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
            If `None`, the value for `self.unknown` is used.
        :return: Deserialized data

        .. versionadded:: 1.0.0
        .. versionchanged:: 3.0.0b7
            This method returns the deserialized data rather than a ``(data, errors)`` duple.
            A :exc:`ValidationError <marshmallow.exceptions.ValidationError>` is raised
            if invalid data are passed.
        Trb   r   r   postprocess)_do_load)r   r   rb   r   r   r$   r$   r)   load  s   
zSchema.load	json_datastr | bytes | bytearrayc                K  s(   | j jj|fi |}| j||||dS )a  Same as :meth:`load`, except it uses `marshmallow.Schema.Meta.render_module` to deserialize
        the passed string before passing data to :meth:`load`.

        :param json_data: A string of the data to deserialize.
        :param many: Whether to deserialize `obj` as a collection. If `None`, the
            value for `self.many` is used.
        :param partial: Whether to ignore missing fields and not require
            any fields declared. Propagates down to ``Nested`` fields as well. If
            its value is an iterable, only missing fields listed in that iterable
            will be ignored. Use dot delimiters to specify nested fields.
        :param unknown: Whether to exclude, include, or raise an error for unknown
            fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
            If `None`, the value for `self.unknown` is used.
        :return: Deserialized data

        .. versionadded:: 1.0.0
        .. versionchanged:: 3.0.0b7
            This method returns the deserialized data rather than a ``(data, errors)`` duple.
            A :exc:`ValidationError <marshmallow.exceptions.ValidationError>` is raised
            if invalid data are passed.
        r   )r@   r   loadsr   )r   r   rb   r   r   rc   r   r$   r$   r)   r     s   zSchema.loadsvalidator_functypes.SchemaValidatorpass_originalr   
int | Nonec                C  s   z|r|||||d W d S ||||d W d S  t yi }	 zF|	j}
|
tkr)t}n,d }z| j|
 }W n tyE   |
| jv rC| j|
 }Y nw |rS|jd urP|jn|
}n|
}|j|	j||d W Y d }	~	d S d }	~	ww )N)r   rb   r   )	r   r'   r   r   rg   r   r   r   r   )r   r   outputr   r   rb   r   r   r   errr'   r   r   r$   r$   r)   _run_validator=  s2   


 zSchema._run_validatorrb   r   dict[str, list[str]]c             
   C  sX   z| j |||dd W i S  ty+ } zttttt f |jW  Y d}~S d}~ww )a  Validate `data` against the schema, returning a dictionary of
        validation errors.

        :param data: The data to validate.
        :param many: Whether to validate `data` as a collection. If `None`, the
            value for `self.many` is used.
        :param partial: Whether to ignore missing fields and not require
            any fields declared. Propagates down to ``Nested`` fields as well. If
            its value is an iterable, only missing fields listed in that iterable
            will be ignored. Use dot delimiters to specify nested fields.
        :return: A dictionary of validation errors.

        .. versionadded:: 1.1.0
        F)rb   r   r   N)r   r   r   r   rS   rD   rP   r   )r   r   rb   r   excr$   r$   r)   validated  s   &zSchema.validateTr   r   c             
   C  s  t  }i }|du r| jnt|}|du r| jnt|}|du r"| j}| jt rLz| jt||||d}W n t	yK }	 z|	
 }d}
W Y d}	~	nd}	~	ww |}|s| j|||||d}
| j||
|d | jt rt|j}| j|d|
||||d | j|d|
||||d |j}|s|r| jt rz| jt|
|||d}
W n t	y }	 z
|	
 }W Y d}	~	nd}	~	ww |rt	|||
d}| j||||d	 ||
S )
ar  Deserialize `data`, returning the deserialized result.
        This method is private API.

        :param data: The data to deserialize.
        :param many: Whether to deserialize `data` as a collection. If `None`, the
            value for `self.many` is used.
        :param partial: Whether to validate required fields. If its
            value is an iterable, only fields listed in that iterable will be
            ignored will be allowed missing. If `True`, all fields will be allowed missing.
            If `None`, the value for `self.partial` is used.
        :param unknown: Whether to exclude, include, or raise an error for unknown
            fields in the data. Use `EXCLUDE`, `INCLUDE` or `RAISE`.
            If `None`, the value for `self.unknown` is used.
        :param postprocess: Whether to run post_load methods..
        :return: Deserialized data
        N)rb   r   r   )r   rb   r   r   )r   r   rb   T)r   	pass_manyr   r   rb   r   field_errorsF)r   r   r   )r   rb   ry   r   r   r   r_   r   _invoke_load_processorsr   normalized_messagesr   _invoke_field_validatorsr   errors_invoke_schema_validatorsr   r   )r   r   rb   r   r   r   r   r  processed_datar   r   r  r   r$   r$   r)   r     s   




		
zSchema._do_loadNonec                 C  sh   | j dur| d| j d | dd | j D | _ | jr2| d| jd | dd | jD | _dS dS )	zVApply then flatten nested schema options.
        This method is private API.
        Nr   intersectionc                 S  s   g | ]
}| d dd qS )r      r   splitr&   fieldr$   r$   r)   r*     s    z4Schema._normalize_nested_options.<locals>.<listcomp>r{   unionc                 S  s   g | ]}d |vr|qS )r   r$   r  r$   r$   r)   r*     s    )r   _Schema__apply_nested_option	set_classr{   r   r$   r$   r)   r     s   

z Schema._normalize_nested_optionsc                 C  s   dd |D }t t}|D ]\}}|| | qt| D ]3\}}	| |	}
t| j| |d}|rI|dkr>|
| |O }
|dkrI|
| |M }
t| j| ||
 qdS )z%Apply nested options to nested fieldsc                 S  s    g | ]}d |v r| d dqS )r   r
  r  )r&   rC   r$   r$   r)   r*          z0Schema.__apply_nested_option.<locals>.<listcomp>r$   r  r	  N)	r   rP   appenditerr+   r  r1   r   setattr)r   option_namefield_namesset_operationnested_fieldsnested_optionsrl   nested_namesr   optionsnew_optionsoriginal_optionsr$   r$   r)   __apply_nested_option  s   
zSchema.__apply_nested_optionc                   s  | j jr| | j j}n| | j }| j jr!|| | j jO }|  }| jdur7| | j}||| O }n|}| jrH|| j }|| j| O }|rWd|  d| d}t|| 	 }|D ]}| j
|t }| || |||< q]| 	 | 	 }}	| D ]\}}|js|||< |js||	|< qdd |	 D  t tt kr fdd D }
td	t|
 d
d | D tttkr݇fddD }tdt| || _|	| _|| _dS )zUpdate self.fields, self.load_fields, and self.dump_fields based on schema options.
        This method is private API.
        NzInvalid fields for z: r   c                 S  s$   g | ]\}}|j d ur|j n|qS r[   r   )r&   rC   r   r$   r$   r)   r*   <  r   z'Schema._init_fields.<locals>.<listcomp>c                      h | ]}  |d kr|qS r
  countr&   x)dump_data_keysr$   r)   r   A      z&Schema._init_fields.<locals>.<setcomp>zThe data_key argument for one or more fields collides with another field's name or data_key argument. Check the following field names and data_key arguments: c                 S  s   g | ]	\}}|j p
|qS r$   )r   )r&   rC   r   r$   r$   r)   r*   J  r   c                   r   r!  r"  r$  )load_attributesr$   r)   r   L  r'  zThe attribute argument for one or more fields collides with another field's name or attribute argument. Check the following field names and attribute arguments: )r@   r   r  r   keysrz   r   r{   r   r   rL   	ma_fieldsInferred_bind_fieldr+   r   r   r   r   rP   r   r   )r   available_field_namesinvalid_fieldsr  messagefields_dictr'   r   r   r   data_keys_duplicatesattributes_duplicatesr$   )r&  r(  r)   r     sj   





zSchema._init_fieldsr'   r   r!   c                 C  r   )zqHook to modify a field when it is bound to the `Schema <marshmallow.Schema>`.

        No-op by default.
        Nr$   )r   r'   r   r$   r$   r)   on_bind_fieldZ  s   zSchema.on_bind_fieldc              
   C  s   || j v rd|_ || jv rd|_z|||  W n' ty? } zt|tr:t|tjr:d| d|j	 d}t|| d}~ww | 
|| dS )zBind field to the schema, setting any necessary attributes on the
        field (e.g. parent and name).

        Also set field load_only and dump_only values if field_name was
        specified in `class Meta <marshmallow.Schema.Meta>`.
        TzField for "zJ" must be declared as a Field instance, not a class. Did you mean "fields.z()"?N)r   r   _bind_to_schema	TypeErrorr   r=   
issubclassr   r%   rq   r3  )r   r'   r   r   msgr$   r$   r)   r,  a  s"   


zSchema._bind_field)r   ro   c                C  s(   | j |d|||d}| j |d|||dS )NF)r   r   rb   r   T_invoke_processors)r   ro   r   rb   r   r$   r$   r)   r   |  s   

zSchema._invoke_dump_processorsc                C  s,   | j |d||||d}| j |d||||dS )NT)r   r   rb   r   r   Fr8  )r   ro   r   rb   r   r   r$   r$   r)   r    s    zSchema._invoke_load_processorsc                C  sN  | j t D ]\}}}t| |}|d }z| j| }	W n  ty: }
 z|| jv r-W Y d }
~
qtd| d|
d }
~
ww |	jd urC|	jn|}|r~t|D ]1\}}z	||	j	pU| }W n	 tya   Y qKw | j
||||| jjrn|nd d}|tu r|||d  qKqz	||	j	p| }W n	 ty   Y qw | j
||||d}|tu r||d  qd S )Nr'   "z" field does not exist.r   )r   r   r'   r   )r_   r   r1   r   rg   r   r   r   r   r   r   r@   r   r   pop)r   r   r   rb   re   rW   validator_kwargs	validatorr'   r   r   r   r   itemr   validated_valuer$   r$   r)   r    s\   

zSchema._invoke_field_validators)r  r   r  c                C  s   | j t D ]H\}}	}
|	|krqt| |}|r|
d rq|
dd}|rA|sAtt||D ]\}\}}| j||||||||d q,q| j|||||||d qd S )Nskip_on_field_errorsr   F)r   r   rb   r   r   r   )r   r   rb   r   r   )r_   r   r1   rL   r   zipr   )r   r   r   r   r   rb   r   r  re   	hook_manyr<  r=  r   r   r>  origr$   r$   r)   r    s<   
z Schema._invoke_schema_validatorsc                  s   | j | D ]N\}}}	||krqt| ||	dd}
r;|s;|
r/ fddt||D }q fdd|D }q|
rI||fdi }q|fdi }q|S )Nr   Fc                   s&   g | ]\}}||fd i qS r   r$   )r&   r>  originalrc   rb   	processorr$   r)   r*     s    z-Schema._invoke_processors.<locals>.<listcomp>c                   s    g | ]}|fd i qS r   r$   )r&   r>  rE  r$   r)   r*     r  rb   )r_   r1   rL   r   )r   ro   r   r   rb   r   rc   re   rB  processor_kwargsr   r$   rE  r)   r9    s   

zSchema._invoke_processors)r   r   r{   r   rb   r   r   r   r   r   r   r   r   r   r   r   )r"   rD   )r"   rZ   )r   rB   rC   rD   r"   r   )r   r   r   r?   rb   ry   )r   r?   rm   rD   r   r?   )r   r?   rb   ry   )r   r?   rb   r   )r   r   r   r   rb   ry   r"   r   )r   r   rb   r   r   r   r   r   )r   r   rb   r   r   r   r   r   )r   r   r   r   rb   ry   r   r   r   ry   r   r   )r   r   rb   r   r   r   r"   r   )
r   r   rb   r   r   r   r   r   r   ry   )r"   r  )r'   rD   r   r!   r"   r  )ro   rD   rb   ry   )ro   rD   rb   ry   r   r   )r   r   rb   ry   )
r   r   r   ry   rb   ry   r   r   r  ry   )ro   rD   r   ry   rb   ry   )Hrq   rr   rs   rt   rD   r*  StringbytesdtdatetimeDateTimefloatFloatry   Booleanr   RawrP   r   intIntegeruuidUUIDtimeTimedateDate	timedelta	TimeDeltadecimalDecimalr   ru   r   r   rx   rA   r   r  r0   r_   r>   r\   r   propertyr   rv   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r  r   r3  r,  r   r  r  r  r9  r$   r$   r$   r)   r     s   
 5^
6
 

"y'+.'
g


K


71r   )	metaclass)r"   r#   )r.   r/   )Brt   
__future__r   r   rK  rJ  r[  r7   r5   r   r9   r   rS  r   abcr   collectionsr   r   collections.abcr   	itertoolsr   marshmallowr   r	   r
   r   r*  marshmallow.decoratorsr   r   r   r   r   r   marshmallow.error_storer   marshmallow.exceptionsr   r   r   marshmallow.orderedsetr   marshmallow.utilsr   r   r   r   r   r   r   r   r   marshmallow.warningsr    TYPE_CHECKINGmarshmallow.fieldsr!   r-   r<   r/   rx   	SchemaABCr   
BaseSchemar$   r$   r$   r)   <module>   sP     ,

}0        !