kf(dZddlmZmZddlZddlZddlZddlZddlm Z ddl m Z m Z e ddgZe Ze jZGdd eZGd d eZGd d eZejdGddeZGddeZGddeZGddeZGddeZeefdZeZefdZdS)z2 Validation errors, and some surrounding helpers. ) defaultdictdequeN)_utils)PY3 iteritemsanyOfoneOfc eZdZedddeeeddf fd ZdZdZereZndZe dZ e dZ e d Z d Zd ZxZS) _ErrorNc tt|||||||||| | ||_t |x|_|_t | x|_|_t||_ |x|_ |_ ||_ ||_||_||_| |_|D] } || _ dSN)superr __init__messagerpath relative_path schema_pathrelative_schema_pathlistcontextcause __cause__ validatorvalidator_valueinstanceschemaparent) selfrrrrrrrrrrerror __class__s u/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/jsonschema/exceptions.pyrz_Error.__init__s fd$$            ).t4 D&7<[7I7II44G}} &++ T^".      EELL  c2d|jjd|jdS)N)r!__name__rrs r"__repr__z_Error.__repr__=s !^444dlllCCr#c >|j|j|j|jf}t d|Dr|jSt j|jd}t j|jd}|jtj d |j|j tj t|jddtj||jtj |jtj|fzzS)Nc3(K|] }|tuVdSr)_unset).0ms r" z%_Error.__unicode__..Ds&::qqF{::::::r#Hwidthzl Failed validating %r in %s%s: %s On %s%s: %s )rrrranyrpprintpformattextwrapdedentrstrip!_word_for_schema_in_error_messagerformat_as_indexrrindent#_word_for_instance_in_error_messager)ressential_for_verbosepschema pinstances r" __unicode__z_Error.__unicode__@s  ND0$-!  ::$9::: : : < .B777N4=;;; |ho/   N  2  "4(A#B#B3B3#G H H M' " "  4  "4#5 6 6 M) $ $    r#cFt|dSNzutf-8unicodeencoder(s r"__str__z_Error.__str__^4==''00 0r#c6|di|S)Nr  _contents)clsothers r" create_fromz_Error.create_fromas"s''U__&&'''r#c|j}||jSt|j}|t |j|Sr)rrr extendleftreversed absolute_pathrrrs r"rRz_Error.absolute_pathesI >% %T'(( !566777 r#c|j}||jSt|j}|t |j|Sr)rrrrPrQabsolute_schema_pathrSs r"rUz_Error.absolute_schema_pathosI >, ,T.// !<==>>> r#c t|D]-\}}t||turt|||.dSr)rgetattrr,setattr)rkwargskvs r"_setz _Error._setysOf%% $ $DAqtQ6))a### $ $r#c>d}tfd|DS)N) rrrrrrrrrrc3<K|]}|t|fVdSr)rW)r-attrrs r"r/z#_Error._contents..s2BBDT74../BBBBBBr#)dict)rattrss` r"rKz_Error._contents~s/ BBBBEBBBBBBr#)r' __module__ __qualname__r,rr)rArrG classmethodrNpropertyrRrUr\rK __classcell__r!s@r"r r s % % % % % % NDDD   6 1 1 1 1(([(XX$$$ CCCCCCCr#r ceZdZdZdZdZdS)ValidationErrorz: An instance was invalid under a provided schema. rrNr'rbrc__doc__r:r=r r#r"riris()1%*4'''r#riceZdZdZdZdZdS) SchemaErrorzB A schema was invalid under its corresponding metaschema. metaschemarNrjr r#r"rmrms()5%*2'''r#rmT)hashc6eZdZdZejZdZdS)RefResolutionErrorz& A ref could not be resolved. c*t|jSr)str_causer(s r"rGzRefResolutionError.__str__s4;r#N)r'rbrcrkr_ibrtrGr r#r"rqrqs<TWYYF     r#rqc0eZdZdZdZdZereZdSdZdS)UndefinedTypeCheckzN A type checker was asked to check a type it did not have registered. c||_dSrtype)rrzs r"rzUndefinedTypeCheck.__init__s  r#cd|jzS)Nz'Type %r is unknown to this type checkerryr(s r"rAzUndefinedTypeCheck.__unicode__s849DDr#cFt|dSrCrDr(s r"rGzUndefinedTypeCheck.__str__rHr#Nr'rbrcrkrrArrGr r#r"rwrwsaEEE 1 1 1 1 1 1r#rwc0eZdZdZdZdZereZdSdZdS) UnknownTypezP A validator was asked to validate an instance against an unknown type. c0||_||_||_dSr)rzrr)rrzrrs r"rzUnknownType.__init__s    r#ctj|jd}tj|jd}t jd|jtj |tj |fzS)Nr0r1z Unknown type %r for validator with schema: %s While checking instance: %s ) r5r6rrr7r8r9rzrr<)rr?r@s r"rAzUnknownType.__unicode__s{.B777N4=;;;      Y g.. i0H0H IJ Jr#cFt|dSrCrDr(s r"rGzUnknownType.__str__rHr#Nr}r r#r"rrsa J J J 1 1 1 1 1 1r#rc@eZdZdZdfd ZdZereZxZSdZxZS) FormatErrorz% Validating a format failed. Nctt|||||_|x|_|_dSr)rrrrrr)rrrr!s r"rzFormatError.__init__s< k4  ))'5999 &++ T^^^r#c|jSr)rr(s r"rAzFormatError.__unicode__s |r#c6|jdSrC)rrFr(s r"rGzFormatError.__str__s<&&w// /r#r) r'rbrcrkrrArrGrfrgs@r"rrs|,,,,,,  0 0 0 0 0 0 0 0r#rcXeZdZdZeZd dZdZdZdZ dZ dZ d Z e d Zd S) ErrorTreezF ErrorTrees make it easier to check which validations failed. r ci|_t|j|_|D]1}|}|jD] }||} ||j|j<|j|_2dSr)errorsrr!rKrrr _instance)rrr containerelements r"rzErrorTree.__init__sq $T^44 1 1EI : / /%g. 05I U_ -"'.I    1 1r#c||jvS)zC Check whether ``instance[index]`` has any errors. rJrindexs r" __contains__zErrorTree.__contains__s &&r#cZ|jtur||vr |j||j|S)a\ Retrieve the child tree one level down at the given ``index``. If the index is not in the instance that this tree corresponds to and is not known by this tree, whatever error would be raised by ``instance.__getitem__`` will be propagated (usually this is some subclass of `exceptions.LookupError`. )rr,rKrs r" __getitem__zErrorTree.__getitem__s5 > ' 'E,=,= N5 ! !~e$$r#c||j|<dS)zB Add an error to the tree at the given ``index``. NrJ)rrvalues r" __setitem__zErrorTree.__setitem__s!&ur#c*t|jS)zY Iterate (non-recursively) over the indices in the instance with errors. )iterrKr(s r"__iter__zErrorTree.__iter__s DN###r#c|jS)z, Return the `total_errors`. ) total_errorsr(s r"__len__zErrorTree.__len__s   r#cBd|jjdt|dS)Nr%z (z total errors)>)r!r'lenr(s r"r)zErrorTree.__repr__"s$+/>+B+B+BCIIIINNr#ctdt|jD}t|j|zS)zT The total number of errors in the entire tree, including children. c3:K|]\}}t|VdSr)r)r-_trees r"r/z)ErrorTree.total_errors..+s,NND3t99NNNNNNr#)sumrrKrr)r child_errorss r"rzErrorTree.total_errors%s? NNIdn4M4MNNNNN 4;,..r#N)r )r'rbrcrkr,rrrrrrrr)rerr r#r"rrsI 1 1 1 1''' % % %&&& $$$!!! OOO//X///r#rcfd}|S)aq Create a key function that can be used to sort errors by relevance. Arguments: weak (set): a collection of validator names to consider to be "weak". If there are two errors at the same level of the instance and one is in the set of weak validator names, the other error will take priority. By default, :validator:`anyOf` and :validator:`oneOf` are considered weak validators and will be superseded by other same-level validation errors. strong (set): a collection of validator names to consider to be "strong" cJ|j}t|j |v|vfSr)rrr)r rstrongweaks r" relevancezby_relevance..relevance?s,O EJ$!6 V8KKKr#r )rrrs`` r" by_relevancer/s0 LLLLLL r#ct|}t|d}|dSttj|g||}|jrt |j|}|j|S)a Try to find an error that appears to be the best match among given errors. In general, errors that are higher up in the instance (i.e. for which `ValidationError.path` is shorter) are considered better matches, since they indicate "more" is wrong with the instance. If the resulting match is either :validator:`oneOf` or :validator:`anyOf`, the *opposite* assumption is made -- i.e. the deepest error is picked, since these validators only need to match once, and any other errors may not be relevant. Arguments: errors (collections.Iterable): the errors to select from. Do not provide a mixture of errors from different validation attempts (i.e. from different instances or schemas), since it won't produce sensical output. key (collections.Callable): the key to use when sorting errors. See `relevance` and transitively `by_relevance` for more details (the default is to sort with the defaults of that function). Changing the default is only useful if you want to change the function that rates errors but still want the error context descent done by this function. Returns: the best matching error, or ``None`` if the iterable was empty .. note:: This function is a heuristic. Its return value may change for a given set of inputs from version to version if better heuristics are added. N)key)rnextmax itertoolschainrmin)rrbests r" best_matchrHsxL&\\F   D | yvv..C 8 8 8D ,*4rsy+*******  ,,,,,,,,y'7+,,  nCnCnCnCnCYnCnCnCb55555f55533333&333T        11111111$11111)111:00000)000(E/E/E/E/E/E/E/E/P#>, LNN %......r#