From 380a2e949780317a9791d329ea3c7971180ff666 2014-11-01 23:41:13 From: Min RK Date: 2014-11-01 23:41:13 Subject: [PATCH] fix backward `f, nb` args for nbformat.write --- diff --git a/IPython/core/magics/basic.py b/IPython/core/magics/basic.py index 02974e6..c4c48cb 100644 --- a/IPython/core/magics/basic.py +++ b/IPython/core/magics/basic.py @@ -608,4 +608,4 @@ Defaulting color scheme to 'NoColor'""" )) nb = v4.new_notebook(cells=cells) with io.open(args.filename, 'w', encoding='utf-8') as f: - write(f, nb, version=4) + write(nb, f, version=4) diff --git a/IPython/html/nbconvert/tests/test_nbconvert_handlers.py b/IPython/html/nbconvert/tests/test_nbconvert_handlers.py index ffeb723..88ff3a7 100644 --- a/IPython/html/nbconvert/tests/test_nbconvert_handlers.py +++ b/IPython/html/nbconvert/tests/test_nbconvert_handlers.py @@ -67,7 +67,7 @@ class APITest(NotebookTestBase): with io.open(pjoin(nbdir, 'foo', 'testnb.ipynb'), 'w', encoding='utf-8') as f: - write(f, nb, version=4) + write(nb, f, version=4) self.nbconvert_api = NbconvertAPI(self.base_url()) diff --git a/IPython/html/services/contents/filemanager.py b/IPython/html/services/contents/filemanager.py index cd077f1..81e36c6 100644 --- a/IPython/html/services/contents/filemanager.py +++ b/IPython/html/services/contents/filemanager.py @@ -303,7 +303,7 @@ class FileContentsManager(ContentsManager): nb['metadata']['name'] = u'' with atomic_writing(os_path, encoding='utf-8') as f: - nbformat.write(f, nb, version=nbformat.NO_CONVERT) + nbformat.write(nb, f, version=nbformat.NO_CONVERT) def _save_file(self, os_path, model, name='', path=''): """save a non-notebook file""" diff --git a/IPython/html/services/contents/tests/test_contents_api.py b/IPython/html/services/contents/tests/test_contents_api.py index c2ef6a1..b62dbb3 100644 --- a/IPython/html/services/contents/tests/test_contents_api.py +++ b/IPython/html/services/contents/tests/test_contents_api.py @@ -144,7 +144,7 @@ class APITest(NotebookTestBase): with io.open(pjoin(nbdir, d, '%s.ipynb' % name), 'w', encoding='utf-8') as f: nb = new_notebook() - write(f, nb, version=4) + write(nb, f, version=4) # create a text file with io.open(pjoin(nbdir, d, '%s.txt' % name), 'w', diff --git a/IPython/html/services/sessions/tests/test_sessions_api.py b/IPython/html/services/sessions/tests/test_sessions_api.py index ad5ef71..4090c34 100644 --- a/IPython/html/services/sessions/tests/test_sessions_api.py +++ b/IPython/html/services/sessions/tests/test_sessions_api.py @@ -64,7 +64,7 @@ class SessionAPITest(NotebookTestBase): with io.open(pjoin(nbdir, 'foo', 'nb1.ipynb'), 'w', encoding='utf-8') as f: nb = new_notebook() - write(f, nb, version=4) + write(nb, f, version=4) self.sess_api = SessionAPI(self.base_url()) diff --git a/IPython/html/tests/test_files.py b/IPython/html/tests/test_files.py index 4c75f5b..51a8d03 100644 --- a/IPython/html/tests/test_files.py +++ b/IPython/html/tests/test_files.py @@ -74,7 +74,7 @@ class FilesTest(NotebookTestBase): with io.open(pjoin(nbdir, 'testnb.ipynb'), 'w', encoding='utf-8') as f: - write(f, nb, version=4) + write(nb, f, version=4) with io.open(pjoin(nbdir, 'test.bin'), 'wb') as f: f.write(b'\xff' + os.urandom(5)) diff --git a/IPython/nbconvert/exporters/tests/test_latex.py b/IPython/nbconvert/exporters/tests/test_latex.py index da368dd..28807af 100644 --- a/IPython/nbconvert/exporters/tests/test_latex.py +++ b/IPython/nbconvert/exporters/tests/test_latex.py @@ -95,7 +95,7 @@ class TestLatexExporter(ExportersTestsBase): with TemporaryDirectory() as td: nbfile = os.path.join(td, notebook_name) with open(nbfile, 'w') as f: - write(f, nb, 4) + write(nb, f, 4) (output, resources) = LatexExporter(template_file='article').from_filename(nbfile) assert len(output) > 0 diff --git a/IPython/nbconvert/tests/base.py b/IPython/nbconvert/tests/base.py index 61664d6..27c3caf 100644 --- a/IPython/nbconvert/tests/base.py +++ b/IPython/nbconvert/tests/base.py @@ -103,7 +103,7 @@ class TestsBase(unittest.TestCase): def create_empty_notebook(self, path): nb = v4.new_notebook() with io.open(path, 'w', encoding='utf-8') as f: - write(f, nb, 4) + write(nb, f, 4) def copy_files_to(self, copy_filenames, dest='.'): "Copy test files into the destination directory" diff --git a/IPython/nbformat/__init__.py b/IPython/nbformat/__init__.py index 100db49..6ad6b9a 100644 --- a/IPython/nbformat/__init__.py +++ b/IPython/nbformat/__init__.py @@ -123,17 +123,17 @@ def read(fp, as_version, **kwargs): return reads(fp.read(), as_version, **kwargs) -def write(fp, nb, version=NO_CONVERT, **kwargs): +def write(nb, fp, version=NO_CONVERT, **kwargs): """Write a notebook to a file in a given nbformat version. The file-like object must accept unicode input. Parameters ---------- - fp : file - Any file-like object with a write method that accepts unicode. nb : NotebookNode The notebook to write. + fp : file + Any file-like object with a write method that accepts unicode. version : int, optional The nbformat version to write. If nb is not this version, it will be converted. diff --git a/IPython/nbformat/sign.py b/IPython/nbformat/sign.py index 9e6ab71..fb7b426 100644 --- a/IPython/nbformat/sign.py +++ b/IPython/nbformat/sign.py @@ -311,7 +311,7 @@ class TrustNotebookApp(BaseIPythonApplication): print("Signing notebook: %s" % notebook_path) self.notary.sign(nb) with atomic_writing(notebook_path) as f: - write(f, nb, NO_CONVERT) + write(nb, f, NO_CONVERT) def generate_new_key(self): """Generate a new notebook signature key"""