MCPcopy Index your code
hub / github.com/python-jsonschema/jsonschema / run

Function run

jsonschema/cli.py:234–292  ·  view source on GitHub ↗
(arguments, stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin)

Source from the content-addressed store, hash-verified

232
233
234def run(arguments, stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin): # noqa: D103
235 outputter = _Outputter.from_arguments(
236 arguments=arguments,
237 stdout=stdout,
238 stderr=stderr,
239 )
240
241 try:
242 schema = outputter.load(arguments["schema"])
243 except _CannotLoadFile:
244 return 1
245
246 Validator = arguments["validator"]
247 if Validator is None:
248 Validator = validator_for(schema)
249
250 try:
251 Validator.check_schema(schema)
252 except SchemaError as error:
253 outputter.validation_error(
254 instance_path=arguments["schema"],
255 error=error,
256 )
257 return 1
258
259 if arguments["instances"]:
260 load, instances = outputter.load, arguments["instances"]
261 else:
262 def load(_):
263 try:
264 return json.load(stdin)
265 except JSONDecodeError as error:
266 outputter.parsing_error(
267 path="<stdin>", exc_info=sys.exc_info(),
268 )
269 raise _CannotLoadFile() from error
270 instances = ["<stdin>"]
271
272 resolver = _RefResolver(
273 base_uri=arguments["base_uri"],
274 referrer=schema,
275 ) if arguments["base_uri"] is not None else None
276
277 validator = Validator(schema, resolver=resolver)
278 exit_code = 0
279 for each in instances:
280 try:
281 instance = load(each)
282 except _CannotLoadFile:
283 exit_code = 1
284 else:
285 exit_code |= _validate_instance(
286 instance_path=each,
287 instance=instance,
288 validator=validator,
289 outputter=outputter,
290 )
291

Callers 1

mainFunction · 0.85

Calls 9

validator_forFunction · 0.90
_RefResolverClass · 0.90
loadFunction · 0.85
_validate_instanceFunction · 0.85
from_argumentsMethod · 0.80
loadMethod · 0.80
ValidatorClass · 0.70
check_schemaMethod · 0.45
validation_errorMethod · 0.45

Tested by

no test coverage detected