Show More
@@ -86,11 +86,11 b' def reads_json(nbjson, **kwargs):' | |||
|
86 | 86 | """ |
|
87 | 87 | nb = reader_reads(nbjson, **kwargs) |
|
88 | 88 | nb_current = convert(nb, current_nbformat) |
|
89 |
|
|
|
90 |
if |
|
|
89 | errors = validate(nb_current) | |
|
90 | if len(errors) > 0: | |
|
91 | 91 | logger.error( |
|
92 | 92 | "Notebook JSON is invalid (%d errors detected during read)", |
|
93 |
|
|
|
93 | len(errors)) | |
|
94 | 94 | return nb_current |
|
95 | 95 | |
|
96 | 96 | |
@@ -99,11 +99,11 b' def writes_json(nb, **kwargs):' | |||
|
99 | 99 | any JSON format errors are detected. |
|
100 | 100 | |
|
101 | 101 | """ |
|
102 |
|
|
|
103 |
if |
|
|
102 | errors = validate(nb) | |
|
103 | if len(errors) > 0: | |
|
104 | 104 | logger.error( |
|
105 | 105 | "Notebook JSON is invalid (%d errors detected during write)", |
|
106 |
|
|
|
106 | len(errors)) | |
|
107 | 107 | nbjson = versions[current_nbformat].writes_json(nb, **kwargs) |
|
108 | 108 | return nbjson |
|
109 | 109 |
@@ -12,24 +12,23 b' schema_path = os.path.join(' | |||
|
12 | 12 | os.path.dirname(__file__), "v%d" % nbformat, nbformat_schema) |
|
13 | 13 | |
|
14 | 14 | |
|
15 |
def isvalid(nbjson |
|
|
15 | def isvalid(nbjson): | |
|
16 | 16 | """Checks whether the given notebook JSON conforms to the current |
|
17 | 17 | notebook format schema. Returns True if the JSON is valid, and |
|
18 | 18 | False otherwise. |
|
19 | 19 | |
|
20 | If `verbose` is set, then print out each error that is detected. | |
|
20 | To see the individual errors that were encountered, please use the | |
|
21 | `validate` function instead. | |
|
21 | 22 | |
|
22 | 23 | """ |
|
23 | 24 | |
|
24 |
errors = validate(nbjson |
|
|
25 | errors = validate(nbjson) | |
|
25 | 26 | return errors == 0 |
|
26 | 27 | |
|
27 | 28 | |
|
28 |
def validate(nbjson |
|
|
29 | def validate(nbjson): | |
|
29 | 30 | """Checks whether the given notebook JSON conforms to the current |
|
30 |
notebook format schema, and returns the |
|
|
31 | ||
|
32 | If `verbose` is set, then print out each error that is detected. | |
|
31 | notebook format schema, and returns the list of errors. | |
|
33 | 32 | |
|
34 | 33 | """ |
|
35 | 34 | |
@@ -42,13 +41,8 b' def validate(nbjson, verbose=False):' | |||
|
42 | 41 | v3schema = jsonpointer.resolve_pointer(v3schema, '/notebook') |
|
43 | 42 | |
|
44 | 43 | # count how many errors there are |
|
45 | errors = 0 | |
|
46 | 44 | v = Draft3Validator(v3schema) |
|
47 |
for e |
|
|
48 | errors = errors + 1 | |
|
49 | if verbose: | |
|
50 | print(error) | |
|
51 | ||
|
45 | errors = [e for e in v.iter_errors(nbjson)] | |
|
52 | 46 | return errors |
|
53 | 47 | |
|
54 | 48 |
General Comments 0
You need to be logged in to leave comments.
Login now