a
    ]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j8rLddl9m:Z: ddddZ;d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list[tuple[str, Field]]returnc                 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_nameZfield_valuer%   r%   `/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/marshmallow/schema.py
<listcomp>7   s   z_get_fields.<locals>.<listcomp>)items)attrsr%   r%   r)   _get_fields2   s    r-   
SchemaMeta)klassc                 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                      s   e Zd ZU dZded< ded< ded< ded< d	d
dd d fddZeefd dddddddZ fddZ	d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   strztuple[type, ...]zdict[str, typing.Any])namebasesr,   r$   c                   s   | d}t|dd}|sJ|D ]&}t|drt|jdr|jj} qJqd}t|}|D ]\}}	||= qVt | |||}
t|
}|
j}|
j	||d|
_
|t|
j
j 7 }| j|
||td|
_|
S )Nr>   orderedF)rF   )r/   
cls_fieldsinherited_fieldsdict_cls)getr1   hasattrr>   rF   r-   super__new__r<   rA   r@   listincluder+   get_declared_fieldsdictr0   )mcsrD   rE   r,   metarF   Zbase_rG   r(   _r/   rH   	__class__r%   r)   rM   c   s.    
zSchemaMeta.__new__r"   
type[dict])r/   rG   rH   rI   r$   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%   )rR   r/   rG   rH   rI   r%   r%   r)   rP      s    zSchemaMeta.get_declared_fieldsc                   s6   t  ||| |r(| jjr(t||  |  | _d S N)rL   __init__r@   registerr	   resolve_hooks_hooks)clsrD   rE   r,   rU   r%   r)   rY      s    zSchemaMeta.__init__'dict[str, list[tuple[str, bool, dict]]]r#   c              
     s   t | }tt}t| D ] |D ].}z|j  }W n tyJ   Y q"Y q"0  qTq"qz
|j}W n typ   Y q0 |	 D ]$\}}|| 
 fdd|D  qzq|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 rX   r%   )r'   manykwargs	attr_namer%   r)   r3      s   z+SchemaMeta.resolve_hooks.<locals>.<genexpr>)r5   r6   r   rN   dirr2   KeyErrorZ__marshmallow_hook__AttributeErrorr+   extend)r]   r;   hooksparentattrZhook_configtagconfigr%   ra   r)   r[      s(    

zSchemaMeta.resolve_hooks)__name__
__module____qualname____doc____annotations__rM   classmethodrQ   rP   rY   r[   __classcell__r%   r%   rU   r)   r.   W   s   
+c                   @  s"   e Zd ZdZd	dddddZdS )

SchemaOptsz/Defines defaults for `marshmallow.Schema.Meta`.Fr=   bool)rS   rF   c                 C  s~  t |dd| _t| jttfs&tdt |dd| _t| jttfsLtd| jr`| jr`tdt |dd| _t| jttfstdt |d	d | _t |d
d | _	t |dd | _
t|drtjdtdd t |dt}nt}t |d|| _t|drt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
timeformatZjson_modulezKThe json_module class Meta option is deprecated. Use render_module instead.   
stacklevelrender_modulerF   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_errorsTrO   	load_only	dump_onlyunknownrZ   r_   F)r1   r   
isinstancerN   tuple
ValueErrorru   rv   rw   rx   ry   rK   warningswarnr    jsonr}   rF   r~   rO   r   r   r   r   r   rZ   r_   )selfrS   rF   r}   r%   r%   r)   rY      sN    
zSchemaOpts.__init__N)F)rl   rm   rn   ro   rY   r%   r%   r%   r)   rs      s   rs   c                   @  s0  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dddddddddddZ*dd d!d"Z+e,d#d d$d%Z-e.d&d'ddd(d)d*d+Z/d,dd-d.d/d0Z0dddd1d2d3Z1e2dd4d5d6Z3d7d8dd-d9d:d;Z4dd8ddd9d<d=Z5dd8ddd9d>d?Z6d7de7dd@dAdBd-dCdDdEdFZ8ddddGdAddddHdIdJZ9ddddGdKddddLdMdNZ:dd4dOdBd-dd-dPdQdRdSZ;dddTdAdddUdVdWdXZ<ddddYdZdAdddd-d[d\d]Z=d^d d_d`Z>d^d dadbZ?d^d dcddZ@dded^dfdgdhZAdded^dfdidjZBddkdd-dldmdnZCdd-ddodpdqZDdBd-drdsdtZEd7dudBd-d-dd-dvdwdxZFddkdd-d-dydzd{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   r^   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   ru   z!typing.ClassVar[dict[str, Field]]rO   rv   ztyping.ClassVar[bool]r_   ztyping.ClassVar[str]rw   rx   ry   r?   r}   rF   r~   r   r   r   rZ   N)rl   rm   rn   ro   rp   r%   r%   r%   r)   r>   Z  s"   
(r>   Nr%   )onlyrv   r_   contextr   r   partialr   ztypes.StrSequenceOrSet | Noneztypes.StrSequenceOrSetzbool | Nonezdict | Nonez$bool | types.StrSequenceOrSet | Nonez
str | Nonec                C  sP  |d urt |stdt |s(tdt| j| _|d u rF| jjn|| _|| _t	| jj
t	|B | _
| jj| _t	|pt	| jj| _t	|pt	| jj| _|| _|d u r| jjnt|| _|rtjdtdd |pi | _|   i | _i | _i | _|   i }	|	| j t| jjD ]}
|	t|
di  q|	| j pBi  |	| _ 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.rz   r{   r   )!r   r   copydeepcopyr0   declared_fieldsr@   r_   r   setrv   rF   r   r   r   r   r   r   r   r    r   _normalize_nested_optionsr   load_fieldsdump_fields_init_fieldsupdater   reversedrV   __mro__r1   r   )r   r   rv   r_   r   r   r   r   r   messagesr]   r%   r%   r)   rY     sL    


zSchema.__init__rC   r#   c                 C  s   d| j j d| j dS )N<z(many=z)>)rV   rl   r_   r   r%   r%   r)   __repr__  s    zSchema.__repr__rW   c                 C  s   | j r
tS tS )z'`dict` type to return when serializing.)rF   r   rQ   r   r%   r%   r)   
dict_class  s    zSchema.dict_classZGeneratedSchema)rD   ztype[Schema])r   rD   r$   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
        ZGeneratedMetar>   rZ   F)r=   r1   objectr   )r]   r   rD   r>   r%   r%   r)   	from_dict  s    zSchema.from_dictr   rt   )errordatar_   c                K  s   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   r_   r`   r%   r%   r)   handle_error  s    zSchema.handle_error)objri   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   ri   r   r%   r%   r)   get_attribute$  s    zSchema.get_attributeindexc             
   C  sR   z| |}W n@ t yL } z(|j|j||d |jp6tW  Y d}~S d}~0 0 |S )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r_   )r   r_   c                  sv   |r|dur fdd|D S    } j D ]@\}}|j|| jd}|tu rTq0|jdurd|jn|}|||< q0|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   r_   retrb   	field_objr   keyr%   r   r)   r   B  s    
zSchema._serializec                C  sf   |du r| j nt|}| jt r4| jt|||d}n|}| j||d}| jt rb| 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)r_   original_datar   )r_   rt   r\   r   _invoke_dump_processorsr   r   )r   r   r_   Z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   r_   argsr`   Z
serializedr%   r%   r)   r   v  s    zSchema.dumps)r_   r   r   r   zRtyping.Mapping[str, typing.Any] | typing.Iterable[typing.Mapping[str, typing.Any]]r   ztyping.Any | list[typing.Any])r   r   r_   r$   c                  s  j j}|r|nd}|r\t s<jjd g|d g }nfddt D }|S  }	t tsjjd g|d ndt}
j	
 D ]\}}|jdur|jn|} |t}|tu rdu s|
r|v rqi }|
r|d tfddD }||d	< ndur*|d	< |||f fd
d	}j||||d}|tur|jpd|}t|	|| qtkrdd j	
 D }t | D ]L} | }tkr||	|< n*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   r_   r   r   r   )_deserializetypingcastrQ   )r'   idxr   )r   r   r   r   r%   r)   r*     s   	
z'Schema._deserialize.<locals>.<listcomp>T.c                   s"   g | ]}| r| d  qS rX   )
startswith)r'   f)
len_prefixprefixr%   r)   r*     s   r   c                   s   |j | | fi |S rX   )Z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 rX   r   )r'   r(   r   r%   r%   r)   	<setcomp>  s   z&Schema._deserialize.<locals>.<setcomp>r   )r@   r~   r   r   r   	enumerater   r   r   r   r+   r   rJ   r   lenr   	attributer   r   r   r   r   )r   r   r   r_   r   r   r   r~   Zret_lZret_dZpartial_is_collectionrb   r   r(   Z	raw_valuer   Zsub_partialr   r   r   r   r%   )r   r   r   r   r   r   r   r)   r     s|    	








zSchema._deserializer_   r   r   )r   r_   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r_   r   r   postprocess)_do_load)r   r   r_   r   r   r%   r%   r)   load  s    
zSchema.loadzstr | bytes | bytearray)	json_datar_   r   r   c                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   r_   r   r   r`   r   r%   r%   r)   r     s    zSchema.loadsztypes.SchemaValidatorz
int | None)validator_funcr   r_   r   pass_originalr   c                C  s   z(|r|||||d n||||d W n t y }	 z|	j}
|
tkrLt}nXd }z| j|
 }W n& ty   |
| jv r| j|
 }Y n0 |r|jd ur|jn|
}n|
}|j|	j||d W Y d }	~	n
d }	~	0 0 d S )N)r   r_   r   )	r   r(   r   r   rd   r   r   r   r   )r   r   outputr   r   r_   r   r   r   errr(   r   r   r%   r%   r)   _run_validator=  s*    
zSchema._run_validatorr_   r   zdict[str, list[str]])r   r_   r   r$   c             
   C  sZ   z| j |||dd W n> tyT } z&ttttt f |jW  Y d}~S d}~0 0 i S )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)r_   r   r   N)r   r   r   r   rQ   rC   rN   r   )r   r   r_   r   excr%   r%   r)   validated  s
    0zSchema.validateTr   )r   r_   r   r   r   c             
   C  s  t  }i }|du r| jnt|}|du r.| jnt|}|du rD| j}| jt rz| jt||||d}W q t	y }	 z|	
 }d}
W Y d}	~	qd}	~	0 0 n|}|st| j|||||d}
| j||
|d | jt rt|j}| j|d|
||||d | j|d|
||||d |j}|st|rt| jt rtz| jt|
|||d}
W n. t	yr }	 z|	
 }W Y d}	~	n
d}	~	0 0 |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)r_   r   r   )r   r_   r   r   )r   r   r_   T)r   	pass_manyr   r   r_   r   field_errorsF)r   r   r   )r   r_   rt   r   r   r   r\   r   _invoke_load_processorsr   Znormalized_messagesr   _invoke_field_validatorsr   errors_invoke_schema_validatorsr   r   )r   r   r_   r   r   r   r   r   Zprocessed_datar   r   r   r   r%   r%   r)   r     s    



		
zSchema._do_loadNonec                 C  sd   | j dur2| d| j d | dd | j D | _ | jr`| d| jd | dd | jD | _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*     r   z4Schema._normalize_nested_options.<locals>.<listcomp>rv   unionc                 S  s   g | ]}d |vr|qS )r   r%   r   r%   r%   r)   r*     r   )r   _Schema__apply_nested_option	set_classrv   r   r%   r%   r)   r     s    
z Schema._normalize_nested_optionsc                 C  s   dd |D }t t}|D ]\}}|| | qt| D ]f\}}	| |	}
t| j| |d}|r|dkr||
| |O }
|dkr|
| |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'   rD   r%   r%   r)   r*     r   z0Schema.__apply_nested_option.<locals>.<listcomp>r%   r   r   N)	r   rN   appenditerr+   r   r1   r   setattr)r   Zoption_namefield_namesZset_operationZnested_fieldsZnested_optionsrh   Znested_namesr   optionsnew_optionsZoriginal_optionsr%   r%   r)   Z__apply_nested_option  s    
zSchema.__apply_nested_optionc                   s  | j jr| | j j}n*| | j }| j jrB|| | j jO }|  }| jdurn| | j}||| O }n|}| jr|| j }|| j| O }|rd|  d| d}t|| 	 }|D ]*}| j
|t }| || |||< q| 	 | 	  }}	| D ]*\}}|js|||< |js ||	|< q dd |	 D  t tt krx 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 rX   r   )r'   rD   r   r%   r%   r)   r*   <  s   z'Schema._init_fields.<locals>.<listcomp>c                   s   h | ]}  |d kr|qS r   countr'   x)dump_data_keysr%   r)   r   A  s   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'   rD   r   r%   r%   r)   r*   J  r   c                   s   h | ]}  |d kr|qS r   r   r   )load_attributesr%   r)   r   L  s   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   keysru   r   rv   r   r   rJ   	ma_fieldsZInferred_bind_fieldr+   r   r   r   r   rN   r   r   )r   Zavailable_field_namesZinvalid_fieldsr   messageZfields_dictr(   r   r   r   Zdata_keys_duplicatesZattributes_duplicatesr%   )r   r   r)   r     sh    




zSchema._init_fieldsr!   )r(   r   r$   c                 C  s   dS )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 nZ ty } zBt|trtt|tjrtd| d|j	 d}t|| W Y d}~n
d}~0 0 | 
|| 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   Z_bind_to_schema	TypeErrorr   r=   
issubclassr   r&   rl   r  )r   r(   r   r   msgr%   r%   r)   r   a  s    


zSchema._bind_field)r   )rj   r_   c                C  s(   | j |d|||d}| j |d|||dS )NF)r   r   r_   r   T_invoke_processors)r   rj   r   r_   r   r%   r%   r)   r   |  s    

zSchema._invoke_dump_processors)rj   r_   r   c                C  s,   | j |d||||d}| j |d||||dS )NT)r   r   r_   r   r   Fr  )r   rj   r   r_   r   r   r%   r%   r)   r     s     zSchema._invoke_load_processors)r   r_   c                C  sb  | j t D ]P\}}}t| |}|d }z| j| }	W nL ty }
 z4|| jv r\W Y d }
~
q
td| d|
W Y d }
~
n
d }
~
0 0 |	jd ur|	jn|}|rt|D ]b\}}z||	j	p| }W n ty   Y q0 | j
||||| jjr|nd d}|tu r||d  qq
z||	j	p| }W n ty4   Y q
0 | j
||||d}|tu r
||d  q
d S )Nr(   "z" field does not exist.r   )r   r   r(   r   )r\   r   r1   r   rd   r   r   r   r   r   r   r@   r~   r   pop)r   r   r   r_   rb   rT   validator_kwargs	validatorr(   r   r   r   r   itemr   Zvalidated_valuer%   r%   r)   r     sL    

(zSchema._invoke_field_validators)r   )r   r   r_   r   r   c                C  s   | j t D ]\}}	}
|	|krq
t| |}|r6|
d r6q
|
dd}|r|stt||D ]&\}\}}| j||||||||d qXq
| j|||||||d q
d S )NZskip_on_field_errorsr   F)r   r   r_   r   r   r   )r   r   r_   r   r   )r\   r   r1   rJ   r   zipr   )r   r   r   r   r   r_   r   r   rb   	hook_manyr
  r  r   r   r  origr%   r%   r)   r     s8    

z Schema._invoke_schema_validators)rj   r   r_   c                  s   | j | D ]\}}}	||krq
t| ||	dd}
rv|sv|
r^ fddt||D }q fdd|D }q
|
r||fdi }q
|fdi }q
|S )Nr   Fc                   s&   g | ]\}}||fd i qS r   r%   )r'   r  originalr`   r_   	processorr%   r)   r*     s   z-Schema._invoke_processors.<locals>.<listcomp>c                   s    g | ]}|fd i qS r   r%   )r'   r  r  r%   r)   r*     r   r_   )r\   r1   rJ   r   )r   rj   r   r   r_   r   r`   rb   r  Zprocessor_kwargsr   r%   r  r)   r    s    

zSchema._invoke_processors)Hrl   rm   rn   ro   rC   r   StringbytesdtdatetimeDateTimefloatFloatrt   Booleanr   ZRawrN   r   intIntegeruuidUUIDtimeZTimedateDate	timedeltaZ	TimeDeltadecimalDecimalr   rp   r   r   rs   rA   r   r   r0   r\   r>   rY   r   propertyr   rq   r   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r  r%   r%   r%   r)   r     s   
5^ 6 
"y'+.'gK71r   )	metaclass)Bro   
__future__r   r   r  r  r#  r7   r5   r   r9   r   r  r   abcr   collectionsr   r   collections.abcr   	itertoolsr   Zmarshmallowr   r	   r
   r   r   Zmarshmallow.decoratorsr   r   r   r   r   r   Zmarshmallow.error_storer   Zmarshmallow.exceptionsr   r   r   Zmarshmallow.orderedsetr   Zmarshmallow.utilsr   r   r   r   r   r   r   r   r   Zmarshmallow.warningsr    TYPE_CHECKINGZmarshmallow.fieldsr!   r-   r<   r.   rs   Z	SchemaABCr   Z
BaseSchemar%   r%   r%   r)   <module>   sN    ,}0        !