##// END OF EJS Templates
Allow validator to be called from reads_json and writes_json
Jessica B. Hamrick -
Show More
@@ -28,13 +28,14 b' from IPython.nbformat.v3 import ('
28 28 NotebookNode,
29 29 new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet,
30 30 parse_filename, new_metadata, new_author, new_heading_cell, nbformat,
31 nbformat_minor, to_notebook_json
31 nbformat_minor, nbformat_schema, to_notebook_json
32 32 )
33 33 from IPython.nbformat import v3 as _v_latest
34 34
35 35 from .reader import reads as reader_reads
36 36 from .reader import versions
37 37 from .convert import convert
38 from .validator import nbvalidate
38 39
39 40 #-----------------------------------------------------------------------------
40 41 # Code
@@ -44,6 +45,7 b' current_nbformat = nbformat'
44 45 current_nbformat_minor = nbformat_minor
45 46 current_nbformat_module = _v_latest.__name__
46 47
48
47 49 def docstring_nbformat_mod(func):
48 50 """Decorator for docstrings referring to classes/functions accessed through
49 51 nbformat.current.
@@ -76,11 +78,19 b' def parse_py(s, **kwargs):'
76 78
77 79 def reads_json(s, **kwargs):
78 80 """Read a JSON notebook from a string and return the NotebookNode object."""
79 return convert(reader_reads(s), current_nbformat)
81 nbjson = reader_reads(s)
82 num_errors = nbvalidate(nbjson)
83 if num_errors > 0:
84 print("Num errors: %d" % num_errors)
85 return convert(nbjson, current_nbformat)
80 86
81 87
82 88 def writes_json(nb, **kwargs):
83 return versions[current_nbformat].writes_json(nb, **kwargs)
89 nbjson = versions[current_nbformat].writes_json(nb, **kwargs)
90 num_errors = nbvalidate(nbjson)
91 if num_errors > 0:
92 print("Num errors: %d" % num_errors)
93 return nbjson
84 94
85 95
86 96 def reads_py(s, **kwargs):
@@ -19,7 +19,8 b' Authors:'
19 19 from .nbbase import (
20 20 NotebookNode,
21 21 new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet,
22 new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor
22 new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor,
23 nbformat_schema
23 24 )
24 25
25 26 from .nbjson import reads as reads_json, writes as writes_json
@@ -11,6 +11,7 b' helpers to build the structs in the right form.'
11 11
12 12 import pprint
13 13 import uuid
14 import os
14 15
15 16 from IPython.utils.ipstruct import Struct
16 17 from IPython.utils.py3compat import cast_unicode, unicode_type
@@ -22,6 +23,7 b' from IPython.utils.py3compat import cast_unicode, unicode_type'
22 23 # Change this when incrementing the nbformat version
23 24 nbformat = 3
24 25 nbformat_minor = 0
26 nbformat_schema = 'v3.withref.json'
25 27
26 28 class NotebookNode(Struct):
27 29 pass
1 NO CONTENT: file renamed from IPython/nbformat/v3/validator.py to IPython/nbformat/validator.py
General Comments 0
You need to be logged in to leave comments. Login now