L i;HUdZddlmZddlmZmZddlmZddlm Z m Z ddl m Z m Z mZddlZddlZddlZddlmZdd lmZdd lmZe rdd lmZmZmZmZdd lmZed dgZ de!d<eZ"de!d<ejFdZ$ejJZ&d+dZ'dZ(Gdde)Z*Gdde*Z+Gdde*Z,edGdde)Z-Gdd e-eZ.Gd!d"e)Z/Gd#d$e)Z0Gd%d&e)Z1Gd'd(Z2e e"fd)Z3e3Z4 e4fd*Z5y),z2 Validation errors, and some surrounding helpers. ) annotations) defaultdictdeque)pformat)dedentindent) TYPE_CHECKINGAnyClassVarN)define) Unresolvable)_utils)IterableMappingMutableMappingSequence)_typesanyOfoneOfzfrozenset[str] WEAK_MATCHESSTRONG_MATCHESz^[a-zA-Z][a-zA-Z0-9_]*$cNtt|dd|jS)zP Format something for an error message as prettily as we currently can. HF)width sort_dicts)rrlstrip)thingprefixs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jsonschema/exceptions.py_prettyr s# '%retfE FFr!c eZdZUded<ded<edddeeeddef dfd ZddZddZedd Z e dd Z e dd Z e dd Z d dd ZdZddZxZS)_Errorz ClassVar[str]!_word_for_schema_in_error_message#_word_for_instance_in_error_messageNc Lt |||||||||| | ||_t|x|_|_t| x|_|_t||_ |x|_ |_ ||_ ||_ ||_||_| |_| |_|D] } || _ yN)super__init__messagerpath relative_path schema_pathrelative_schema_pathlistcontextcause __cause__ validatorvalidator_valueinstanceschemaparent _type_checker)selfr9rBr:r@r?rCrDrEr<rF type_checkererror __class__s rr8z_Error.__init__7s             ).t4 D&7<[7II44G} &++ T^".    ) EEL r!cPd|jjd|jdS)N<: >)rKr-r9rHs r__repr__z_Error.__repr__`s'4>>**+2dll-=Q??r!c6|j|j|j|jf}t d|Dr |j St j|jt|jdd}t j|j|j}d}td|j d|jd|dt|j| d |dt|j| d jS) Nc3,K|] }|tuywr6)_unset).0ms r z!_Error.__str__..gs:qqF{:s) containerindices z z Failed validating z in z: rz On )rBrCrDrEanyr9rformat_as_indexr2r>r=r3r;rr rstrip)rHessential_for_verboser< instance_pathrs r__str__z_Error.__str__cs NND00$--!  :$9: :<< ,,<<223CR8 ..>>&&  \\N#~~0[MBV456v678    r!c.|di|jS)Nr4 _contents)clsothers r create_fromz_Error.create_froms'U__&''r!c|j}| |jSt|j}|jt |j |Sr6)rFr;r extendleftreversed absolute_pathrHrFr:s rrmz_Error.absolute_pathsH >%% %T''( !5!567 r!c|j}| |jSt|j}|jt |j |Sr6)rFr=rrkrlabsolute_schema_pathrns rrpz_Error.absolute_schema_pathsH >,, ,T../ ! r!c d}|jD]r}t|tr|dt|zdzz }(tj |r |d|zz }F|j ddj dd}|d |zd zz }t|S) N$[].\z\\'z\'z['z'])rm isinstanceintstr&_JSON_PATH_COMPATIBLE_PROPERTY_PATTERNmatchreplace)rHr:elem escaped_elems r json_pathz_Error.json_paths&& 3D$$c$i#--7==dCd "#||D&9AA#uM |+d22 3 r!c ||jtur||_|jD]%\}}t||tust |||'yr6)rGrTitemsgetattrsetattr)rHrIkwargskvs r_setz _Error._setsS  #(:(:f(D!-D LLN $DAqtQ6)a# $r!cFd}|Dcic]}|t||c}Scc}w)N) r9r@r?rBrCr:r<rDrErF)r)rHattrsattrs rrfz_Error._contentss+ 7<.s0     & &t}}m D s03) rEKeyError TypeErrorrxrzrGrrDr^)rHexpecteds` r _matches_typez_Error._matches_typesr {{6*H h $%%--dmmXF F !)   )$  sAA.-A.)r9rzrBrzr:Iterable[str | int]r@zException | NonerCr rDr rEzMapping[str, Any] | boolr<rrFz _Error | NonerIz_types.TypeCheckerreturnNonerrz)rhr1)rzSequence[str | int]r6)rIz_types.TypeChecker | Nonerr rr)rbool)r- __module__ __qualname____annotations__rTr8rQrc classmethodripropertyrmrprrrfr __classcell__rKs@rr1r12s,'44)66  $&"&%+1+- $+1' ' ' " '  ' ' ' )' )' ' )'  ' R@ :((  37 $/ $ $  $=  r!r1ceZdZdZdZdZy)ValidationErrorz: An instance was invalid under a provided schema. rErDNr-rr__doc__r2r3r4r!rrrs)1%*4'r!rceZdZdZdZdZy) SchemaErrorzB A schema was invalid under its corresponding metaschema. metaschemarENrr4r!rrrs)5%*2'r!rF)slotsc.eZdZUdZdZded<dZddZy) r)z& A ref could not be resolved. zjsonschema.exceptions.RefResolutionError is deprecated as of version 4.18.0. If you wish to catch potential reference resolution errors, directly catch referencing.exceptions.Unresolvable. Exception_causecp|j|jurtS|j|jk(Sr6)rKNotImplementedrrHrhs r__eq__z_RefResolutionError.__eq__s+ >> 0! !{{ell**r!c,t|jSr6)rzrrPs rrcz_RefResolutionError.__str__s4;;r!Nr)r-rrrr*rrrcr4r!rr)r)s#  > +  r!r)c2eZdZddZdZdZdZdZdZy) _WrappedReferencingErrorc2tj|d|y)N_wrapped)object __setattr__)rHr@s rr8z!_WrappedReferencingError.__init__s4U3r!c|j|jur|j|jk(S|j|jjur|j|k(StSr6)rKrrrs rrz_WrappedReferencingError.__eq__sP ??dnn ,==ENN2 2 __ 7 7 7==E) )r!c.t|j|Sr6)rr)rHrs rr/z$_WrappedReferencingError.__getattr__st}}d++r!c,t|jSr6)hashrrPs r__hash__z!_WrappedReferencingError.__hash__sDMM""r!c"d|jdS)NzFr!rc eZdZdZddZddZy)UndefinedTypeCheckzN A type checker was asked to check a type it did not have registered. c||_yr6r)rHrs rr8zUndefinedTypeCheck.__init__s  r!c"d|jdS)NzType z is unknown to this type checkerrrPs rrczUndefinedTypeCheck.__str__styym#CDDr!N)rrzrrrr-rrrr8rcr4r!rrr sEr!rceZdZdZdZdZy) UnknownTypezP A validator was asked to validate an instance against an unknown type. c.||_||_||_yr6)rrDrE)rHrrDrEs rr8zUnknownType.__init__s    r!c d}td|jdt|j|dt|j|dj S)Nr[z Unknown type z, for validator with schema: r\z7 While checking instance: r])rrr rErDr`)rHrs rrczUnknownType.__str__sc))'V456v678     r!Nrr4r!rrrs  r!rc*eZdZdZdfd ZdZxZS) FormatErrorz% Validating a format failed. cPt|||||_|x|_|_yr6)r7r8r9r@rA)rHr9r@rKs rr8zFormatError.__init__2s' %( &++ T^r!c|jSr6)r9rPs rrczFormatError.__str__7s ||r!r6)r-rrrr8rcrrs@rrr-s, r!rcVeZdZdZeZd d dZd dZdZddZ dZ dZ dZ e d Zy ) ErrorTreezF ErrorTrees make it easier to check which validations failed. ci|_t|j|_|D]D}|}|jD]}||} ||j|j <|j |_Fyr6)errorsrrKrfr:rBrD _instance)rHrrJrYelements rr8zErrorTree.__init__Bsj<> 2=dnn2M 1EI :: /%g.  /05I  U__ -"'..I   1r!c||jvS)zC Check whether ``instance[index]`` has any errors. rerHindexs r __contains__zErrorTree.__contains__Ns&&r!cj|jtur||vr|j||j|S)aQ 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 `LookupError`. )rrTrfrs r __getitem__zErrorTree.__getitem__Ts2 >> 'E,= NN5 !~~e$$r!cZtjdtd||j|<y)a Add an error to the tree at the given ``index``. .. deprecated:: v4.20.0 Setting items on an `ErrorTree` is deprecated without replacement. To populate a tree, provide all of its sub-errors when you construct the tree. z8ErrorTree.__setitem__ is deprecated without replacement.r$r%N)r'r(r+rf)rHrvalues r __setitem__zErrorTree.__setitem__as)  F  !&ur!c,t|jS)zY Iterate (non-recursively) over the indices in the instance with errors. )iterrfrPs r__iter__zErrorTree.__iter__rsDNN##r!c|jS)z, Return the `total_errors`. ) total_errorsrPs r__len__zErrorTree.__len__xs   r!cjt|}|dk(rdnd}d|jjd|d|dS)NrJrrMz (z total z)>)lenrKr-)rHtotalrs rrQzErrorTree.__repr__~s>D !QJH4>>**+2eWGF82FFr!ctd|jjD}t|j|zS)zT The total number of errors in the entire tree, including children. c38K|]\}}t|ywr6)r)rU_trees rrWz)ErrorTree.total_errors..sKD3t9Ks)sumrfrrr)rH child_errorss rrzErrorTree.total_errorss5 KDNN4H4H4JKK 4;;,..r!N)r4)rzIterable[ValidationError])r str | int)rrrr)r-rrrrTrr8rrrrrrQrrr4r!rrr;sFI 1' %&"$ ! G //r!rcfd}|S)a{ Create a key function that can be used to sort errors by relevance. Arguments: weak (set): a collection of validation keywords 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 validation keywords, the other error will take priority. By default, :kw:`anyOf` and :kw:`oneOf` are considered weak keywords and will be superseded by other same-level validation errors. strong (set): a collection of validation keywords to consider to be "strong" c|j}t|j |j|v|v|j fSr6)rBrr:r)rJrBstrongweaks r relevancezby_relevance..relevancesJOO _  JJ T !  ##% %   r!r4)rrrs`` r by_relevancers&  r!ct||d}|y|jr[tjd|j|}t |dk(r||d||dk(r|S|d}|jr[|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 :kw:`oneOf` or :kw:`anyOf`, the *opposite* assumption is made -- i.e. the deepest error is picked, since these keywords only need to match once, and any other errors may not be relevant. Arguments: errors (collections.abc.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.abc.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)keydefaultr$)rrr)maxr?heapq nsmallestr)rrbestsmallests r best_matchrs}N v3 -D | ,,??1dll< x=A #hqk"2c(1+6F"FK{ ,, Kr!)rr rrz)6r __future__r collectionsrrpprintrtextwraprrtypingr r r rrer'rr referencing.exceptionsr r jsonschemarcollections.abcrrrrr frozensetrrrcompiler{UnsetrTr r/rr1rrr)rrrrrrrrr4r!rrs7#*#// @KK!('7);< n@ N %2r!