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