From 4e4ce4042ebeb40bc94c489961c58b6c1c8f2152 2013-10-17 21:09:08 From: Paul Ivanov Date: 2013-10-17 21:09:08 Subject: [PATCH] simplified named_notebook_path implementation Also updated the tests --- diff --git a/IPython/html/services/notebooks/nbmanager.py b/IPython/html/services/notebooks/nbmanager.py index bcd71d5..2d8c6ef 100644 --- a/IPython/html/services/notebooks/nbmanager.py +++ b/IPython/html/services/notebooks/nbmanager.py @@ -54,29 +54,21 @@ class NotebookManager(LoggingConfigurable): Returns ------- name : string or None - the filename of the notebook, or None if not a .ipynb extesnsion - path : string or None + the filename of the notebook, or None if not a .ipynb extension + path : string the path to the directory which contains the notebook """ names = notebook_path.split('/') - if len(names) > 1: - name = names[-1] - if name.endswith(".ipynb"): - name = name - path = notebook_path[:-1]+'/' - else: - name = None - path = notebook_path+'/' + + name = names[-1] + if name.endswith(".ipynb"): + name = name + path = "/".join(names[:-1]) + '/' else: - name = names[0] - if name.endswith(".ipynb"): - name = name - path = None - else: - name = None - path = notebook_path+'/' + name = None + path = "/".join(names) + '/' return name, path - + def url_encode(self, path): parts = path.split('/') return os.path.join(*[quote(p) for p in parts]) diff --git a/IPython/html/services/notebooks/tests/test_nbmanager.py b/IPython/html/services/notebooks/tests/test_nbmanager.py index 3a745ca..e8370c8 100644 --- a/IPython/html/services/notebooks/tests/test_nbmanager.py +++ b/IPython/html/services/notebooks/tests/test_nbmanager.py @@ -40,10 +40,17 @@ class TestNotebookManager(TestCase): name, path = nm.named_notebook_path('hello') self.assertEqual(name, None) self.assertEqual(path, 'hello/') + + name, path = nm.named_notebook_path('/') + self.assertEqual(name, None) name, path = nm.named_notebook_path('hello.ipynb') self.assertEqual(name, 'hello.ipynb') - self.assertEqual(path, None) + self.assertEqual(path, '/') + + name, path = nm.named_notebook_path('/hello.ipynb') + self.assertEqual(name, 'hello.ipynb') + self.assertEqual(path, '/') name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb') self.assertEqual(name, 'hello.ipynb')