Show More
@@ -13,7 +13,7 from ..base.handlers import ( | |||
|
13 | 13 | IPythonHandler, FilesRedirectHandler, |
|
14 | 14 | notebook_path_regex, path_regex, |
|
15 | 15 | ) |
|
16 |
from IPython.nbformat |
|
|
16 | from IPython.nbformat import from_dict | |
|
17 | 17 | |
|
18 | 18 | from IPython.utils.py3compat import cast_bytes |
|
19 | 19 |
@@ -10,9 +10,10 import requests | |||
|
10 | 10 | |
|
11 | 11 | from IPython.html.utils import url_path_join |
|
12 | 12 | from IPython.html.tests.launchnotebook import NotebookTestBase, assert_http_error |
|
13 |
from IPython.nbformat |
|
|
14 | new_markdown_cell, new_code_cell, | |
|
15 | new_output) | |
|
13 | from IPython.nbformat import write | |
|
14 | from IPython.nbformat.v4 import ( | |
|
15 | new_notebook, new_markdown_cell, new_code_cell, new_output, | |
|
16 | ) | |
|
16 | 17 | |
|
17 | 18 | from IPython.testing.decorators import onlyif_cmds_exist |
|
18 | 19 | |
@@ -66,7 +67,7 class APITest(NotebookTestBase): | |||
|
66 | 67 | |
|
67 | 68 | with io.open(pjoin(nbdir, 'foo', 'testnb.ipynb'), 'w', |
|
68 | 69 | encoding='utf-8') as f: |
|
69 |
write(nb, |
|
|
70 | write(f, nb, version=4) | |
|
70 | 71 | |
|
71 | 72 | self.nbconvert_api = NbconvertAPI(self.base_url()) |
|
72 | 73 |
@@ -12,7 +12,7 import shutil | |||
|
12 | 12 | from tornado import web |
|
13 | 13 | |
|
14 | 14 | from .manager import ContentsManager |
|
15 |
from IPython |
|
|
15 | from IPython import nbformat | |
|
16 | 16 | from IPython.utils.io import atomic_writing |
|
17 | 17 | from IPython.utils.path import ensure_dir_exists |
|
18 | 18 | from IPython.utils.traitlets import Unicode, Bool, TraitError |
@@ -253,7 +253,7 class FileContentsManager(ContentsManager): | |||
|
253 | 253 | os_path = self._get_os_path(name, path) |
|
254 | 254 | with io.open(os_path, 'r', encoding='utf-8') as f: |
|
255 | 255 | try: |
|
256 |
nb = |
|
|
256 | nb = nbformat.read(f, as_version=4) | |
|
257 | 257 | except Exception as e: |
|
258 | 258 | raise web.HTTPError(400, u"Unreadable Notebook: %s %r" % (os_path, e)) |
|
259 | 259 | self.mark_trusted_cells(nb, name, path) |
@@ -295,7 +295,7 class FileContentsManager(ContentsManager): | |||
|
295 | 295 | def _save_notebook(self, os_path, model, name='', path=''): |
|
296 | 296 | """save a notebook file""" |
|
297 | 297 | # Save the notebook file |
|
298 |
nb = |
|
|
298 | nb = nbformat.from_dict(model['content']) | |
|
299 | 299 | |
|
300 | 300 | self.check_and_sign(nb, name, path) |
|
301 | 301 | |
@@ -303,7 +303,7 class FileContentsManager(ContentsManager): | |||
|
303 | 303 | nb['metadata']['name'] = u'' |
|
304 | 304 | |
|
305 | 305 | with atomic_writing(os_path, encoding='utf-8') as f: |
|
306 |
|
|
|
306 | nbformat.write(f, nb, version=nbformat.NO_CONVERT) | |
|
307 | 307 | |
|
308 | 308 | def _save_file(self, os_path, model, name='', path=''): |
|
309 | 309 | """save a non-notebook file""" |
@@ -522,7 +522,7 class FileContentsManager(ContentsManager): | |||
|
522 | 522 | # ensure notebook is readable (never restore from an unreadable notebook) |
|
523 | 523 | if cp_path.endswith('.ipynb'): |
|
524 | 524 | with io.open(cp_path, 'r', encoding='utf-8') as f: |
|
525 |
|
|
|
525 | nbformat.read(f, as_version=4) | |
|
526 | 526 | self._copy(cp_path, nb_path) |
|
527 | 527 | self.log.debug("copying %s -> %s", cp_path, nb_path) |
|
528 | 528 |
@@ -11,7 +11,8 import os | |||
|
11 | 11 | from tornado.web import HTTPError |
|
12 | 12 | |
|
13 | 13 | from IPython.config.configurable import LoggingConfigurable |
|
14 |
from IPython.nbformat import |
|
|
14 | from IPython.nbformat import sign, validate, ValidationError | |
|
15 | from IPython.nbformat.v4 import new_notebook | |
|
15 | 16 | from IPython.utils.traitlets import Instance, Unicode, List |
|
16 | 17 | |
|
17 | 18 | |
@@ -220,8 +221,8 class ContentsManager(LoggingConfigurable): | |||
|
220 | 221 | def validate_notebook_model(self, model): |
|
221 | 222 | """Add failed-validation message to model""" |
|
222 | 223 | try: |
|
223 |
|
|
|
224 |
except |
|
|
224 | validate(model['content']) | |
|
225 | except ValidationError as e: | |
|
225 | 226 | model['message'] = 'Notebook Validation failed: {}:\n{}'.format( |
|
226 | 227 | e.message, json.dumps(e.instance, indent=1, default=lambda obj: '<UNKNOWN>'), |
|
227 | 228 | ) |
@@ -234,7 +235,7 class ContentsManager(LoggingConfigurable): | |||
|
234 | 235 | model = {} |
|
235 | 236 | if 'content' not in model and model.get('type', None) != 'directory': |
|
236 | 237 | if ext == '.ipynb': |
|
237 |
model['content'] = |
|
|
238 | model['content'] = new_notebook() | |
|
238 | 239 | model['type'] = 'notebook' |
|
239 | 240 | model['format'] = 'json' |
|
240 | 241 | else: |
@@ -308,13 +309,14 class ContentsManager(LoggingConfigurable): | |||
|
308 | 309 | Parameters |
|
309 | 310 | ---------- |
|
310 | 311 | nb : dict |
|
311 |
The notebook object (in |
|
|
312 | The notebook object (in current nbformat) | |
|
312 | 313 | name : string |
|
313 | 314 | The filename of the notebook (for logging) |
|
314 | 315 | path : string |
|
315 | 316 | The notebook's directory (for logging) |
|
316 | 317 | """ |
|
317 | if nb['nbformat'] != current.nbformat: | |
|
318 | # can't sign old notebooks | |
|
319 | if nb['nbformat'] != 4: | |
|
318 | 320 | return |
|
319 | 321 | if self.notary.check_cells(nb): |
|
320 | 322 | self.notary.sign(nb) |
@@ -329,7 +331,7 class ContentsManager(LoggingConfigurable): | |||
|
329 | 331 | Parameters |
|
330 | 332 | ---------- |
|
331 | 333 | nb : dict |
|
332 |
The notebook object (in |
|
|
334 | The notebook object (in current nbformat) | |
|
333 | 335 | name : string |
|
334 | 336 | The filename of the notebook (for logging) |
|
335 | 337 | path : string |
@@ -14,9 +14,10 import requests | |||
|
14 | 14 | |
|
15 | 15 | from IPython.html.utils import url_path_join, url_escape |
|
16 | 16 | from IPython.html.tests.launchnotebook import NotebookTestBase, assert_http_error |
|
17 |
from IPython.nbformat import |
|
|
18 |
from IPython.nbformat. |
|
|
19 | new_markdown_cell, from_dict) | |
|
17 | from IPython.nbformat import read, write, from_dict | |
|
18 | from IPython.nbformat.v4 import ( | |
|
19 | new_notebook, new_markdown_cell, | |
|
20 | ) | |
|
20 | 21 | from IPython.nbformat import v2 |
|
21 | 22 | from IPython.utils import py3compat |
|
22 | 23 | from IPython.utils.data import uniq_stable |
@@ -143,7 +144,7 class APITest(NotebookTestBase): | |||
|
143 | 144 | with io.open(pjoin(nbdir, d, '%s.ipynb' % name), 'w', |
|
144 | 145 | encoding='utf-8') as f: |
|
145 | 146 | nb = new_notebook() |
|
146 |
write(nb, |
|
|
147 | write(f, nb, version=4) | |
|
147 | 148 | |
|
148 | 149 | # create a text file |
|
149 | 150 | with io.open(pjoin(nbdir, d, '%s.txt' % name), 'w', |
@@ -354,7 +355,7 class APITest(NotebookTestBase): | |||
|
354 | 355 | self._check_created(resp, u'Upload tést.ipynb', u'å b') |
|
355 | 356 | resp = self.api.read(u'Upload tést.ipynb', u'å b') |
|
356 | 357 | data = resp.json() |
|
357 |
self.assertEqual(data['content']['nbformat'], |
|
|
358 | self.assertEqual(data['content']['nbformat'], 4) | |
|
358 | 359 | |
|
359 | 360 | def test_copy_untitled(self): |
|
360 | 361 | resp = self.api.copy_untitled(u'ç d.ipynb', path=u'å b') |
@@ -422,7 +423,7 class APITest(NotebookTestBase): | |||
|
422 | 423 | |
|
423 | 424 | nbfile = pjoin(self.notebook_dir.name, 'foo', 'a.ipynb') |
|
424 | 425 | with io.open(nbfile, 'r', encoding='utf-8') as f: |
|
425 |
newnb = read(f, |
|
|
426 | newnb = read(f, as_version=4) | |
|
426 | 427 | self.assertEqual(newnb.cells[0].source, |
|
427 | 428 | u'Created by test ³') |
|
428 | 429 | nbcontent = self.api.read('a.ipynb', 'foo').json()['content'] |
@@ -9,7 +9,7 from tornado.web import HTTPError | |||
|
9 | 9 | from unittest import TestCase |
|
10 | 10 | from tempfile import NamedTemporaryFile |
|
11 | 11 | |
|
12 |
from IPython.nbformat import |
|
|
12 | from IPython.nbformat import v4 as nbformat | |
|
13 | 13 | |
|
14 | 14 | from IPython.utils.tempdir import TemporaryDirectory |
|
15 | 15 | from IPython.utils.traitlets import TraitError |
@@ -95,8 +95,8 class TestContentsManager(TestCase): | |||
|
95 | 95 | return os_path |
|
96 | 96 | |
|
97 | 97 | def add_code_cell(self, nb): |
|
98 |
output = |
|
|
99 |
cell = |
|
|
98 | output = nbformat.new_output("display_data", {'application/javascript': "alert('hi');"}) | |
|
99 | cell = nbformat.new_code_cell("print('hi')", outputs=[output]) | |
|
100 | 100 | nb.cells.append(cell) |
|
101 | 101 | |
|
102 | 102 | def new_notebook(self): |
@@ -11,7 +11,8 pjoin = os.path.join | |||
|
11 | 11 | |
|
12 | 12 | from IPython.html.utils import url_path_join |
|
13 | 13 | from IPython.html.tests.launchnotebook import NotebookTestBase, assert_http_error |
|
14 |
from IPython.nbformat. |
|
|
14 | from IPython.nbformat.v4 import new_notebook | |
|
15 | from IPython.nbformat import write | |
|
15 | 16 | |
|
16 | 17 | class SessionAPI(object): |
|
17 | 18 | """Wrapper for notebook API calls.""" |
@@ -63,7 +64,7 class SessionAPITest(NotebookTestBase): | |||
|
63 | 64 | with io.open(pjoin(nbdir, 'foo', 'nb1.ipynb'), 'w', |
|
64 | 65 | encoding='utf-8') as f: |
|
65 | 66 | nb = new_notebook() |
|
66 |
write(nb, |
|
|
67 | write(f, nb, version=4) | |
|
67 | 68 | |
|
68 | 69 | self.sess_api = SessionAPI(self.base_url()) |
|
69 | 70 |
@@ -10,7 +10,8 pjoin = os.path.join | |||
|
10 | 10 | import requests |
|
11 | 11 | import json |
|
12 | 12 | |
|
13 |
from IPython.nbformat |
|
|
13 | from IPython.nbformat import write | |
|
14 | from IPython.nbformat.v4 import (new_notebook, | |
|
14 | 15 | new_markdown_cell, new_code_cell, |
|
15 | 16 | new_output) |
|
16 | 17 | |
@@ -73,7 +74,7 class FilesTest(NotebookTestBase): | |||
|
73 | 74 | |
|
74 | 75 | with io.open(pjoin(nbdir, 'testnb.ipynb'), 'w', |
|
75 | 76 | encoding='utf-8') as f: |
|
76 |
write(nb, |
|
|
77 | write(f, nb, version=4) | |
|
77 | 78 | |
|
78 | 79 | with io.open(pjoin(nbdir, 'test.bin'), 'wb') as f: |
|
79 | 80 | f.write(b'\xff' + os.urandom(5)) |
General Comments 0
You need to be logged in to leave comments.
Login now