Viewing File: /opt/alt/python35/lib/python3.5/site-packages/cerberus/__pycache__/validator.cpython-35.pyc



LX@swdZddlmZddlmZddlmZmZmZm	Z	ddl
m
Z
ddlmZmZddl
Z
ddlmZdd	lmZdd
lmZmZddlmZmZmZmZddlmZmZejZd
dZGddde Z!Gddde Z"Gddde#Z$dZ%Gddde&Z'e'de$fiZ$dS)a

    Extensible validation for Python dictionaries.
    This module implements Cerberus Validator class

    :copyright: 2012-2016 by Nicola Iarocci.
    :license: ISC, see LICENSE for more details.

    Full documentation is available at http://python-cerberus.org
)absolute_import)literal_eval)HashableIterableMappingSequence)copy)datedatetimeN)warn)errors)
_int_types	_str_type)schema_registryrules_set_registryDefinitionSchemaSchemaError)drop_item_from_tupleisclasscCsdd}|}||_|S)NcSstddS)NzcDummy method called. Its purpose is to hold justvalidation constraints for a rule in its docstring.)RuntimeError)self
constraintfieldvaluer
/validator.pydummysz(dummy_for_rule_validation.<locals>.dummy)__doc__)Zrule_constraintsrfrrrdummy_for_rule_validations	rc@seZdZdZdS)
DocumentErrorzD Raised when the target document is missing or has the wrong format N)__name__
__module____qualname__rrrrrr (sr c@seZdZdZdS)_SchemaRuleTypeErrorzs Raised when a schema (list) validation encounters a mapping.
        Not supposed to be used outside this module. N)r!r"r#rrrrrr$-sr$c@s8eZdZdZdZdZeZddZddZ	d	d
Z
eddZd
dZ
ddddZddZddZddZddZddZeddZejddZedd Zed!d"Zejd#d"Zed$d%Zed&d'Zejd(d'Zed)d*Zejd+d*Zed,d-Zed.d/Zed0d1Zejd2d1Zed3d4Zed5d6Z e jd7d6Z ed8d9Z!e!jd:d9Z!dd;d<Z"dd=d>d?Z#d@dAZ$dBdCZ%dDdEZ&dFdGZ'dHdIZ(dJdKZ)dLdMZ*dNdOZ+e,dPdQZ-dRdSZ.dTdUZ/dVdWZ0dXdYZ1dZd[Z2d\d]Z3d^d_Z4dd=d`dadbZ5e5Z6dcddZ7dedfZ8dgdhZ9e:diZ;djdkZ<dldmZ=dndoZ>dpdqZ?drdsZ@dtduZAdvdwZBdxdyZCdzd{ZDd|d}ZEd~dZFddZGddZHddZIddZJddZKddZLddZMddZNddZOddZPe:dZQddZRddZSddZTddZUddZVddZWddZXddZYddZZddZ[ddZ\ddZ]ddZ^ddZ_ddZ`ddZaddZbddZcdS)	Validatora6 Validator class. Normalizes and/or validates any mapping against a
    validation-schema which is provided as an argument at class instantiation
    or upon calling the :meth:`~cerberus.Validator.validate`,
    :meth:`~cerberus.Validator.validated` or
    :meth:`~cerberus.Validator.normalized` method. An instance itself is
    callable and executes a validation.

    All instantiation parameters are optional.

    There are the introspective properties :attr:`types`, :attr:`validators`,
    :attr:`coercers`, :attr:`default_setters`, :attr:`rules`,
    :attr:`normalization_rules` and :attr:`validation_rules`.

    The attributes reflecting the available rules are assembled considering
    constraints that are defined in the docstrings of rules' methods and is
    effectively used as validation schema for :attr:`schema`.

    :param schema: See :attr:`~cerberus.Validator.schema`.
                   Defaults to :obj:`None`.
    :type schema: any :term:`mapping`
    :param ignore_none_values: See :attr:`~cerberus.Validator.ignore_none_values`.
                               Defaults to ``False``.
    :type ignore_none_values: :class:`bool`
    :param allow_unknown: See :attr:`~cerberus.Validator.allow_unknown`.
                          Defaults to ``False``.
    :type allow_unknown: :class:`bool` or any :term:`mapping`
    :param purge_unknown: See :attr:`~cerberus.Validator.purge_unknown`.
                          Defaults to to ``False``.
    :type purge_unknown: :class:`bool`
    :param error_handler: The error handler that formats the result of
                          :attr:`~cerberus.Validator.errors`.
                          When given as two-value tuple with an error-handler
                          class and a dictionary, the latter is passed to the
                          initialization of the error handler.
                          Default: :class:`~cerberus.errors.BasicErrorHandler`.
    :type error_handler: class or instance based on
                         :class:`~cerberus.errors.BaseErrorHandler` or
                         :class:`tuple`
    nullablereadonlytypecOsd|_tj|_d|_tj|_tj|_f|_	f|_
d|_|j||_
|j|||jdd|_|jdd|_dS)z The arguments will be treated as with this signature:

        __init__(self, schema=None, ignore_none_values=False,
                 allow_unknown=False, purge_unknown=False,
                 error_handler=errors.BasicErrorHandler)
        NFschema
allow_unknown)documentr	ErrorList_errorsrecent_errorDocumentErrorTreedocument_error_treeSchemaErrorTreeschema_error_tree
document_pathschema_pathupdate_Validator__init_error_handler
error_handler_Validator__store_configgetr)r*)rargskwargsrrr__init__hs					zValidator.__init__cCs|jdtj}t|tr3|\}}ni}t|rat|tjra||St|tjrw|StddS)Nr7zInvalid error_handler.)	poprZBasicErrorHandler
isinstancetupler
issubclassZBaseErrorHandlerr)rr;r7Z	eh_configrrrZ__init_error_handlers
zValidator.__init_error_handlercCsmd}xWt|dt|D]9\}}||krNtd|q#||||<q#W||_dS)z0 Assign args to kwargs and store configuration. r)ignore_none_valuesr*
purge_unknownNz.__init__ got multiple values for argument '%s')zschemazignore_none_valuesz
allow_unknownz
purge_unknown)	enumeratelen	TypeError_config)rr:r;Z	signatureiprrrZ__store_configs)
	zValidator.__store_configcCs|jjdS)z) Purge the cache of known valid schemas. N)_valid_schemasclear)clsrrrclear_cachesszValidator.clear_cachescGst|dkry|jj|d|jjx|dD]4}|j|7_|j|7_|jj|q>Wnlt|dkrt|dt	r|j
|dtj|dn&t|dkr|d}|dj
}|dj}|dd}|j|f}|j}|tjj
krL|dk	rL|||f7}|s[d}	nA|j|j|}
|dkr|
j|d}	n
|
|}	|jj|}tj|||||	|||_|j
|jgdS)a Creates and adds one or multiple errors.

        :param args: Accepts different argument's signatures.

                     *1. Bulk addition of errors:*

                     - :term:`iterable` of
                       :class:`~cerberus.errors.ValidationError`-instances

                     The errors will be added to
                     :attr:`~cerberus.Validator._errors`.

                     *2. Custom error:*

                     - the invalid field's name

                     - the error message

                     A custom error containing the message will be created and
                     added to :attr:`~cerberus.Validator._errors`.
                     There will however be fewer information contained in the
                     error (no reference to the violated rule and its
                     constraint).

                     *3. Defined error:*

                     - the invalid field's name

                     - the error-reference, see :mod:`cerberus.errors`

                     - arbitrary, supplemental information about the error

                     A :class:`~cerberus.errors.ValidationError` instance will
                     be created and added to
                     :attr:`~cerberus.Validator._errors`.
        rNr&F)rDr-extendsortr0r2r7emitr>r_errorrZCUSTOMcoderuler3r4
UNKNOWN_FIELD_resolve_rules_setr)r9r+ZValidationErrorr.)rr:errorrrSrTinfor3r4rZfield_definitionsrrrrrRs8%
%!


		
zValidator._errorNcKs|jj}|j||js`d|d<t|d<|j|d<|j|d<|j|d<|j|}|dkr|j	|_	n(t
|ts|f}|j	||_	|dkr|j|_n(t
|ts|f}|j||_|S)a@ Creates a new instance of Validator-(sub-)class. All initial
            parameters of the parent are passed to the initialization, unless
            a parameter is given as an explicit *keyword*-parameter.

        :param document_crumb: Extends the
                               :attr:`~cerberus.Validator.document_path`
                               of the child-validator.
        :type document_crumb: :class:`tuple` or :term:`hashable`
        :param schema_crumb: Extends the
                             :attr:`~cerberus.Validator.schema_path`
                             of the child-validator.
        :type schema_crumb: :class:`tuple` or hashable
        :param kwargs: Overriding keyword-arguments for initialization.
        :type kwargs: :class:`dict`

        :return: an instance of ``self.__class__``
        Tis_childr7root_allow_unknown
root_documentroot_schemaN)
rFrr5rYtoy_error_handlerr*r+r)	__class__r3r>r?r4)rdocument_crumbschema_crumbr;Zchild_configZchild_validatorrrr_get_child_validators(
	




		zValidator._get_child_validatorcCs.dj||jdd}t||dS)Nz_{0}_{1} _)formatreplacegetattr)rZdomainrTZ
methodnamerrrZ__get_rule_handler,szValidator.__get_rule_handlercCst|j}t|j}x|D]}x3t|ddD]}t|j|||_q>Wx3t|ddD]}t|j|||_qtW|jr%|j|j||q%WdS)a Removes nodes by index from an errorpath, relatively to the
            basepaths of self.

        :param errors: A list of :class:`errors.ValidationError` instances.
        :param dp_items: A list of integers, pointing at the nodes to drop from
                         the :attr:`document_path`.
        :param sp_items: Alike ``dp_items``, but for :attr:`schema_path`.
        reverseTN)rDr3r4sortedrZchild_errors_drop_nodes_from_errorpaths)rr-Zdp_itemsZsp_itemsZdp_basedepthZsp_basedepthrWrGrrrri0s	
	z%Validator._drop_nodes_from_errorpathscCs|jdrC|dd}|jdr7|jn|j}n	|j}|jd}x-|D]%}|j|}|dkrbdSqbW|d|fS)a Searches for a field as defined by path. This method is used by the
            ``dependency`` evaluation logic.

        :param path: Path elements are separated by a ``.``. A leading ``^``
                     indicates that the path relates to the document root,
                     otherwise it relates to the currently evaluated document,
                     which is possibly a subdocument.
                     The sequence ``^^`` at the start will be interpreted as a
                     literal ``^``.
        :type path: :class:`str`
        :returns: Either the found field name and its value or :obj:`None` for
                  both.
        :rtype: A two-value :class:`tuple`.
        ^rMN.)NN)
startswithr+r[splitr9)rpathcontextpartspartrrr
_lookup_fieldFs	
zValidator._lookup_fieldcCs6t|tr|St|tr2|jj|SdS)N)r>rrrr9)rZ	rules_setrrrrVds
zValidator._resolve_rules_setcCs6t|tr|St|tr2|jj|SdS)N)r>rrrr9)rr)rrr_resolve_schemaks
zValidator._resolve_schemacCs|jjddS)a: If ``True`` unknown fields that are not defined in the schema will
            be ignored. If a mapping with a validation schema is given, any
            undefined field will be validated against its rules.
            Also see :ref:`allowing-the-unknown`.
            Type: :class:`bool` or any :term:`mapping` r*F)rFr9)rrrrr*tszValidator.allow_unknowncCsB|jpt|ttfs1t|d|i||jd<dS)Nr*)rYr>boolrrF)rrrrrr*}scCs|j|jS)z The errors of the last processing formatted by the handler that is
            bound to :attr:`~cerberus.Validator.error_handler`. )r7r-)rrrrrszValidator.errorscCs|jjddS)za Whether to not process :obj:`None`-values in a document or not.
            Type: :class:`bool` rAF)rFr9)rrrrrAszValidator.ignore_none_valuescCs||jd<dS)NrA)rF)rrrrrrAscCs|jjddS)z ``True`` for child-validators obtained with
        :meth:`~cerberus.Validator._get_child_validator`.
        Type: :class:`bool` rYF)rFr9)rrrrrYszValidator.is_childcCs|jjddS)z1 ``True`` if the document is already normalized. 
is_normalizedF)rFr9)rrrrrvszValidator.is_normalizedcCs||jd<dS)Nrv)rF)rrrrrrvscCs|jjddS)z If ``True`` unknown fields will be deleted from the document
            unless a validation is called with disabled normalization.
            Also see :ref:`purging-unknown-fields`. Type: :class:`bool` rBF)rFr9)rrrrrBszValidator.purge_unknowncCs||jd<dS)NrB)rF)rrrrrrBscCs|jjd|jS)zw The :attr:`~cerberus.Validator.allow_unknown` attribute of the
            first level ancestor of a child validator. rZ)rFr9r*)rrrrrZszValidator.root_allow_unknowncCs|jjd|jS)zr The :attr:`~cerberus.Validator.document` attribute of the
            first level ancestor of a child validator. r[)rFr9r+)rrrrr[szValidator.root_documentcCs|jjdtS)z^ The registry that holds referenced rules sets.
            Type: :class:`~cerberus.Registry` r)rFr9r)rrrrrszValidator.rules_set_registrycCs||jd<dS)Nr)rF)rregistryrrrrscCs|jjd|jS)zp The :attr:`~cerberus.Validator.schema` attribute of the
            first level ancestor of a child validator. r\)rFr9r))rrrrr\szValidator.root_schemacCs|jS)z The validation schema of a validator. When a schema is passed to
            a method, it replaces this attribute.
            Type: any :term:`mapping` or :obj:`None` )_schema)rrrrr)szValidator.schemacCsR|dkrd|_n6|js0t|tr<||_nt|||_dS)N)rxrYr>r)rr)rrrr)s
cCs|jjdtS)zW The registry that holds referenced schemas.
        Type: :class:`~cerberus.Registry` r)rFr9r)rrrrrszValidator.schema_registrycCs||jd<dS)Nr)rF)rrwrrrrscCstj|_d|_tj|_tj|_t||_	|dk	rft
|||_n<|jdkrt|j
tri|_nttj|dkrttjt|tsttjj||jj|dS)N)rr,r-r.r/r0r1r2rr+rr)r>r*rrxrZSCHEMA_ERROR_MISSINGr ZDOCUMENT_MISSINGZDOCUMENT_FORMATrdr7start)rr+r)rrrZ__init_processings"	zValidator.__init_processingFcCsU|j|||j|j|j|jj||jrJ|rJdS|jSdS)a Returns the document normalized according to the specified rules
        of a schema.

        :param document: The document to normalize.
        :type document: any :term:`mapping`
        :param schema: The validation schema. Defaults to :obj:`None`. If not
                       provided here, the schema must have been provided at
                       class instantiation.
        :type schema: any :term:`mapping`
        :param always_return_document: Return the document, even if an error
                                       occurred. Defaults to: ``False``.
        :type always_return_document: :class:`bool`
        :return: A normalized copy of the provided mapping or :obj:`None` if an
                 error occurred during normalization.
        N)_Validator__init_processing_Validator__normalize_mappingr+r)r7endr-)rr+r)always_return_documentrrr
normalizedszValidator.normalizedcCst|tr|j|}|j}x%|D]}|j||||<q1W|j|||jr{|j|||j|||j	|||j
|||j|||S)N)r>rrtrrV#_Validator__normalize_rename_fieldsrB_normalize_purge_unknown$_Validator__validate_readonly_fields$_Validator__normalize_default_fields_normalize_coerce _Validator__normalize_containers)rmappingr)rrrrZ__normalize_mappings
	zValidator.__normalize_mappingcCstj}x|D]}||kr]d||kr]|j||d||||||<qt|jtrd|jkr|j|jd||||||<qWdS)a {'oneof': [
                {'type': 'callable'},
                {'type': 'list',
                 'schema': {'oneof': [{'type': 'callable'},
                                      {'type': 'string'}]}},
                {'type': 'string'}
                ]} coerceN)rCOERCION_FAILED_Validator__normalize_coercer>r*r)rrr)rWrrrrr(s		
%zValidator._normalize_coercecCst|tr$|jd|}nht|tr|}xL|D]D}|j||||}tj|jj|j	|fkr@Pq@W|Sy||SWnBt
k
r}z"|j||t||SWYdd}~XnXdS)NZnormalize_coerce)
r>r_Validator__get_rule_handlerrrrrr0fetch_errors_fromr3	ExceptionrRstr)rZ	processorrrrWresultrHerrrZ__normalize_coerce;s 
	zValidator.__normalize_coercecCs%x|D]}||krqt||trd||krZ|j||||dd||kr|j||||dt||td@ry|j|||Wqtk
rYqXqt||trqqt||trd||kr|j	|||qWdS)N	keyschemavalueschemar*rBr))z
allow_unknownz
purge_unknownzschema)
r>r+_Validator__normalize_mapping_per_keyschema-_Validator__normalize_mapping_per_valueschemaset(_Validator__normalize_mapping_per_schemar$rr_Validator__normalize_sequence)rrr)rrrrZ__normalize_containersOs,


z Validator.__normalize_containersc	s[tfdd||D}tdd||D}|jd|d|dfd|}|j|dd	}|jr|j|jgd
dg|j|jx|D]}|||krq||||kr.tdjd
dj|j	|fd||||||||<q|||||||<|||=qWdS)Nc3s|]}|fVqdS)Nr).0k)property_rulesrr	<genexpr>isz>Validator.__normalize_mapping_per_keyschema.<locals>.<genexpr>css|]}||fVqdS)Nr)rrrrrrjsr_r`rr)r}TrNzHNormalizing keys of {path}: {key} already exists, its value is replaced.rorkkey)
dictrar~r-rirRrrdjoinr3)	rrrrr)r+	validatorrrr)rrZ!__normalize_mapping_per_keyschemahs&#			

z+Validator.__normalize_mapping_per_keyschemacstfdd||D}|jd|d|dfd|}|j||dd||<|jr|j|jgd	g|j|jdS)
Nc3s|]}|fVqdS)Nr)rr)value_rulesrrrsz@Validator.__normalize_mapping_per_valueschema.<locals>.<genexpr>r_r`rr)r}TrN)rrar~r-rirR)rrrrr)rr)rrZ#__normalize_mapping_per_valueschemas#		
	z-Validator.__normalize_mapping_per_valueschemac
Cs|jd|d|dfd||dd||jd|jd||jd|j}|j||dd||<|jr|j|jdS)Nr_r`r)r*rBr}T)rar9r*rBr~r-rR)rrrr)rrrrZ__normalize_mapping_per_schemas	
	z(Validator.__normalize_mapping_per_schemacstfddtt|Dtddt|D}|jdddfd}|j|dd}x |D]}||||<qW|jr|j|jgd	g|j|jdS)
Nc3s#|]}|dfVqdS)r)Nr)rr)rr)rrrsz1Validator.__normalize_sequence.<locals>.<genexpr>css!|]\}}||fVqdS)Nr)rrvrrrrsr_r`r)r}TrN)	rrangerDrCrar~r-rirR)rrrr)r+rrrGr)rr)rZ__normalize_sequences#		
	zValidator.__normalize_sequencecCs.x't|D]}||kr
||=q
W|S)z {'type': 'boolean'} )r?)rr)rrrrrsz"Validator._normalize_purge_unknowncCsxt|D]x}||krH|j||||j|||q
t|jtr
d|jkr
|j|||ji|q
W|S)Nrename_handler)r?_normalize_rename_normalize_rename_handlerr>r*r)rrr)rrrrZ__normalize_rename_fieldssz#Validator.__normalize_rename_fieldscCs1d||kr-|||||d<||=dS)z {'type': 'hashable'} renameNr)rrr)rrrrrszValidator._normalize_renamecCs\d||krdS|j||d||tj}||krX||||<||=dS)a {'oneof': [
                {'type': 'callable'},
                {'type': 'list',
                 'schema': {'oneof': [{'type': 'callable'},
                                      {'type': 'string'}]}},
                {'type': 'string'}
                ]} rN)rrZRENAMING_FAILED)rrr)rnew_namerrrrsz#Validator._normalize_rename_handlercsMxFfddDD]%}j|d||q WdS)Nc3s=|]3}|krj|jdr|VqdS)r'N)rVr9)rx)rr)rrrrsz7Validator.__validate_readonly_fields.<locals>.<genexpr>r')_validate_readonly)rrr)rr)rr)rrZ__validate_readonly_fieldss&z$Validator.__validate_readonly_fieldsc	sfddD}yfdd|D}Wntk
rStYnXx!|D]}|j|q[Wt}fdd|D}x|r~|jd}y|j|Wn_tk
r|j|YnAtk
r*}z!|j	|t
jt|WYdd}~XnXt
|}||krnx$|D]}|j	|t
jdqJWPq|j|qWdS)NcsIg|]?}|ks?|dkr|jddr|qS)Nr&F)r9)rr)rr)rr
<listcomp>s	z8Validator.__normalize_default_fields.<locals>.<listcomp>cs&g|]}d|kr|qS)defaultr)rr)r)rrrs	cs&g|]}d|kr|qS)default_setterr)rr)r)rrrs	rz)Circular dependencies of default setters.)rEr$_normalize_defaultrr=_normalize_default_setterKeyErrorappendrrRrZSETTING_DEFAULT_FAILEDrr?add)	rrr)fieldsZfields_with_defaultrZknown_fields_statesrZfields_stater)rr)rZ__normalize_default_fieldss0

		
/
z$Validator.__normalize_default_fieldscCs||d||<dS)z {'nullable': True} rNr)rrr)rrrrrszValidator._normalize_defaultcCsSd||krO||d}t|tr?|jd|}||||<dS)zi {'oneof': [
                {'type': 'callable'},
                {'type': 'string'}
                ]} rZnormalize_default_setterN)r>rr)rrr)rsetterrrrrs		z#Validator._normalize_default_setterTcCs||_t|_|j|||rJ|j|j|jd|_xn|jD]c}|jry|j|dkryqT|jj	|}|dk	r|j
||qT|j|qTW|js|j|j|j
j|t|jS)aO Normalizes and validates a mapping against a validation-schema of
        defined rules.

        :param document: The document to normalize.
        :type document: any :term:`mapping`
        :param schema: The validation schema. Defaults to :obj:`None`. If not
                       provided here, the schema must have been provided at
                       class instantiation.
        :type schema: any :term:`mapping`
        :param update: If ``True``, required fields won't be checked.
        :type update: :class:`bool`
        :param normalize: If ``True``, normalize the document before validation.
        :type normalize: :class:`bool`

        :return: ``True`` if validation succeeds, otherwise ``False``. Check
                 the :func:`errors` property for a list of processing errors.
        :rtype: :class:`bool`
        TN)r5r_unrequired_by_excludesrzr{r+r)rvrAr9 _Validator__validate_definitions#_Validator__validate_unknown_fields$_Validator__validate_required_fieldsr7r|rur-)rr+r)r5	normalizerdefinitionsrrrvalidates"			zValidator.validatecOsA|jdd}|j|||jr6|r6dS|jSdS)z Wrapper around :meth:`~cerberus.Validator.validate` that returns
            the normalized and validated document or :obj:`None` if validation
            failed. r}FN)r=rr-r+)rr:r;r}rrr	validated0s
zValidator.validatedcCs|jr|j|}t|jttfr|jr=dnd}|jd|d||ji}|||idds|j|jn|j|t	j
dS)Nr*Z__allow_unknown__r`r)rF)r*r+r>rrrYrarRr-rrU)rrrr`rrrrZ__validate_unknown_fields;s	
	z#Validator.__validate_unknown_fieldscsfdd}jjtfddjD}x|D]}||rcdSqcWt}|tjO}|t|d8}|tj8}x2|D]*}y||Wqtk
rPYqXqWdS)	z5 Validate a field's value against its defined rules. cs8jd|}|r4|j|dSdS)Nr)rr9)rTr)rrrrrr
validate_ruleQsz7Validator.__validate_definitions.<locals>.validate_rulec3s0|]&}|ks$|jkr|VqdS)N)mandatory_validations)rr)rrrrrZsz3Validator.__validate_definitions.<locals>.<genexpr>Nr*required)z
allow_unknownzrequired)rVr+r?priority_validationsrrnormalization_rulesr$)rrrrZprior_rulesrTrulesr)rrrrrZ__validate_definitionsNs 
%


z Validator.__validate_definitionsz {'oneof': [{'type': 'boolean'},
                       {'type': ['dict', 'string'],
                        'validator': 'bulk_schema'}]} cCst|trZt|trZt|t|}|r||j|tjt|n"||kr||j|tj|dS)z {'type': 'list'} N)	r>rrrrRrZUNALLOWED_VALUESlistZUNALLOWED_VALUE)rZallowed_valuesrrZ	unallowedrrr_validate_allowedpszValidator._validate_allowedcCst|tr|g}t|tr:|j||nt|trY|j|||jj|j|dfdk	rdSdS)z- {'type': ['dict', 'hashable', 'hashables']} dependenciesNT)	r>rr*_Validator__validate_dependencies_sequencer)_Validator__validate_dependencies_mappingr0Zfetch_node_fromr4)rrrrrrr_validate_dependencieszs		z Validator._validate_dependenciesc	Csd}i}x|jD]u\}}t|tsDt|trM|g}|j|\}}||kr{|d7}q|j||iqW|t|kr|j|tj	|dS)NrrM)
itemsr>rrrsr5rDrRrZDEPENDENCIES_FIELD_VALUE)	rrrZvalidated_dependencies_counterZ
error_infoZdependency_nameZdependency_valuesZwanted_fieldZwanted_field_valuerrrZ__validate_dependencies_mappings	
z)Validator.__validate_dependencies_mappingcCsDx=|D]5}|j|ddkr|j|tj|qWdS)Nr)rsrRrZDEPENDENCIES_FIELD)rrrZ
dependencyrrrZ __validate_dependencies_sequences
z*Validator.__validate_dependencies_sequencecCs?t|tr;t|dkr;|r;|j|tjdS)z {'type': 'boolean'} rN)r>rrDrRrZEMPTY_NOT_ALLOWED)remptyrrrrr_validate_emptys(zValidator._validate_emptycst|tr|g}dj|krLj|drLjj|xQ|D]I}|jkrSdj|krSj|drSjj|qSWfdd|Drdjdd|D}j|tj|dS)z% {'type': ['hashable', 'hashables']} rcs%g|]}|jkrdqS)T)r+)rr)rrrrs	z0Validator._validate_excludes.<locals>.<listcomp>z, css|]}dj|VqdS)z'{0}'N)rd)rZwordrrrrsz/Validator._validate_excludes.<locals>.<genexpr>N)	r>rr)rrrrRrZEXCLUDES_FIELD)rZexcludesrrexcludeZ
exclusion_strr)rr_validate_excludess	$

zValidator._validate_excludescCst|tr4||kr|j|tj|n{t|tr~t|t|@}|r|j|tjt|n1t|t	r||kr|j|tj|dS)z {'type': 'list'} N)
r>rrRrZFORBIDDEN_VALUErrZFORBIDDEN_VALUESrint)rZforbidden_valuesrrZ	forbiddenrrr_validate_forbiddenszValidator._validate_forbiddencCst|t|kr@|j|tjt|t|ntddt|D}|jd|d|dfd|}|tddt|Dd|jd	d
s|j|tj|j	dS)z( {'type': 'list', 'validator': 'items'} css!|]\}}||fVqdS)Nr)rrG
definitionrrrrsz,Validator._validate_items.<locals>.<genexpr>r_r`rr)css!|]\}}||fVqdS)Nr)rrGrrrrrsr5rFN)
rDrRrZITEMS_LENGTHrrCrar5Z	BAD_ITEMSr-)rrrvaluesr)rrrr_validate_itemss(	"zValidator._validate_itemscCs4d}tj}xt|D]\}}||ji}	xJdD]B}
|
|	|krD|
|j|krD|j||
|	||
<qDWd|	|kr|j|	|d<|jd|||fd|	dd}||jd|jdd	r|d
7}q|j	|j
gdg|j|j
qW||fS)
z` Validates value against all definitions and logs errors according
            to the operator. rr*r(r`r)Tr5rFrM)z
allow_unknownztype)rr,rCrr)r*rar+r5rir-rO)roperatorrrrZ
valid_counterr-rGrr)rTrrrrZ__validate_logicals"
#	
zValidator.__validate_logicalcCsP|jd|||\}}|dkrL|j|tj||t|dS)z& {'type': 'list', 'logical': 'anyof'} ZanyofrMN)_Validator__validate_logicalrRrZANYOFrD)rrrrvalidsr-rrr_validate_anyofszValidator._validate_anyofcCsV|jd|||\}}|t|krR|j|tj||t|dS)z& {'type': 'list', 'logical': 'allof'} ZallofN)rrDrRrZALLOF)rrrrrr-rrr_validate_allofszValidator._validate_allofcCsP|jd|||\}}|dkrL|j|tj||t|dS)z' {'type': 'list', 'logical': 'noneof'} ZnoneofrN)rrRrZNONEOFrD)rrrrrr-rrr_validate_noneofszValidator._validate_noneofcCsP|jd|||\}}|dkrL|j|tj||t|dS)z& {'type': 'list', 'logical': 'oneof'} oneofrMN)rrRrZONEOFrD)rrrrrr-rrr_validate_oneofszValidator._validate_oneofcCs<y#||kr"|j|tjWntk
r7YnXdS)z {'nullable': False } N)rRrZ	MAX_VALUErE)rZ	max_valuerrrrr
_validate_maxs

zValidator._validate_maxcCs<y#||kr"|j|tjWntk
r7YnXdS)z {'nullable': False } N)rRrZ	MIN_VALUErE)rZ	min_valuerrrrr
_validate_mins

zValidator._validate_mincCsAt|tr=t||kr=|j|tjt|dS)z {'type': 'integer'} N)r>rrDrRrZ
MAX_LENGTH)rZ
max_lengthrrrrr_validate_maxlengths!zValidator._validate_maxlengthcCsAt|tr=t||kr=|j|tjt|dS)z {'type': 'integer'} N)r>rrDrRrZ
MIN_LENGTH)rZ
min_lengthrrrrr_validate_minlength!s!zValidator._validate_minlengthcCs1|dkr-|rdS|j|tjdSdS)z {'type': 'boolean'} NT)rRrZNOT_NULLABLE)rr&rrrrr_validate_nullable&s
zValidator._validate_nullablec
st|tr|jd|d|dfdtfdd|jD}|tdd|jDdd	s|j|jgd
dg|j|tj	|jdS)
zq {'type': ['dict', 'string'], 'validator': 'bulk_schema',
            'forbidden': ['rename', 'rename_handler']} r_r`rr)c3s|]}|fVqdS)Nr)rr)r)rrr6sz0Validator._validate_keyschema.<locals>.<genexpr>css|]}||fVqdS)Nr)rrrrrr7srFrNrN)
r>rrarkeysrir-rRrZ	KEYSCHEMA)rr)rrrr)r)r_validate_keyschema/s	("	zValidator._validate_keyschemacCsb|r^|js&|j|tjdStj|jj|j|fk}|jr^|r^dSdS)z {'type': 'boolean'} TN)rvrRrZREADONLY_FIELDr0rr3)rr'rrZ	has_errorrrrr=s		zValidator._validate_readonlycCsat|tsdS|jds,|d7}tj|}|j|s]|j|tjdS)z {'type': 'string'} N$)	r>rendswithrecompilematchrRrZREGEX_MISMATCH)rpatternrrZre_objrrr_validate_regexLs
zValidator._validate_regexz {'type': 'boolean'} c
s)y,tfddjjD}Wn:tk
rhjrajddkratnYnX|j8}|tfddD}x!|D]}j|t	j
qWjr%tfddD}jj|r%x(j|D]}j|t	j
qWdS)	zq Validates that required fields are not missing.

        :param document: The document being validated.
        c3s9|]/\}}j|jddkr|VqdS)rTN)rVr9)rrr)rrrr^s	z7Validator.__validate_required_fields.<locals>.<genexpr>rMr)c3s4|]*}j|dk	s(jr|VqdS)N)r9rA)rr)r+rrrrgsc3s*|] }j|dk	r|VqdS)N)r9)rr)r+rrrqsNrl)rr)rAttributeErrorrYr4r$rrRrZREQUIRED_FIELD
isdisjoint)rr+rZmissingrrr)r+rrZ__validate_required_fieldsXs,
	
&
	z$Validator.__validate_required_fieldscCsk|dkrdSt|trEt|trE|j|||n"t|trg|j|||dS)z {'type': ['dict', 'string'],
             'anyof': [{'validator': 'schema'},
                       {'validator': 'bulk_schema'}]} N)r>rr$_Validator__validate_schema_sequencer#_Validator__validate_schema_mapping)rr)rrrrr_validate_schemawszValidator._validate_schemacCs|j|}|j|jd|j}|jd|d|dfd|d|}y/||d|jdds|j|jWn(tk
r|j|t	j
YnXdS)Nr*r_r`r)r5rF)rtr)r9r*rar5rRr-r$rZBAD_TYPE_FOR_SCHEMA)rrr)rr*rrrrZ__validate_schema_mappings	
z#Validator.__validate_schema_mappingc	stfddtt|D|jd|d|dfdd|j}|tddt|Dd|jd	d
|jr|j|jgdg|j	|t
j|jdS)Nc3s|]}|fVqdS)Nr)rrG)r)rrrsz7Validator.__validate_schema_sequence.<locals>.<genexpr>r_r`r)r*css!|]\}}||fVqdS)Nr)rrGrrrrrsr5rFrN)rrrDrar*rCr5r-rirRrZSEQUENCE_SCHEMA)rrr)rrr)r)rZ__validate_schema_sequences+	"	z$Validator.__validate_schema_sequencecs_t|tr|gn|}tfdd|DrDdSj|tjdSdS)z {'type': ['string', 'list']} c3s'|]}jd|VqdS)Z
validate_typeN)r)rr)rrrrrsz+Validator._validate_type.<locals>.<genexpr>NT)r>ranyrRrZBAD_TYPE)rZ	data_typerrtypesr)rrr_validate_types
zValidator._validate_typecCst|trdSdS)NT)r>ru)rrrrr_validate_type_booleansz Validator._validate_type_booleancCst|trdSdS)NT)r>r	)rrrrr_validate_type_dateszValidator._validate_type_datecCst|trdSdS)NT)r>r
)rrrrr_validate_type_datetimesz!Validator._validate_type_datetimecCst|trdSdS)NT)r>r)rrrrr_validate_type_dictszValidator._validate_type_dictcCst|ttfrdSdS)NT)r>floatr
)rrrrr_validate_type_floatszValidator._validate_type_floatcCst|trdSdS)NT)r>r
)rrrrr_validate_type_integersz Validator._validate_type_integercCst|ttfrdSdS)NT)r>bytes	bytearray)rrrrr_validate_type_binaryszValidator._validate_type_binarycCs't|tr#t|tr#dSdS)NT)r>rr)rrrrr_validate_type_lists
zValidator._validate_type_listcCs-t|ttfr)t|tr)dSdS)NT)r>r
rru)rrrrr_validate_type_numberszValidator._validate_type_numbercCst|trdSdS)NT)r>r)rrrrr_validate_type_setszValidator._validate_type_setcCst|trdSdS)NT)r>r)rrrrr_validate_type_stringszValidator._validate_type_stringcCs~t|tr1|jd|}|||nIt|trgx7|D]}|j|||qGWn||||jdS)a {'oneof': [
                {'type': 'callable'},
                {'type': 'list',
                 'schema': {'oneof': [{'type': 'callable'},
                                      {'type': 'string'}]}},
                {'type': 'string'}
                ]} rN)r>rrr_validate_validatorrR)rrrrrrrrrs
zValidator._validate_validatorc
s|df}t|tr|jd|d|dtfdd|D}||d|jdd	|jr|j|jgd
g|j|tj	|jdS)zq {'type': ['dict', 'string'], 'validator': 'bulk_schema',
            'forbidden': ['rename', 'rename_handler']} rr_r`r)c3s|]}|fVqdS)Nr)rr)r)rrrsz2Validator._validate_valueschema.<locals>.<genexpr>r5rFrNN)
r>rrarr5r-rirRrZVALUESCHEMA)rr)rrr`rr)r)r_validate_valueschemas	"	zValidator._validate_valueschema)nullable)rzreadonlyztype)dr!r"r#rrrrrIr<r6r8classmethodrLrRrarrirsrVrtpropertyr*rrrArYrvrBrZr[rr\r)rrzr~r{rrrrrrrstaticmethodrrrrrrrrr__call__rrrrZ_validate_allow_unknownrrrrrrrrrrrrrrrrrrrrrZ_validate_requiredrrrrrrrrrrrrrrrrrrrrrrr%3s'	*J.			+	


	

r%z7The rule's arguments are validated against this schema:csFeZdZdZfddZfddZddZS)InspectedValidatorz Metaclass for all validators csKd|dkr2|djd|ddjitt|j||S)NrrNrMr)r5rsuperr__new__)rKr:)r^rrrs"zInspectedValidator.__new__csfdd}ttj|fi__xb|dD]T}|jdrj|tddf7_qHjd|j|<qHWjjdd<tdd	|d
D_	jd
d}j	|dd
ddd<|dd<x/dd	j
DD]}dj|d<q'Wffi___
x|dD]}|jdrj|tddf7_ql|jdrj|tddf7_qljd|j
|<qlWxHdD]@}j
|d}j|dd
ddd<|dd<qWjj
dddd<i_jjjjjj
dS)Ncs#tfddtDS)Nc3s8|].}|jdr|jdddVqdS)rcrNrMNrl)rmrn)rr)prefixrrrszNInspectedValidator.__init__.<locals>.attributes_with_prefix.<locals>.<genexpr>)r?dir)r)rK)rrattributes_with_prefixsz;InspectedValidator.__init__.<locals>.attributes_with_prefixrZtype_Z
_validate_r(Zallowedcss|]}|VqdS)Nr)rrrrrrsz.InspectedValidator.__init__.<locals>.<genexpr>rrrMr)rNcss!|]}|dkr|VqdS)r&Nr)rrrrrrsTrrZcoerce_Zdefault_setter_Z_normalize_rrr)zcoercezrename_handler)rrr<rZvalidation_rulesrmrD$_InspectedValidator__get_rule_schemar?Z
validatorsrZcoercersZdefault_settersrrr5)rKr:r
Z	attributerrT)r^)rKrr<s6%")%%
-	zInspectedValidator.__init__c
Cst||j}|dkr'i}nPt|krF|jtd}yt|j}Wntk
rvi}YnX|std|jddd|S)NrMz>No validation schema is defined for the arguments of rule '%s'rcrNrl)rfrRULE_SCHEMA_SEPARATORrnrstriprr)rKZmethod_nameZ	docstringrrrrZ__get_rule_schema,s	
z$InspectedValidator.__get_rule_schema)r!r"r#rrr<rrr)r^rrs,r)(rZ
__future__rZastrcollectionsrrrrrr
r	rwarningsrZcerberusrZcerberus.platformr
rZcerberus.schemarrrrZcerberus.utilsrrZToyErrorHandlerr]rrr r$objectr%rr(rrrrr<module>	s.""
F
Back to Directory File Manager