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



LXK@sdZddlmZddlmZmZmZddlmZmZddl	m
Z
ddlmZddl
mZddlmZmZed	d
ZeddZeddZd
ZeddZeddZeddZeddZeddZeddZdZeddZeddZeddZeddZed d!Zed"d#Z ed$d%Z!ed&d'Z"ed(d)Z#ed*d+Z$ed,d-Z%ed.d-Z&ed/d0Z'ed1d0Z(ed2dZ)ed3d4Z*ed5d6Z+ed7d8Z,ed9d:Z-ed;dZ.ed<dZ/ed=dZ0ed>d?Z1ed@dAZ2edBd!Z3edCdZ4edDdEZ5edFdGZ6edHdIZ7edJdKZ8dLZ9dMZ:GdNdOdOe;Z<GdPdQdQe=Z>GdRdSdSeZ?GdTdUdUe?Z@GdVdWdWe@ZAGdXdYdYe@ZBGdZd[d[e;ZCGd\d]d]eCZDd^d_ZEGd`dadaeCZFGdbdcdceFZGdS)dz? This module contains the error-related constants and classes. )absolute_import)defaultdict
namedtupleMutableMapping)copydeepcopy)wraps)pformat)PYTHON_VERSION)compare_paths_ltquote_stringZcerberus_errorz
code, ruleNzdocument is missingZrequiredZdependenciesZexcludes!z''{0}' is not a document, must be a dict"empty#Znullable$type%schema&items'Z	minlength(	maxlengthAregexBminCmaxDZallowedEFZ	forbiddenG`aZcoercebZrename_handlercreadonlydZdefault_setterZ	keyschemaZvalueschemaZnoneofZoneofZanyofZallofz0schema definition for field '{0}' must be a dictzvalidation schema missingc@seZdZdZddZddZddZdd	Zd
dZe	dd
Z
e	ddZe	ddZe	ddZ
e	ddZe	ddZdS)ValidationErrorz< A simple class to store and query basic error information. cCsC||_||_||_||_||_||_||_dS)N)
document_pathschema_pathcoderule
constraintvalueinfo)selfr<r=r>r?r@rArBrD
/errors.py__init__^s							zValidationError.__init__cCst|t|kS)z< Assumes the errors relate to the same document and schema. )hash)rCotherrDrDrE__eq__rszValidationError.__eq__cCs't|jt|jAt|jAS)z@ Expects that all other properties are transitively determined. )rGr<r=r>)rCrDrDrE__hash__vszValidationError.__hash__cCs<|j|jkr%t|j|jSt|j|jSdS)N)r<rr=)rCrHrDrDrE__lt__{szValidationError.__lt__cCspdjd|jjdtt|d|jd|jdt|jdt|j	dt|j
d	|jS)
Nz{class_name} @ {memptr} ( document_path={document_path},schema_path={schema_path},code={code},constraint={constraint},value={value},info={info} )
class_nameZmemptrr<r=r>r@rArB)format	__class____name__hexidr<r=r>rr@rArB)rCrDrDrE__repr__s			zValidationError.__repr__cCs|jr|jdSdS)zX
        A list that contains the individual errors of a bulk validation error.
        rN)is_group_errorrB)rCrDrDrEchild_errorsszValidationError.child_errorscCsX|js
dStt}x8|jD]-}|jt|j}||j|q#W|S)z Dictionary with errors of an *of-rule mapped to the index of the
            definition it occurred in. Returns :obj:`None` if not applicable.
            N)is_logic_errorrlistrTr=lenappend)rCresulterrorirDrDrEdefinitions_errorss	z"ValidationError.definitions_errorscCs|jr|jdSdSdS)z8 Field of the contextual mapping, possibly :obj:`None`. r
N)r<)rCrDrDrEfields	zValidationError.fieldcCst|jtj@S)z* ``True`` for errors of bulk validations. )boolr>ERROR_GROUP)rCrDrDrErSszValidationError.is_group_errorcCst|jtjtj@S)zV ``True`` for validation errors against different schemas with
            *of-rules. )r_r>LOGICALr`)rCrDrDrErUszValidationError.is_logic_errorcCst|jtj@S)z$ ``True`` for normalization errors. )r_r>
NORMALIZATION)rCrDrDrEis_normalization_errorsz&ValidationError.is_normalization_errorN)rO
__module____qualname____doc__rFrIrJrKrRpropertyrTr\r^rSrUrcrDrDrDrEr;\sr;c@s"eZdZdZddZdS)	ErrorListz A list for :class:`~cerberus.errrors.ValidationError` instances that
        can be queried with the ``in`` keyword for a particular error code. cCs5x.dd|DD]}||jkrdSqWdS)Ncss|]}|jVqdS)N)r>).0xrDrDrE	<genexpr>sz)ErrorList.__contains__.<locals>.<genexpr>TF)r>)rCZerror_definitionr>rDrDrE__contains__szErrorList.__contains__N)rOrdrerfrlrDrDrDrErhsrhc@seZdZdZddZdd	Zd
dZdd
ZddZddZ	ddZ
ddZeddZ
eddZddZddZdS) 
ErrorTreeNodedescendantserrorsparent_nodepath	tree_rootcCsN||_|jj|_|d|jjd|_t|_i|_dS)Nr
)rprrdepthrqrhrorn)rCrqrprDrDrErFs
	zErrorTreeNode.__init__cCs|j||S)N)add)rCrZrDrDrE__add__s
zErrorTreeNode.__add__cCs|j|=dS)N)rn)rCkeyrDrDrE__delitem__szErrorTreeNode.__delitem__cCs
t|jS)N)iterro)rCrDrDrE__iter__szErrorTreeNode.__iter__cCs|jj|S)N)rnget)rCitemrDrDrE__getitem__szErrorTreeNode.__getitem__cCs
t|jS)N)rWro)rCrDrDrE__len__szErrorTreeNode.__len__cCs||j|<dS)N)rn)rCrvrArDrDrE__setitem__szErrorTreeNode.__setitem__cCst|jdt|jS)N,)strrorn)rCrDrDrE__str__szErrorTreeNode.__str__cCs
t|jS)N)rWrq)rCrDrDrErsszErrorTreeNode.depthcCs
|jjS)N)rr	tree_type)rCrDrDrErszErrorTreeNode.tree_typecCs|j|}||j}||jkr>t||||<t||jdkr||jj|||jj|jrx1|j	D]}|j
|7_
qWn|||7<dS)Nr
)	_path_of_rsrnrmrWrorXsortrSrTrr)rCrZZ
error_pathrvchild_errorrDrDrErts
	zErrorTreeNode.addcCst||jdS)N_path)getattrr)rCrZrDrDrErszErrorTreeNode._path_of_N)zdescendantszerrorszparent_nodezpathz	tree_root)rOrdre	__slots__rFrurwryr|r}r~rrgrsrrtrrDrDrDrErmsrmcsOeZdZdZgddZfddZddZdd	ZS)
	ErrorTreezs Base class for :class:`~cerberus.errors.DocumentErrorTree` and
        :class:`~cerberus.errors.SchemaErrorTree`. cCsOd|_||_f|_t|_i|_x|D]}||7}q7WdS)N)rprrrqrhrorn)rCrorZrDrDrErFs				
zErrorTree.__init__csI|j|s/|jj||jjntt|j|dS)zd Add an error to the tree.

        :param error: :class:`~cerberus.errors.ValidationError`
        N)rrorXrsuperrrt)rCrZ)rNrDrErtsz
ErrorTree.addcCs-|j|}|dk	r"|jStSdS)z Returns all errors for a particular path.

        :param path: :class:`tuple` of :term:`hashable` s.
        :rtype: :class:`~cerberus.errors.ErrorList`
        N)fetch_node_fromrorh)rCrqnoderDrDrEfetch_errors_fromszErrorTree.fetch_errors_fromcCs2|}x%|D]}||}|dkr
Pq
W|S)z Returns a node for a path.

        :param path: Tuple of :term:`hashable` s.
        :rtype: :class:`~cerberus.errors.ErrorTreeNode` or :obj:`None`
        NrD)rCrqcontextrvrDrDrEr(s

zErrorTree.fetch_node_from)rOrdrerfrFrtrrrDrD)rNrErs
	rc@seZdZdZdZdS)DocumentErrorTreezr Implements a dict-like class to query errors by indexes following the
        structure of a validated document. ZdocumentN)rOrdrerfrrDrDrDrEr6src@seZdZdZdZdS)SchemaErrorTreezm Implements a dict-like class to query errors by indexes following the
        structure of the used schema. rN)rOrdrerfrrDrDrDrEr<src@sveZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZdS)BaseErrorHandlerzo Base class for all error handlers.
        Subclasses are identified as error-handlers with an instance-test. cOsdS)z' Optionally initialize a new instance. NrD)rCargskwargsrDrDrErFEszBaseErrorHandler.__init__cCs
tdS)a$ Returns errors in a handler-specific format.

        :param errors: An object containing the errors.
        :type errors: :term:`iterable` of
                      :class:`~cerberus.errors.ValidationError` instances or a
                      :class:`~cerberus.Validator` instance
        N)NotImplementedError)rCrorDrDrE__call__IszBaseErrorHandler.__call__cCs
tdS)z7 Be a superhero and implement an iterator over errors. N)r)rCrDrDrErySszBaseErrorHandler.__iter__cCs
tdS)z Add an error to the errors' container object of a handler.

        :param error: The error to add.
        :type error: :class:`~cerberus.errors.ValidationError`
        N)r)rCrZrDrDrErtWszBaseErrorHandler.addcCsdS)z Optionally emits an error in the handler's format to a stream.
            Or light a LED, or even shut down a power plant.

        :param error: The error to emit.
        :type error: :class:`~cerberus.errors.ValidationError`
        NrD)rCrZrDrDrEemit_szBaseErrorHandler.emitcCsdS)z Gets called when a validation ends.

        :param validator: The calling validator.
        :type validator: :class:`~cerberus.Validator` NrD)rC	validatorrDrDrEendhszBaseErrorHandler.endcCs"x|D]}|j|qWdS)z Adds all errors to the handler's container object.

        :param errors: The errors to add.
        :type errors: :term:`iterable` of
                      :class:`~cerberus.errors.ValidationError` instances
        N)rt)rCrorZrDrDrEextendos
zBaseErrorHandler.extendcCsdS)z Gets called when a validation starts.

        :param validator: The calling validator.
        :type validator: :class:`~cerberus.Validator`
        NrD)rCrrDrDrEstartyszBaseErrorHandler.startN)rOrdrerfrFrryrtrrrrrDrDrDrErBs
	
rc@s(eZdZddZddZdS)ToyErrorHandlercOstddS)NzThis is not supposed to happen.)RuntimeError)rCrrrDrDrErszToyErrorHandler.__call__cCsdS)NrD)rCrDrDrEclearszToyErrorHandler.clearN)rOrdrerrrDrDrDrErsrcs2tfdd}tdkr.|SS)zCerberus error messages expect regular binary strings.
    If unicode is used in a ValidationError message can't be printed.

    This decorator ensures that if legacy Python is used unicode
    strings are encoded before passing to a function.
    csdd}t|}||j|_||j|_||j|_||j|_||j|_||S)NcSs t|tr|jdS|S)z1Helper encoding unicode strings into binary utf-8zutf-8)
isinstanceunicodeencode)rArDrDrE_encodes
z0encode_unicode.<locals>.wrapped.<locals>._encode)rr<r=r@rArB)objrZr)frDrEwrappedszencode_unicode.<locals>.wrappedr)rr
)rrrD)rrEencode_unicodesrcF@seZdZdZdddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d'd+d)d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d7d=d>d?d@dAdBdCdDi#ZdEdFdGZdEdHdIZdJdKZedLdMZ	dNdOZ
dPdQZdRdSZdTdUZ
dVdWZedXdYZdZd[Zd\d]ZdES)^BasicErrorHandlerz3 Models cerberus' legacy. Returns a :class:`dict`. rz{0}r
zdocument is missingrzrequired fieldrz
unknown fieldrzfield '{0}' is requiredrz%depends on these values: {constraint}rz&{0} must not be present with '{field}'rz''{0}' is not a document, must be a dictrzempty values not allowedrznull value not allowedrzmust be of {constraint} typerzmust be of dict typerz0length of list should be {constraint}, it is {0}rzmin length is {constraint}rzmax length is {constraint}r z)value does not match regex '{constraint}'r"zmin value is {constraint}r$zmax value is {constraint}r&zunallowed value {value}r'zunallowed values {0}r(r)r+z&field '{field}' cannot be coerced: {0}r,z&field '{field}' cannot be renamed: {0}r-zfield is read-onlyr/z.default value for '{field}' cannot be set: {0}r1z'mapping doesn't validate subschema: {0}r2z.one or more sequence-items don't validate: {0}r3z2one or more keys of a mapping  don't validate: {0}r4z3one or more values in a mapping don't validate: {0}r7z one or more definitions validater8z#none or more than one rule validater9zno definitions validater:z&one or more definitions don't validateNcCs|dkrin||_dS)N)tree)rCrrDrDrErFszBasicErrorHandler.__init__cCs*|dk	r#|j|j||jS)N)rrpretty_tree)rCrorDrDrErs

zBasicErrorHandler.__call__cCs
t|jS)N)r	r)rCrDrDrErszBasicErrorHandler.__str__cCsj|jr|j|nM|jr2|j|n4|j|jkrf|j|j|j|j	|dS)N)
rUinsert_logic_errorrSinsert_group_errorr>messagesinsert_errorr<format_messager^)rCrZrDrDrErts		zBasicErrorHandler.addcCs
i|_dS)N)r)rCrDrDrErszBasicErrorHandler.clearcCs2|j|jj|jd|jd|d|jS)Nr@r^rA)rr>rMrBr@rA)rCr^rZrDrDrErsz BasicErrorHandler.format_messagecCs|d}t|dkrn||jkrX|j|j}|j|||g7<q|ig|j|<nt|dkr||jkrig|j|<|j|d}|r|jdt|}n|j}|j|dd||j|jdS)z Adds an error or sub-tree to :attr:tree.

        :param path: Path to the error.
        :type path: Tuple of strings and integers.
        :param node: An error message or a sub-tree.
        :type node: String or dictionary.
        rr
rNr])rWrpoprNrrupdate)rCrqrr^subtreenewrDrDrErs
zBasicErrorHandler.insert_errorcCslxe|jD]Z}|jr)|j|q
|jrB|j|q
|j|j|j|j|q
WdS)N)	rTrUrrSrrr<rr^)rCrZrDrDrErs		z$BasicErrorHandler.insert_group_errorcCs|j|jf}|j}|j||j||x|jD]}|j|}|s^qBd|j|f}xU|D]M}|jrtqx|jrtqx|j||f|j||qxWqBWdS)Nz%s definition %s)	r<r?r^rrr\rUrrS)rCrZrqr^r[rTnodenamerrDrDrErs	

				z$BasicErrorHandler.insert_logic_errorcCs5t|j}x|D]}|j||qW|S)N)rr_purge_empty_dicts)rCZprettyr^rDrDrEr*s
zBasicErrorHandler.pretty_treecCsG|d}|ds!|jn"x|D]}|j||q(WdS)Nr
r]r])rr)rCZ
error_listrrvrDrDrEr1s




z$BasicErrorHandler._purge_empty_dictscCs|jdS)N)r)rCrrDrDrEr9szBasicErrorHandler.start)rOrdrerfrrFrrrrtrrrrrrgrrrrDrDrDrErs`

rc@s)eZdZejjZded<dS)SchemaErrorHandlerzunknown rulerN)rOrdrerrrrDrDrDrEr=sr)HrfZ
__future__rcollectionsrrrrr	functoolsrpprintr	Zcerberus.platformr
Zcerberus.utilsrrZErrorDefinitionZCUSTOMZDOCUMENT_MISSINGZREQUIRED_FIELDZ
UNKNOWN_FIELDZDEPENDENCIES_FIELDZDEPENDENCIES_FIELD_VALUEZEXCLUDES_FIELDZDOCUMENT_FORMATZEMPTY_NOT_ALLOWEDZNOT_NULLABLEZBAD_TYPEZBAD_TYPE_FOR_SCHEMAZITEMS_LENGTHZ
MIN_LENGTHZ
MAX_LENGTHZREGEX_MISMATCHZ	MIN_VALUEZ	MAX_VALUEZUNALLOWED_VALUEZUNALLOWED_VALUESZFORBIDDEN_VALUEZFORBIDDEN_VALUESrbZCOERCION_FAILEDZRENAMING_FAILEDZREADONLY_FIELDZSETTING_DEFAULT_FAILEDr`ZMAPPING_SCHEMAZSEQUENCE_SCHEMAZ	KEYSCHEMAZVALUESCHEMAZ	BAD_ITEMSraZNONEOFZONEOFZANYOFZALLOFZSCHEMA_ERROR_DEFINITION_TYPEZSCHEMA_ERROR_MISSINGobjectr;rVrhrmrrrrrrrrrDrDrDrE<module>sz
c
<1@
Back to Directory File Manager