D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
usr
/
lib
/
python3.6
/
site-packages
/
jsonschema
/
Filename :
cli.py
back
Copy
from __future__ import absolute_import import argparse import json import sys from jsonschema._reflect import namedAny from jsonschema.validators import validator_for def _namedAnyWithDefault(name): if "." not in name: name = "jsonschema." + name return namedAny(name) def _json_file(path): with open(path) as file: return json.load(file) parser = argparse.ArgumentParser( description="JSON Schema Validation CLI", ) parser.add_argument( "-i", "--instance", action="append", dest="instances", type=_json_file, help=( "a path to a JSON instance (i.e. filename.json)" "to validate (may be specified multiple times)" ), ) parser.add_argument( "-F", "--error-format", default="{error.instance}: {error.message}\n", help=( "the format to use for each error output message, specified in " "a form suitable for passing to str.format, which will be called " "with 'error' for each error" ), ) parser.add_argument( "-V", "--validator", type=_namedAnyWithDefault, help=( "the fully qualified object name of a validator to use, or, for " "validators that are registered with jsonschema, simply the name " "of the class." ), ) parser.add_argument( "schema", help="the JSON Schema to validate with (i.e. filename.schema)", type=_json_file, ) def parse_args(args): arguments = vars(parser.parse_args(args=args or ["--help"])) if arguments["validator"] is None: arguments["validator"] = validator_for(arguments["schema"]) return arguments def main(args=sys.argv[1:]): sys.exit(run(arguments=parse_args(args=args))) def run(arguments, stdout=sys.stdout, stderr=sys.stderr): error_format = arguments["error_format"] validator = arguments["validator"](schema=arguments["schema"]) validator.check_schema(arguments["schema"]) errored = False for instance in arguments["instances"] or (): for error in validator.iter_errors(instance): stderr.write(error_format.format(error=error)) errored = True return errored
Name
Size
Last Modified
Owner
Permissions
Actions
__pycache__
Dir
July 28 2023 2:57:35
root
0755
schemas
Dir
July 28 2023 2:57:35
root
0755
tests
Dir
July 28 2023 2:57:35
root
0755
__init__.py
0.663
KB
July 24 2015 9:41:16
root
0644
__main__.py
0.038
KB
July 24 2015 9:41:16
root
0644
_format.py
6.881
KB
November 27 2016 4:02:38
root
0644
_reflect.py
4.905
KB
July 24 2015 9:41:16
root
0644
_utils.py
4.915
KB
November 27 2016 3:39:01
root
0644
_validators.py
11.98
KB
January 26 2017 6:18:56
root
0644
_version.py
0.119
KB
February 05 2017 12:23:18
root
0644
cli.py
2.1
KB
February 04 2017 6:23:23
root
0644
compat.py
1.516
KB
November 24 2019 6:37:38
root
0644
exceptions.py
6.863
KB
November 27 2016 4:06:28
root
0644
validators.py
15.825
KB
November 27 2016 4:24:41
root
0644
2017 © D7net | D704T team