`dcUdZddlmZddlmZddlmZddlmZddl m Z ddl m Z m Z mZmZddlmZdd lmZdd lZdd lZdd lZdd lZdd lZdd lZdd lmZmZmZmZmZmZej@Z!iZ"d e#d <ejHZ%gZ&de#d<dZ'dZ(dZ)dZ*dd ejVejXe)e dfdZ- dXdZ.e-ej^didej`dejbdejddejfdejhdejjdejld ejnd!ejpdejrd"ejtd#ejvd$ejxd%ejzd&ej|d'ej~d(ejejejejejd)ejejdd*ej+ZHe-ej^d,idej`dejbdejdd-ejd.ejdejdejld!ejpdejrd"ejtd#ejvd/ejd$ejxd%ejzd&ej|d0ejd'ej~ejjejejejejejejejejd1 ejejd,d2ej+ZUe-ej^d3idej`dejbdejdd-ejd.ejd4ejd5ejdejdejld6ejd7ejd!ejpdejd"ejtd#ejvd/ejd$ejejzej|ejejejjejejejejejejejejejd8ejejd3ej9Z`e-ej^d:idej`dejbdejdd-ejd.ejd4ejd5ejdejdejld6ejd7ejd!ejpd;ejdejd"ejtd#ejvd/ejejejzej|ejejejjejejejejejejejejejd<ejejd:ej9Zde-ej^d=id>ejdej`dejbdejdd-ejd.ejd4ejd5ejd?ejd@ejdejld6ejd7ejd!ejpd;ejdejd"ejtid#ejvd/ejd$ejd%ejzd&ej|d0ejd'ejdAejjdBejdCejd(ejdDejdEejdFejdGejdHejdIejejejdJejejd=KZme-ej^dLidMejdej`dejbdejdd-ejd.ejd4ejd5ejd?ejd@ejdejld6ejd7ejd!ejpd;ejdejd"ejtid#ejvd/ejd$ejd%ejzd&ej|d0ejd'ejdAejjdBejdCejd(ejdDejdNejdEejdFejdGejdHejejejejdOejVejXdLKZqeqZrGdPdQesZtdRZudSZvdTZwdUZxdYdVZye!fdWZzy )ZzQ Creation and extension of validators, with implementations for existing drafts. ) annotations)deque)Sequence) lru_cache) methodcaller)unquote urldefragurljoinurlsplit)urlopen)warnN)_format_legacy_validators_types_utils _validators exceptionszdict[str, typing.Any] _VALIDATORSzlist[tuple[str, typing.Any]] _VOCABULARIESc|dk(r$tjdtdddlm}|S|dk(r"tjdtdt S|d k(r"tjd tdt Std td |) N ErrorTreezkImporting ErrorTree from jsonschema.validators is deprecated. Instead import it from jsonschema.exceptions. stacklevelr)r validatorszvAccessing jsonschema.validators.validators is deprecated. Use jsonschema.validators.validator_for with a given schema. meta_schemaszxAccessing jsonschema.validators.meta_schemas is deprecated. Use jsonschema.validators.validator_for with a given schema.zmodule z has no attribute ) warningsr DeprecationWarningjsonschema.exceptionsrr _META_SCHEMASAttributeError__name__)namers 7/usr/lib/python3/dist-packages/jsonschema/validators.py __getattr__r%%s {  <   4    K       K    78*,>tfE FFcfd}|S)a Register the decorated validator for a ``version`` of the specification. Registered validators and their meta schemas will be considered when parsing :kw:`$schema` keywords' URIs. Arguments: version (str): An identifier to use as the version's name Returns: collections.abc.Callable: a class decorator to decorate the validator with the version cb|t<|j|j}|t|<|SN)rID_OF META_SCHEMAr )clsmeta_schema_idversions r$ _validateszvalidates.._validatesVs." G3??3(+ n% r&)r.r/s` r$ validatesr1Bs( r&c8|dus|dury|jddS)zB Return the ID of a schema for recent JSON Schema drafts. TF$idgetschemas r$_id_ofr9^s%~5 ::eR  r&cts6tjtjdj t j Dcgc]\}}||j fc}}tzScc}}w)N vocabularies)rextendr load_schemaitemsr r+)id validators r$_store_schema_listrAgsd V//?EEGH9F9L9L9N (5IY " "#   sA7r0r>c  | tjG fdd}|R|jjddjdd}|dx|_|_t ||}|S)as Create a new validator class. Arguments: meta_schema (collections.abc.Mapping): the meta schema for the new validator class validators (collections.abc.Mapping): a mapping from names to callables, where each callable will validate the schema property with the given name. Each callable should take 4 arguments: 1. a validator instance, 2. the value of the property being validated within the instance 3. the instance 4. the schema version (str): an identifier for the version that this validator class will validate. If provided, the returned validator class will have its ``__name__`` set to include the version, and also will have `jsonschema.validators.validates` automatically called for the given version. type_checker (jsonschema.TypeChecker): a type checker, used when applying the :kw:`type` keyword. If unprovided, a `jsonschema.TypeChecker` will be created with a set of default types typical of JSON Schema drafts. format_checker (jsonschema.FormatChecker): a format checker, used when applying the :kw:`format` keyword. If unprovided, a `jsonschema.FormatChecker` will be created with a set of default formats typical of JSON Schema drafts. id_of (collections.abc.Callable): A function that given a schema, returns its ID. applicable_validators (collections.abc.Callable): A function that given a schema, returns the list of applicable validators (validation keywords and callables) which will be used to validate the instance. Returns: a new `jsonschema.protocols.Validator` class c"eZdZeWZeWZWZWZeWZ e je jZe jddZe jdZfdZedZdZdfd Zdd Zd Zd Zdd Zy)create..Validator)reprNF)defaultrErFcl|j'tj|j|_yy)N)id_of)resolver RefResolver from_schemar8)selfrIs r$__attrs_post_init__z-create..Validator.__attrs_post_init__s3}}$ + 7 7KK!8! %r&c||jj|D] }tjj |yr))r+ iter_errorsr SchemaError create_from)r,r8errors r$ check_schemaz&create..Validator.check_schemas>S__-99&A @ ,,88?? @r&c(|j}|jd|j}t||}t j |D]>}|j s|j}|ddk7r|n|dd}||vs0t||||<@|di|S)Nr8rGr_r0) __class__ setdefaultr8 validator_forattrfieldsinitr#getattr)rMchangesr,r8 NewValidatorfield attr_name init_names r$evolvez create..Validator.evolves..C''$++>F(=LS) Bzz!JJ )21)if$ref)rr rr8rValidationErrorrJ push_scope VALIDATORSr6_set TYPE_CHECKER schema_path appendleft pop_scope) rMrg_schemascopekvr@errorsrSapplicable_validatorsrIs r$rPz%create..Validator.iter_errorssh" 4 '  ++$E! 0028,?"$(%" 'NE ((/ .1':$DAq $ 3 3A 6I ( &tQ'BHbF!' $ &',-%-#*)-):): #N2!--88;#  $ $&MM++-5MM++-sA:E>BD$E$EEc3K|j|j|D]@}||jj|||jj||Byw)Nr7)rdrPpathrqrp)rMrgr8rzrprSs r$descendz!create..Validator.descendsbF3??I #JJ))$/*%%00=  sA&A(c4|j|i|D]}|yr))rP)rMargskwargsrSs r$validatez"create..Validator.validates()))4:6:   r&c |jj||S#tj$r"tj|||j wxYwr))rois_typerUndefinedTypeCheck UnknownTyper8)rMrgtypes r$rz!create..Validator.is_type!sQ J((004@@00 J ,,T8T[[II Js 5Ac|.tjdtd|j|}t |j |d}|duS)NzPassing a schema to Validator.is_valid is deprecated and will be removed in a future release. Call validator.evolve(schema=new_schema).is_valid(...) instead.rrr7)rr rrdnextrP)rMrgrsrSs r$is_validz"create..Validator.is_valid'sT" # '  {{'{2))(3T:ED= r&r))NN)r" __module__ __qualname__dictrmr+roFORMAT_CHECKER staticmethodr*r[ibreprlibrEr8rJformat_checkerrN classmethodrTrdrPr{rrr)rxformat_checker_argrI meta_schemarhrsr$ ValidatorrDs*% ;' # +U#gll+4774e4 .   @  @ +$3 .j   J  !r&r r3-)r[stitlereplacer"rr1) rrr.rhrrIrxrsafers `` ` `` @r$createrosH( VV@!@! @!D}}&&sB/77R@9=i6HH Y3&Ig&y1 r&ct|j}|j|| |j}| |j}t |j |||||jS)a Create a new validator class by extending an existing one. Arguments: validator (jsonschema.protocols.Validator): an existing validator class validators (collections.abc.Mapping): a mapping of new validator callables to extend with, whose structure is as in `create`. .. note:: Any validator callables with the same name as an existing one will (silently) replace the old validator callable entirely, effectively overriding any validation done in the "parent" validator class. If you wish to instead extend the behavior of a parent's validator callable, delegate and call it directly in the new validator function by retrieving it using ``OldValidator.VALIDATORS["validation_keyword_name"]``. version (str): a version for the new validator class type_checker (jsonschema.TypeChecker): a type checker, used when applying the :kw:`type` keyword. If unprovided, the type checker of the extended `jsonschema.protocols.Validator` will be carried along. format_checker (jsonschema.FormatChecker): a format checker, used when applying the :kw:`format` keyword. If unprovided, the format checker of the extended `jsonschema.protocols.Validator` will be carried along. Returns: a new `jsonschema.protocols.Validator` class extending the one provided .. note:: Meta Schemas The new validator class will have its parent's meta schema. If you wish to change or extend the meta schema in the new validator class, modify ``META_SCHEMA`` directly on the returned class. Note that no implicit copying is done, so a copy should likely be made before modifying it, in order to not affect the old validator. )rrr.rhrrI)rrmupdaterorrr+r*)r@rr.rhrall_validatorss r$r<r<@snF)../N*% -- "11 ))!!%oo  r&draft3rjadditionalItemsadditionalProperties dependenciesdisallow divisibleByenumextendsformatmaxItems maxLengthmaximumminItems minLengthminimumpattern)patternProperties propertiesr uniqueItemsc&|jddSNr?r3r5r7s r$rD"-r&)rrrhrr.rIrxdraft4allOfanyOf maxProperties minProperties) multipleOfnotoneOfrrrrequiredrrc&|jddSrr5r7s r$rrrr&draft6constcontainsexclusiveMaximumexclusiveMinimum)rrrrrrrrrr propertyNamesrrr)rrrhrr.rxdraft7ri)rrrrrrrrrrrrrrrz draft2019-09z $recursiveRefdependentRequireddependentSchemasrrrrrrrrunevaluatedItems)unevaluatedPropertiesr)rrrhrr.z draft2020-12z $dynamicRef prefixItems)rrrceZdZdZ ddZeefdZdZdZ e dZ e dZ e jd Ze jd Zd Zed Zed ZdZdZdZdZy)rKa Resolve JSON References. Arguments: base_uri (str): The URI of the referring document referrer: The actual referring document store (dict): A mapping from URIs to documents to cache cache_remote (bool): Whether remote refs should be cached after first resolution handlers (dict): A mapping from URI schemes to functions that should be used to retrieve them urljoin_cache (:func:`functools.lru_cache`): A cache that will be used for caching the results of joining the resolution scope to subscopes. remote_cache (:func:`functools.lru_cache`): A cache that will be used for caching the results of resolved remote URLs. Attributes: cache_remote (bool): Whether remote refs should be cached after first resolution Ncl|tdt}|td|j}||_||_t ||_|g|_tjt|_ |jj|||j|<||_ ||_y)Ni)rr resolve_from_urlreferrer cache_remoterhandlers _scopes_stackrURIDictrAstorer_urljoin_cache _remote_cache)rMbase_urirrrr urljoin_cache remote_caches r$__init__zRefResolver.__init__s  +IdOG4M  *9T?4+@+@AL  (X &Z^^$6$89  % ' 8+)r&c$|||||d|S)z Construct a resolver from a JSON schema object. Arguments: schema: the referring schema Returns: `RefResolver` )rrr0)r,r8rIr}r~s r$rLzRefResolver.from_schemas TE&MFLVLLr&cn|jj|j|j|y)z Enter a given sub-scope. Treats further dereferences as being performed underneath the given scope. N)rappendrresolution_scoperMrts r$rlzRefResolver.push_scopes. !!    5 5u = r&c~ |jjy#t$rtjdwxYw)z Exit the most recent entered scope. Treats further dereferences as being performed underneath the original scope. Don't call this method more times than `push_scope` has been called. znFailed to pop the scope from an empty stack. `pop_scope()` should only be called once for every `push_scope()`N)rpop IndexErrorrRefResolutionErrorrMs r$rrzRefResolver.pop_scopes@     " " $ //!  s<c |jdS)z8 Retrieve the current resolution scope. )rrs r$rzRefResolver.resolution_scopes !!"%%r&c6t|j\}}|S)zL Retrieve the current base URI, not including any fragment. )r r)rMurirVs r$rzRefResolver.base_uris 4001Q r&c#Ktjdtd|j| d|j y#|j wxYww)zT Temporarily enter the given scope for the duration of the context. zVjsonschema.RefResolver.in_scope is deprecated and will be removed in a future release.rN)rr rrlrrrs r$in_scopezRefResolver.in_scopesI   +      NN DNN s.AAAAAc#K|j|\}}|j| ||jy#|jwxYww)z Resolve the given ``ref`` and enter its resolution scope. Exits the scope on exit of this context manager. Arguments: ref (str): The reference to resolve N)resolverlrr)rMrefurlresolveds r$ resolvingzRefResolver.resolving!sD S) X  N NN DNN s&A>AAAc(|j|Sr))_get_subschemas_cache)rMkeys r$_find_in_referrerzRefResolver._find_in_referrer6s))+C00r&ctDcic]}|g}}t|jtD]\}}||j ||Scc}wr))_SUBSCHEMAS_KEYWORDS_search_schemar_match_subschema_keywordsr)rMrcachekeyword subschemas r$rz!RefResolver._get_subschemas_cache9s\$89Sb99"0 MM4#  - GY 'N ! !) , - :s A c|jd}|syt|\}}|D]^}|j|j|d}|j d|j dk(sF|r|j ||}||fcSy)Nr4/)rr rrrstripresolve_fragment)rMr subschemasrfragmentr target_uris r$_find_in_subschemaszRefResolver._find_in_subschemasBs//1%8 !# X# &I,,%%y'7J  %C8 $ 5 5i JII~% &r&c|j|j|jd}|j|}||S||j |fS)z. Resolve the given reference. r)rrrrr)rMrrmatchs r$rzRefResolver.resolveRsX!!$"7"7=DDSI((-  LD&&s+++r&ct|\}}|r |j|}n |j}|j||S#t$r< |j|}n&#t$r}t j |d}~wwxYwYVwxYw)z( Resolve the given URL. N) r rKeyErrorresolve_remote Exceptionrrrr)rMrrdocumentexcs r$rzRefResolver.resolve_from_url^s"# X  =::c?}}H$$Xx88 ==#2237H =$77<<= =s5A B AB A?%A::A??BBcF|jd}|sS|jur |j}nfd}dD]}||D]}|||k(s |ccSdD] }||D]}d|z||k(s|ccS"|rt|j dng}|D]F}|j ddj dd}t tr t|} |HS#t$rYwxYw#ttf$rtjd |wxYw) z Resolve a ``fragment`` within the referenced ``document``. Arguments: document: The referent document fragment (str): a URI fragment to resolve within it rc3LKtt|Ed{y7wr))r_match_keyword)rr s r$findz*RefResolver.resolve_fragment..finds)(N34GHHHs $"$)$anchor$dynamicAnchor)r?r4#z~1z~0~zUnresolvable JSON pointer: )lstriprrrsplitr isinstancerint ValueError TypeError LookupErrorrr)rMr rrrrpartsparts ` r$rzRefResolver.resolve_fragmentpsd??3'O t}} $))D I5 %G!'] % y11$$ % %% %G!'] % >Yw%77$$ % % 19!'',b D<<c*224=D(H-t9D #D>  "{+  331(> s C) C8) C54C58(D c ddl}t|j}||jvr|j||}nl|dvr"|r |j |j }nFt|5}t j|jjd}ddd|jr|j|<S#t$rd}YwxYw#1swY7xYw)a Resolve a remote ``uri``. If called directly, does not check the store first, but after retrieving the document at the specified URI it will be saved in the store if :attr:`cache_remote` is True. .. note:: If the requests_ library is present, ``jsonschema`` will use it to request the remote ``uri``, so that the correct encoding is detected and used. If it isn't, or if the scheme of the ``uri`` is not ``http`` or ``https``, UTF-8 is assumed. Arguments: uri (str): The URI to resolve Returns: The retrieved document .. _requests: https://pypi.org/project/requests/ rN)httphttpszutf-8) requests ImportErrorr schemerr6jsonr loadsreaddecoderr)rMrr r"resultrs r$rzRefResolver.resolve_remotes:  #%% T]] "*T]]6*3/F ( (X\\#&++-F @CHHJ$5$5g$>? @   $DJJsO % H  @ @sC03C CCC")r0Tr0NN)r"rr__doc__rrr9rLrlrrpropertyrr contextlibcontextmanagerrrrrrrrrrrr0r&r$rKrKs)^*6'-MM"  &&&  (1[[   ,9$6p1r&rK)r4r?rrcfd}|S)Nc3 K|vr|yywr)r0valuers r$matcherz_match_keyword..matchers e K s r0)rr0s` r$rrs Nr&c#8KtD] }||vs||fywr))rr.s r$rrs''! e 5. !s c#Kt|g}|rT|j}t|ts#||Ed{|j |j |rSyy7(w)zBreadth-first search routine.N)rrrr extendleftvalues)r8r0r4r/s r$rrsW F8_F  %& 5>!!%,,.)  "s;A(A&%A($A(c| t|}|j|||g|i|}tj|j |}||y)a Validate an instance under the given schema. >>> validate([2, 3, 4], {"maxItems": 2}) Traceback (most recent call last): ... ValidationError: [2, 3, 4] is too long :func:`validate` will first verify that the provided schema is itself valid, since not doing so can lead to less obvious error messages and fail in less obvious or consistent ways. If you know you have a valid schema already, especially if you intend to validate multiple instances with the same schema, you likely would prefer using the `Validator.validate` method directly on a specific validator (e.g. ``Draft7Validator.validate``). Arguments: instance: The instance to validate schema: The schema to validate with cls (Validator): The class that will be used to validate the instance. If the ``cls`` argument is not provided, two things will happen in accordance with the specification. First, if the schema has a :kw:`$schema` keyword containing a known meta-schema [#]_ then the proper validator will be used. The specification recommends that all schemas contain :kw:`$schema` properties for this reason. If no :kw:`$schema` property is found, the default validator class is the latest released draft. Any other provided positional and keyword arguments will be passed on when instantiating the ``cls``. Raises: `jsonschema.exceptions.ValidationError` if the instance is invalid `jsonschema.exceptions.SchemaError` if the schema itself is invalid .. rubric:: Footnotes .. [#] known by a validator registered with `jsonschema.validators.validates` N)rZrTr best_matchrP)rgr8r,r}r~r@rSs r$rrsap {F#VF,T,V,I  ! !)"7"7"A BE  r&c|turtn|}|dus|dusd|vr|S|dtvr|turtdtdtj |d|S)a Retrieve the validator class appropriate for validating the given schema. Uses the :kw:`$schema` keyword that should be present in the given schema to look up the appropriate validator class. Arguments: schema (collections.abc.Mapping or bool): the schema to look at default: the default to return if the appropriate validator class cannot be determined. If unprovided, the default is to return the latest supported draft. TFz$schemazThe metaschema specified by $schema was not found. Using the latest draft to validate, but this will raise an error in the future.rr)_UNSET_LATEST_VERSIONr r rr6)r8rFDefaultValidators r$rZrZ;sr,+2V*; ~5IV,C i - f  .#    VI.0@ AAr&)r0NNNr)){r( __future__r collectionsrcollections.abcr functoolsroperatorr urllib.parserr r r urllib.requestr rr r*r#rtypingr[ jsonschemarrrrrrUnsetr8r__annotations__rr rr%r1r9rAdraft202012_type_checkerdraft202012_format_checkerrr<r=rrrdependencies_draft3disallow_draft3rrextends_draft3ritems_draft3_draft4rrmaximum_draft3_draft4rrminimum_draft3_draft4rrproperties_draft3 type_draft3rdraft3_type_checkerdraft3_format_checkerignore_ref_siblingsDraft3Validatorrr!dependencies_draft4_draft6_draft7rrnot_rrrrdraft4_type_checkerdraft4_format_checkerDraft4Validatorrcontains_draft6_draft7rritems_draft6_draft7_draft201909rrrdraft6_type_checkerdraft6_format_checkerDraft6Validatorif_draft7_type_checkerdraft7_format_checkerDraft7Validator recursiveRefrrrrrdraft201909_type_checkerdraft201909_format_checkerDraft201909Validator dynamicRefr>rDraft202012Validatorr9objectrKrrrrrrZr0r&r$ris #$!>>"    %' "' .0 +0G:8! 0055 &w/Nf  Qh"""8, ;66  @ @ *>>  &66  {--      %44 +$$ #77 K(( [** %;; K(( [** %;;!" ;&&#$)::(::".."..+.++00  -,@@;@"""8, ;66  @ @ ""  ""  *LL      +$$ #77 K(( [** 22 %;; K(( [** 22!" %;;#$",,""&&(::!,,((  "..58++00  -,@@E#J"""8,   ;66   @ @  ""  ""  ""  &==  *LL       K88  K88  +$$  #CC  K((  [**  22! " ;&&# $ (( **$22&&!,,""&&(::!,,$22((  "..? B++00 ,@@M'R"""8,! !;66!  @ @! "" ! "" ! "" ! &==! *LL!    ! K88! K88! +$$! koo! #CC! K((! [**!!" 22#!$&&(( **$22&&!,,""&&(::!,,$22((  "..A!D++00 ,@@O(T""">2%+88% % ;66%  @ @ % "" % "" % ""% K((% [::% K88%    % K88% K88% +$$% koo% #CC!%" K((#%$ [**%%& 22'%( ;&&)%* K((+%, [**-%. 22/%0 ;&&1%2 k,,3%4 {5%6 ""7%8 ;&&9%: [::;%< k,,=%> 22?%@ K((A%B    C%D K88E%F"-!B!B"..I%L0055 U+Z""">2&{--& & ;66&  @ @ & "" & "" & ""& K((& [::& K88&    & K88& K88& +$$& koo& ""!&" K((#&$ [**%&& 22'&( ;&&)&* K((+&, [**-&. 22/&0 ;&&1&2 k,,3&4 {5&6 ""7&8 ;&&9&: [::;&< {..=&> k,,?&@ 22A&B K((C&D    E&F(88!,!B!B"..K&N0055 W,\'O&Od B! *?D#)%Br&