mfSndZddlmZddlZddlmZmZddlmZmZddl m Z ddl m Z ddl mZdd lmZmZed d Z eddZed 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(ed2d3Z)ed4dZ*ed5d6Z+ed7d8Z,ed9d:Z-ed;d<Z.ed=dZ/ed>dZ0ed?dZ1ed@dAxZ2Z3edBdCxZ4Z5edDd!Z6edEdZ7edFdGZ8edHdIZ9edJdKZ:edLdMZ; dNZZ?GdRdSe@ZAGdTdUeZBGdVdWeBZCGdXdYeCZDGdZd[eCZEGd\d]e>ZFGd^d_eFZGd`ZHGdadbeFZIGdcddeIZJdS)ez? This module contains the error-related constants and classes. )absolute_importN) defaultdict namedtuple)copydeepcopy)wraps)pformat)MutableMapping)compare_paths_lt quote_stringErrorDefinitionz code, ruledocument is missingrequired dependenciesexcludes!''{0}' is not a document, must be a dict"empty#nullable$type%schema&items' minlength( maxlengthAregexBminCmaxDallowedEF forbiddenGHcontains`acoercebrename_handlercreadonlyddefault_setter keysrules valuesrulesnoneofoneofanyofallofz0schema definition for field '{0}' must be a dictzvalidation schema missingceZdZdZdZdZdZdZdZe dZ e dZ e d Z e d Z e d Ze d Zd S)ValidationErrorz:A simple class to store and query basic error information.ct||_ ||_ ||_ ||_ ||_ ||_ ||_dSN) document_path schema_pathcoderule constraintvalueinfo)selfrTrUrVrWrXrYrZs F/opt/imunify360/venv/lib64/python3.11/site-packages/cerberus/errors.py__init__zValidationError.__init___sU* %& % ? 4$+ &  % %cBt|t|kS)z:Assumes the errors relate to the same document and schema.)hashr[others r\__eq__zValidationError.__eq__rsDzzT%[[((r^c~t|jt|jz t|jz S)z>Expects that all other properties are transitively determined.)r`rTrUrVr[s r\__hash__zValidationError.__hash__vs0D&''$t/?*@*@@4 ??RRr^c|j|jkrt|j|jSt|j|jSrS)rTr rUras r\__lt__zValidationError.__lt__zs?  !4 4 4#D$68KLL L#D$4e6GHH Hr^c d|jjtt ||j|jt|jt|j t|j |j S)Nz{class_name} @ {memptr} ( document_path={document_path},schema_path={schema_path},code={code},constraint={constraint},value={value},info={info} )) class_namememptrrTrUrVrXrYrZ) format __class____name__hexidrTrUrVr rXrYrZres r\__repr__zValidationError.__repr__so  #F>22d88}}"0 ,^^'88"4:..Y#   r^c.|jr |jdndS)zX A list that contains the individual errors of a bulk validation error. rN)is_group_errorrZres r\ child_errorszValidationError.child_errorss $2z)ErrorList.__contains__..s*77Q16[(777777r^) isinstancer TypeErrorrVany)r[error_definitionrs @r\ __contains__zErrorList.__contains__sF*O<< O&+ 7777$777777r^N)rnrrrrrr^r\rrs- 88888r^rceZdZdZdZdZdZdZdZdZ dZ d Z d Z e d Ze d Zd ZdZdS) ErrorTreeNode) descendantserrors parent_nodepath tree_rootc||_|jj|_|d|jjdz|_t |_i|_dSNr)rrdepthrrrr)r[rrs r\r]zErrorTreeNode.__init__sM&)354+1A556 kk r^cPt|tr ||jvS||jvSrS)rr rr)r[items r\rzErrorTreeNode.__contains__s/ dO , , ,4;& &4++ +r^c|j|=dSrSr)r[keys r\ __delitem__zErrorTreeNode.__delitem__s  S ! ! !r^c*t|jSrS)iterrres r\__iter__zErrorTreeNode.__iter__sDK   r^ct|tr |jD]}|j|jkr|cSdS|j|SrS)rr rrVrget)r[rr{s r\ __getitem__zErrorTreeNode.__getitem__s^ dO , , . ! !9 ** LLL+4#''-- -r^c*t|jSrS)rxrres r\__len__zErrorTreeNode.__len__s4;r^c*|SrS)__str__res r\rqzErrorTreeNode.__repr__s||~~r^c||j|<dSrSr)r[rrYs r\ __setitem__zErrorTreeNode.__setitem__s %r^cZt|jdzt|jzS)N,)strrrres r\rzErrorTreeNode.__str__s'4;#%D,<(=(===r^c*t|jSrS)rxrres r\rzErrorTreeNode.depths49~~r^c|jjSrS)r tree_typeres r\rzErrorTreeNode.tree_types ~''r^c||}||j}||jvrt||||<||}t ||jdzkrb|j||j|jr$|j D]}|j |dSdS| |dSr) _path_of_rrrrxrrysortrsrtradd)r[r{ error_pathrnode child_errors r\rzErrorTreeNode.adds^^E** $ d& & &%j$77DICy z??dj1n , , K  u % % % K     # 4#(#544KN&&{3333 4 444 HHUOOOOOr^c2t||jdzS)N_path)getattrrr[r{s r\rzErrorTreeNode._path_of_sudnw6777r^N)rnrr __slots__r]rrrrrrqrrrrrrrrr^r\rrsMI,,, """!!!...   &&&>>>X((X($88888r^rc6eZdZdZddZfdZdZdZxZS) ErrorTreezw Base class for :class:`~cerberus.errors.DocumentErrorTree` and :class:`~cerberus.errors.SchemaErrorTree`. rcd|_||_d|_t|_i|_|D]}||dS)Nr)rrrrrrrr[rr{s r\r]zErrorTree.__init__!sU kk   E HHUOOOO  r^c||s5|j||jdSt t ||dS)zl Add an error to the tree. :param error: :class:`~cerberus.errors.ValidationError` N)rrryrsuperrr)r[r{rms r\rz ErrorTree.add*sm ~~e$$ . K  u % % % K        )T " " & &u - - - - -r^cZ||}||jStS)z Returns all errors for a particular path. :param path: :class:`tuple` of :term:`hashable` s. :rtype: :class:`~cerberus.errors.ErrorList` )fetch_node_fromrr)r[rrs r\fetch_errors_fromzErrorTree.fetch_errors_from6s/##D))  ; ;; r^c,|}|D]}||}|n|S)z Returns a node for a path. :param path: Tuple of :term:`hashable` s. :rtype: :class:`~cerberus.errors.ErrorTreeNode` or :obj:`None` r)r[rcontextrs r\rzErrorTree.fetch_node_fromCs5  CclGr^)r) rnrrrr]rrr __classcell__)rms@r\rrst  . . . . .          r^rceZdZdZdZdS)DocumentErrorTreezv Implements a dict-like class to query errors by indexes following the structure of a validated document. documentNrnrrrrrr^r\rrRs IIIr^rceZdZdZdZdS)SchemaErrorTreezq Implements a dict-like class to query errors by indexes following the structure of the used schema. r!Nrrr^r\rr[s IIIr^rcBeZdZdZdZdZdZdZdZdZ dZ d Z d S) BaseErrorHandlerziBase class for all error handlers. Subclasses are identified as error-handlers with an instance-test.cdS)z%Optionally initialize a new instance.Nrr[argskwargss r\r]zBaseErrorHandler.__init__hs r^ct)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 NotImplementedErrorr[rs r\__call__zBaseErrorHandler.__call__ls "!r^ct)z5Be a superhero and implement an iterator over errors.rres r\rzBaseErrorHandler.__iter__ws!!r^ct)z Add an error to the errors' container object of a handler. :param error: The error to add. :type error: :class:`~cerberus.errors.ValidationError` rrs r\rzBaseErrorHandler.add{s "!r^cdS)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` Nrrs r\emitzBaseErrorHandler.emits  r^cdS)z Gets called when a validation ends. :param validator: The calling validator. :type validator: :class:`~cerberus.Validator` Nrr[ validators r\endzBaseErrorHandler.end  r^c:|D]}||dS)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)rrs r\extendzBaseErrorHandler.extends.  E HHUOOOO  r^cdS)z Gets called when a validation starts. :param validator: The calling validator. :type validator: :class:`~cerberus.Validator` Nrrs r\startzBaseErrorHandler.startrr^N) rnrrrr]rrrrrrrrr^r\rrdsJJ    " " """""""              r^rceZdZdZdZdS)ToyErrorHandlerc td)NzThis is not supposed to happen.) RuntimeErrorrs r\rzToyErrorHandler.__call__s<===r^cdSrSrres r\clearzToyErrorHandler.clears r^N)rnrrrrrr^r\rrs2>>>     r^rc`tfd}tjdkr|nS)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. cd}t|}||j|_||j|_||j|_||j|_||j|_||S)NcZt|tr|dS|S)z1Helper encoding unicode strings into binary utf-8zutf-8)runicodeencode)rYs r\_encodez0encode_unicode..wrapped.._encodes+%)) -||G,,,Lr^)rrTrUrXrYrZ)objr{rfs r\wrappedzencode_unicode..wrappeds    U %ge&9::#GE$566"75#344gek** WUZ(( qe}}r^)r)rsys version_info)rrs` r\encode_unicodersG 1XX    X &--7714r^creZdZdZidddddddd d d d d ddddddddddddddddddd d!d"d#id$d%d&d'd(d)d*d'd+d)d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;dd9d?d@dAdBdCdDdEZdVdGZdHZdIZedJZ e dKZ dLZ dMZ dNZdOZdPZdQZdRZdWdSZdWdTZdWdUZdFS)XBasicErrorHandlerz Models cerberus' legacy. Returns a :class:`dict`. When mangled through :class:`str` a pretty-formatted representation of that tree is returned. rz{0}rrrzrequired fieldrz unknown fieldrzfield '{0}' is requiredrz%depends on these values: {constraint}rz&{0} must not be present with '{field}'rrrzempty values not allowedrznull value not allowedrzmust be of {constraint} typer zmust be of dict typer"z'length of list should be {0}, it is {1}r$zmin length is {constraint}r&zmax 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}r0zunallowed values {0}r1r3r4zmissing members {0}r7z&field '{field}' cannot be coerced: {0}r9z&field '{field}' cannot be renamed: {0}r;zfield is read-onlyr=z.default value for '{field}' cannot be set: {0}r@z'mapping doesn't validate subschema: {0}rAz.one or more sequence-items don't validate: {0}rBz2one or more keys of a mapping don't validate: {0}rDz3one or more values in a mapping don't validate: {0}rHz one or more definitions validaterJz#none or more than one rule validatezno definitions validatez&one or more definitions don't validate)rLrNNc|in||_dSrStree)r[r s r\r]zBasicErrorHandler.__init__s,BBD r^cb||||jSrS)rr pretty_treers r\rzBasicErrorHandler.__call__s*  Fr^c*t|jSrS)r r res r\rzBasicErrorHandler.__str__st'(((r^cnt|j}|D]}||||SrS)rr _purge_empty_dicts)r[prettyrs r\r zBasicErrorHandler.pretty_trees@$)$$ 3 3E  # #F5M 2 2 2 2 r^cNt|}|||jr||dS|jr||dS|j|jvr6||j | |j |dSdSrS) r_rewrite_error_pathrv_insert_logic_errorrs_insert_group_errorrVmessages _insert_errorrT_format_messagerrs r\rzBasicErrorHandler.adds   '''     $ $U + + + + +  !   $ $U + + + + + Z4= ( (   #T%9%9%+u%M%M     ) (r^ci|_dSrSr res r\rzBasicErrorHandler.clears  r^c.|dSrS)rrs r\rzBasicErrorHandler.start"s r^c^|j|jj|j|j||jdS)N)rXrrY)rrVrlrZrXrY)r[rr{s r\rz!BasicErrorHandler._format_message%s7/t}UZ(/ ZE$4E    r^c6|d}t|dkrO||jvr8|j|}|j|xx||gz cc<dS|ig|j|<dSt|dkr||jvr ig|j|<|j|d}|r$|t |}n|}||dd|||jdSdS)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. rrrr N)rxr poprmrrupdate)r[rrrsubtreenews r\rzBasicErrorHandler._insert_error*s+Q t99>> !!)E*..00 %   T7O3     $(": %   YY!^^DI%%$&4 % i&r*G 'nn$w--n88nn&&   d122h - - - NN38 $ $ $ $ $^r^c|jD]p}|jr|||jr||<||j||j|qdSrS) rtrvrrsrrrTrr)r[r{rs r\rz%BasicErrorHandler._insert_group_errorFs -  K) ((5555+ ((5555""-(():KHH  r^c |j}||j||||jD]p}|D]k}|jr|||jr| |<||j|||lqdSrS) rrrTrr}valuesrvrrsr)r[r{rdefinition_errorsrs r\rz%BasicErrorHandler._insert_logic_errorRs  5.0D0DUE0R0RSSS!&!9!@!@!B!B   0   -,,[9999 /,,[9999&&#1,,UK@@   r^c|d}|ds|dS|D]}|||dS)Nr)rr)r[ error_listrrs r\rz$BasicErrorHandler._purge_empty_dictsbsaR."~ 6 NN      6 6'' 5555 6 6r^c|jr|||dS|jr|||dSdS)zY Recursively rewrites the error path to correctly represent logic errors N)rv_rewrite_logic_error_pathrs_rewrite_group_error_path)r[r{offsets r\rz%BasicErrorHandler._rewrite_error_pathjs\   :  * *5& 9 9 9 9 9  ! :  * *5& 9 9 9 9 9 : :r^ct|j|z }|jD]6}|j|d}|j|z|_|||7dSrS)rxrTrtr)r[r{r) child_startr relative_paths r\r(z+BasicErrorHandler._rewrite_group_error_pathssm%-..7  - : :K'5kllCM(-(;m(KK %  $ $[& 9 9 9 9  : :r^ct|j|z }|jD]V\}}|s|jd|}|j|fz}|D]4}|j|d} || z|_|||dz5WdS)Nz definition r)rxrTr}r#rWr) r[r{r)r+r|r#nodenamerrrel_paths r\r'z+BasicErrorHandler._rewrite_logic_error_path|s%-..7 $)$<$B$B$D$D B B A $ -2ZZZ;H&(4D0 B B &4[\\B,08O )((fqjAAAA  B B Br^rS)r)rnrrrrr]rrrr rrrrrrrrrrr(r'rr^r\rrs % e% #% % o % ' % 5 % 6% 7% (% &% ,% $% 7% *% *% 9!%" )#%%$ )%%& ''%( $)%* '+%, $-%. #/%0 61%2 63%4 "5%6 >7%8 79%: >;%< B=%> C?%@ >A%B 0C%D 3E%%F(6I%%%HN1111   )))X ^    %%%8    666::::::::BBBBBBr^rcJeZdZejZded<dS)SchemaErrorHandlerz unknown rulerN)rnrrrrrrr^r\r1r1s+ )..00H#HTNNNr^r1)Kr __future__rr collectionsrrrr functoolsrpprintr cerberus.platformr cerberus.utilsr r r CUSTOMDOCUMENT_MISSINGREQUIRED_FIELD UNKNOWN_FIELDDEPENDENCIES_FIELDDEPENDENCIES_FIELD_VALUEEXCLUDES_FIELDDOCUMENT_FORMATEMPTY_NOT_ALLOWED NOT_NULLABLEBAD_TYPEBAD_TYPE_FOR_SCHEMA ITEMS_LENGTH MIN_LENGTH MAX_LENGTHREGEX_MISMATCH MIN_VALUE MAX_VALUEUNALLOWED_VALUEUNALLOWED_VALUESFORBIDDEN_VALUEFORBIDDEN_VALUESMISSING_MEMBERSrCOERCION_FAILEDRENAMING_FAILEDREADONLY_FIELDSETTING_DEFAULT_FAILEDrMAPPING_SCHEMASEQUENCE_SCHEMA KEYSRULES KEYSCHEMA VALUESRULES VALUESCHEMA BAD_ITEMSrNONEOFONEOFANYOFALLOFSCHEMA_ERROR_DEFINITION_TYPESCHEMA_ERROR_MISSINGobjectrQrwrrrrrrrrrr1rr^r\rasEE&&&&&& ////////,,,,,,99999999*. == t $ $#?4..( z22d++ $_T>::*?4@@ z22"/$--;#OD'22tZ00 ?4 ( (%odH55tW-- _T; / / _T; / / !w// OD% ( ( OD% ( ( !/$ 22"?433!/$ 44"?455!/$ 33 d++ !/$11!/$(899 z22(/?@@odD))  x00!/$11'k::: I+OD-@@@ k OD' * * /$ % % x ( (g&&g&&g&&Q2e4e4e4e4e4fe4e4e4P 8 8 8 8 8 8 8 8F8F8F8F8F8NF8F8F8R44444 444n iE E E E E vE E E P     &   5556{B{B{B{B{B({B{B{B|$$$$$*$$$$$r^