U `S@sdZddlmZddlmZmZddlmZmZddlm Z ddl m Z ddl m Z mZddlmZmZed d Zedd Zed d Zd ZeddZedd ZeddZeddZeddZedd ZdZeddZeddZeddZeddZed 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(ed2d3Z)ed4d Z*ed5d6Z+ed7d8Z,ed9d:Z-ed;d<Z.ed=d Z/ed>dZ0ed?dZ1ed@dAZ2Z3edBdCZ4Z5edDd!Z6edEd Z7edFdGZ8edHdIZ9edJdKZ:edLdMZ;dNZZ?GdRdSdSe@ZAGdTdUdUeZBGdVdWdWeBZCGdXdYdYeCZDGdZd[d[eCZEGd\d]d]e>ZFGd^d_d_eFZGd`daZHGdbdcdceFZIGdddedeeIZJd S)fz? This module contains the error-related constants and classes. )absolute_import) defaultdict namedtuple)copydeepcopy)wraps)pformat)PYTHON_VERSIONMutableMapping)compare_paths_lt quote_stringErrorDefinitionz code, ruleNdocument is missingZrequiredZ dependenciesZexcludes!''{0}' is not a document, must be a dict"empty#Znullable$type%schema&items'Z minlength(Z maxlengthAZregexBminCmaxDZallowedEFZ forbiddenGHcontains`aZcoercebZrename_handlercreadonlydZdefault_setterZ keysrulesZ valuesrulesZnoneofZoneofZanyofZallofz0schema definition for field '{0}' must be a dictzvalidation schema missingc@seZdZdZddZddZddZdd Zd d Ze d d Z e ddZ e ddZ e ddZ e ddZe ddZdS)ValidationErrorz:A simple class to store and query basic error information.cCs.||_||_||_||_||_||_||_dSN) document_path schema_pathcoderule constraintvalueinfo)selfr@rArBrCrDrErFrH@/opt/alt/python38/lib/python3.8/site-packages/cerberus/errors.py__init__^szValidationError.__init__cCst|t|kS)z:Assumes the errors relate to the same document and schema.)hashrGotherrHrHrI__eq__qszValidationError.__eq__cCst|jt|jAt|jAS)z>Expects that all other properties are transitively determined.)rKr@rArBrGrHrHrI__hash__uszValidationError.__hash__cCs,|j|jkrt|j|jSt|j|jSdSr?)r@r rArLrHrHrI__lt__ys zValidationError.__lt__c Cs>dj|jjtt||j|jt|jt|j t|j |j dS)Nz{class_name} @ {memptr} ( document_path={document_path},schema_path={schema_path},code={code},constraint={constraint},value={value},info={info} )) class_nameZmemptrr@rArBrDrErF) format __class____name__hexidr@rArBr rDrErFrOrHrHrI__repr__s zValidationError.__repr__cCs|jr|jdSdS)zX A list that contains the individual errors of a bulk validation error. rN)is_group_errorrFrOrHrHrI child_errorsszValidationError.child_errorscCs@|js dStt}|jD]"}|jt|j}|||q|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_errorrlistrZrAlenappend)rGresulterrorirHrHrIdefinitions_errorss z"ValidationError.definitions_errorscCs|jr|jdSdSdS)z6Field of the contextual mapping, possibly :obj:`None`.N)r@rOrHrHrIfields zValidationError.fieldcCst|jtj@S)z(``True`` for errors of bulk validations.)boolrB ERROR_GROUPrOrHrHrIrYszValidationError.is_group_errorcCst|jtjtj@S)z[ ``True`` for validation errors against different schemas with \*of-rules. )rerBLOGICALrfrOrHrHrIr[szValidationError.is_logic_errorcCst|jtj@S)z"``True`` for normalization errors.)rerB NORMALIZATIONrOrHrHrIis_normalization_errorsz&ValidationError.is_normalization_errorN)rU __module__ __qualname____doc__rJrNrPrQrXpropertyrZrbrdrYr[rirHrHrHrIr>[s$     r>c@seZdZdZddZdS) ErrorListz A list for :class:`~cerberus.errors.ValidationError` instances that can be queried with the ``in`` keyword for a particular :class:`~cerberus.errors.ErrorDefinition`. cs*t|tst|jtfdd|DS)Nc3s|]}|jkVqdSr?)rB).0xZ wanted_coderHrI sz)ErrorList.__contains__..) isinstancer TypeErrorrBany)rGZerror_definitionrHrqrI __contains__s zErrorList.__contains__N)rUrjrkrlrvrHrHrHrIrnsrnc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ e ddZe ddZddZddZdS) ErrorTreeNode) descendantserrors parent_nodepath tree_rootcCs8||_|jj|_|d|jjd|_t|_i|_dSNr)rzr|depthr{rnryrx)rGr{rzrHrHrIrJs  zErrorTreeNode.__init__cCs"t|tr||jkS||jkSdSr?)rsr ryrx)rGitemrHrHrIrvs  zErrorTreeNode.__contains__cCs |j|=dSr?rx)rGkeyrHrHrI __delitem__szErrorTreeNode.__delitem__cCs t|jSr?)iterryrOrHrHrI__iter__szErrorTreeNode.__iter__cCs>t|tr.|jD]}|j|jkr|SqdS|j|SdSr?)rsr ryrBrxget)rGrr`rHrHrI __getitem__s     zErrorTreeNode.__getitem__cCs t|jSr?)r]ryrOrHrHrI__len__szErrorTreeNode.__len__cCs|Sr?)__str__rOrHrHrIrXszErrorTreeNode.__repr__cCs||j|<dSr?r)rGrrErHrHrI __setitem__szErrorTreeNode.__setitem__cCst|jdt|jS)N,)strryrxrOrHrHrIrszErrorTreeNode.__str__cCs t|jSr?)r]r{rOrHrHrIr~szErrorTreeNode.depthcCs|jjSr?)r| tree_typerOrHrHrIrszErrorTreeNode.tree_typecCs||}||j}||jkr,t||||<||}t||jdkr||j||j|jr|j D]}|j |qhn | |dSr}) _path_of_r~rxrwr]ryr^sortrYrZr|add)rGr`Z error_pathrnode child_errorrHrHrIrs      zErrorTreeNode.addcCst||jdS)N_path)getattrrrGr`rHrHrIrszErrorTreeNode._path_of_N)rUrjrk __slots__rJrvrrrrrXrrrmr~rrrrHrHrHrIrws    rwcs:eZdZdZd ddZfddZddZd d ZZS) ErrorTreezw Base class for :class:`~cerberus.errors.DocumentErrorTree` and :class:`~cerberus.errors.SchemaErrorTree`. rHcCs8d|_||_d|_t|_i|_|D]}||q$dS)NrH)rzr|r{rnryrxrrGryr`rHrHrIrJ szErrorTree.__init__cs6||s"|j||jntt||dS)zl Add an error to the tree. :param error: :class:`~cerberus.errors.ValidationError` N)rryr^rsuperrrrrTrHrIr)s   z ErrorTree.addcCs"||}|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_fromryrn)rGr{rrHrHrIfetch_errors_from5s zErrorTree.fetch_errors_fromcCs&|}|D]}||}|dkrq"q|S)z Returns a node for a path. :param path: Tuple of :term:`hashable` s. :rtype: :class:`~cerberus.errors.ErrorTreeNode` or :obj:`None` NrH)rGr{contextrrHrHrIrBs zErrorTree.fetch_node_from)rH) rUrjrkrlrJrrr __classcell__rHrHrrIrs   rc@seZdZdZdZdS)DocumentErrorTreezv Implements a dict-like class to query errors by indexes following the structure of a validated document. ZdocumentNrUrjrkrlrrHrHrHrIrQsrc@seZdZdZdZdS)SchemaErrorTreezq Implements a dict-like class to query errors by indexes following the structure of the used schema. rNrrHrHrHrIrZsrc@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)BaseErrorHandlerziBase class for all error handlers. Subclasses are identified as error-handlers with an instance-test.cOsdS)z%Optionally initialize a new instance.NrHrGargskwargsrHrHrIrJgszBaseErrorHandler.__init__cCstdS)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 NNotImplementedErrorrGryrHrHrI__call__ks zBaseErrorHandler.__call__cCstdS)z5Be a superhero and implement an iterator over errors.NrrOrHrHrIrvszBaseErrorHandler.__iter__cCstdS)z Add an error to the errors' container object of a handler. :param error: The error to add. :type error: :class:`~cerberus.errors.ValidationError` NrrrHrHrIrzszBaseErrorHandler.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` NrHrrHrHrIemitszBaseErrorHandler.emitcCsdS)z Gets called when a validation ends. :param validator: The calling validator. :type validator: :class:`~cerberus.Validator` NrHrGZ validatorrHrHrIendszBaseErrorHandler.endcCs|D]}||qdS)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)rrrHrHrIextendszBaseErrorHandler.extendcCsdS)z Gets called when a validation starts. :param validator: The calling validator. :type validator: :class:`~cerberus.Validator` NrHrrHrHrIstartszBaseErrorHandler.startN) rUrjrkrlrJrrrrrrrrHrHrHrIrcs     rc@seZdZddZddZdS)ToyErrorHandlercOs tddS)NzThis is not supposed to happen.) RuntimeErrorrrHrHrIrszToyErrorHandler.__call__cCsdSr?rHrOrHrHrIclearszToyErrorHandler.clearN)rUrjrkrrrHrHrHrIrsrcs$tfdd}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. csVdd}t|}||j|_||j|_||j|_||j|_||j|_||S)NcSst|tr|dS|S)z1Helper encoding unicode strings into binary utf-8zutf-8)rsZunicodeencode)rErHrHrI_encodes  z0encode_unicode..wrapped.._encode)rr@rArDrErF)objr`rfrHrIwrappeds     zencode_unicode..wrappedr)rr )rrrHrrIencode_unicodesrc%@seZdZdZdddddddd d d d d dddddddddddddddddddddd d!d"d#$ZdDd%d&Zd'd(Zd)d*Zed+d,Z e d-d.Z d/d0Z d1d2Z d3d4Zd5d6Zd7d8Zd9d:Zd;d<ZdEd>d?ZdFd@dAZdGdBdCZd$S)HBasicErrorHandlerz Models cerberus' legacy. Returns a :class:`dict`. When mangled through :class:`str` a pretty-formatted representation of that tree is returned. z{0}rzrequired fieldz unknown fieldzfield '{0}' is requiredz%depends on these values: {constraint}z&{0} must not be present with '{field}'rzempty values not allowedznull value not allowedzmust be of {constraint} typezmust be of dict typez'length of list should be {0}, it is {1}zmin length is {constraint}zmax length is {constraint}z)value does not match regex '{constraint}'zmin value is {constraint}zmax value is {constraint}zunallowed value {value}zunallowed values {0}zmissing members {0}z&field '{field}' cannot be coerced: {0}z&field '{field}' cannot be renamed: {0}zfield is read-onlyz.default value for '{field}' cannot be set: {0}z'mapping doesn't validate subschema: {0}z.one or more sequence-items don't validate: {0}z2one or more keys of a mapping don't validate: {0}z3one or more values in a mapping don't validate: {0}z one or more definitions validatez#none or more than one rule validatezno definitions validatez&one or more definitions don't validate)$rrrrrrrrrrrrrr r!r"r#r%r'r(r)r*r+r.r/r0r2r4r5r6r7r:r;r<r=NcCs|dkr in||_dSr?tree)rGrrHrHrIrJszBasicErrorHandler.__init__cCs||||jSr?)rr pretty_treerrHrHrIrs zBasicErrorHandler.__call__cCs t|jSr?)rrrOrHrHrIrszBasicErrorHandler.__str__cCs&t|j}|D]}|||q|Sr?)rr_purge_empty_dicts)rGZprettyrdrHrHrIrs zBasicErrorHandler.pretty_treecCs^t|}|||jr$||n6|jr6||n$|j|jkrZ||j | |j |dSr?) r_rewrite_error_pathr[_insert_logic_errorrY_insert_group_errorrBmessages _insert_errorr@_format_messagerdrrHrHrIr s     zBasicErrorHandler.addcCs i|_dSr?rrOrHrHrIrszBasicErrorHandler.clearcCs |dSr?)rrrHrHrIr!szBasicErrorHandler.startcCs"|j|jj|j|j||jdS)N)rDrdrE)rrBrSrFrDrE)rGrdr`rHrHrIr$s  z!BasicErrorHandler._format_messagecCs|d}t|dkrT||jkrD|j|}|j|||g7<q|ig|j|<nnt|dkr||jkrvig|j|<|j|d}|r|jt|d}n|}||dd|||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. rrrcrN)r]rpoprTrrupdate)rGr{rrdsubtreenewrHrHrIr)s      zBasicErrorHandler._insert_errorcCsL|jD]@}|jr||q|jr.||q||j||j|qdSr?) rZr[rrYrrr@rrd)rGr`rrHrHrIrEs    z%BasicErrorHandler._insert_group_errorc Cst|j}||j||||jD]H}|D]>}|jrD||q.|jrV| |q.||j|||q.q&dSr?) rdrr@rrbvaluesr[rrYr)rGr`rddefinition_errorsrrHrHrIrQs   z%BasicErrorHandler._insert_logic_errorcCs6|d}|ds|n|D]}|||qdS)Nrc)rr)rGZ error_listrrrHrHrIras  z$BasicErrorHandler._purge_empty_dictsrcCs*|jr|||n|jr&|||dS)zY Recursively rewrites the error path to correctly represent logic errors N)r[_rewrite_logic_error_pathrY_rewrite_group_error_path)rGr`offsetrHrHrIrisz%BasicErrorHandler._rewrite_error_pathcCsDt|j|}|jD]*}|j|d}|j||_|||qdSr?)r]r@rZr)rGr`r child_startr relative_pathrHrHrIrrs   z+BasicErrorHandler._rewrite_group_error_pathc Csxt|j|}|jD]Z\}}|s&qd|j|f}|j|f}|D],}|j|d} || |_|||dqDqdS)Nz%s definition %sr)r]r@rbrrCr) rGr`rrrarnodenamer{rZrel_pathrHrHrIr{s  z+BasicErrorHandler._rewrite_logic_error_path)N)r)r)r)rUrjrkrlrrJrrrmrrrrrrrrrrrrrrHrHrHrIrsn'     rc@seZdZejZded<dS)SchemaErrorHandlerz unknown rulerN)rUrjrkrrrrHrHrHrIrs r)KrlZ __future__r collectionsrrrr functoolsrZpprintrZcerberus.platformr r Zcerberus.utilsr r r ZCUSTOMZDOCUMENT_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_VALUESZMISSING_MEMBERSrhZCOERCION_FAILEDZRENAMING_FAILEDZREADONLY_FIELDZSETTING_DEFAULT_FAILEDrfZMAPPING_SCHEMAZSEQUENCE_SCHEMAZ KEYSRULESZ KEYSCHEMAZ VALUESRULESZ VALUESCHEMAZ BAD_ITEMSrgZNONEOFZONEOFZANYOFZALLOFZSCHEMA_ERROR_DEFINITION_TYPEZSCHEMA_ERROR_MISSINGobjectr>r\rnrwrrrrrrrrrHrHrHrIs~                                        hI7  H?