##// END OF EJS Templates
simplified named_notebook_path implementation...
Paul Ivanov -
Show More
@@ -54,29 +54,21 b' class NotebookManager(LoggingConfigurable):'
54 Returns
54 Returns
55 -------
55 -------
56 name : string or None
56 name : string or None
57 the filename of the notebook, or None if not a .ipynb extesnsion
57 the filename of the notebook, or None if not a .ipynb extension
58 path : string or None
58 path : string
59 the path to the directory which contains the notebook
59 the path to the directory which contains the notebook
60 """
60 """
61 names = notebook_path.split('/')
61 names = notebook_path.split('/')
62 if len(names) > 1:
62
63 name = names[-1]
63 name = names[-1]
64 if name.endswith(".ipynb"):
64 if name.endswith(".ipynb"):
65 name = name
65 name = name
66 path = notebook_path[:-1]+'/'
66 path = "/".join(names[:-1]) + '/'
67 else:
68 name = None
69 path = notebook_path+'/'
70 else:
67 else:
71 name = names[0]
68 name = None
72 if name.endswith(".ipynb"):
69 path = "/".join(names) + '/'
73 name = name
74 path = None
75 else:
76 name = None
77 path = notebook_path+'/'
78 return name, path
70 return name, path
79
71
80 def url_encode(self, path):
72 def url_encode(self, path):
81 parts = path.split('/')
73 parts = path.split('/')
82 return os.path.join(*[quote(p) for p in parts])
74 return os.path.join(*[quote(p) for p in parts])
@@ -40,10 +40,17 b' class TestNotebookManager(TestCase):'
40 name, path = nm.named_notebook_path('hello')
40 name, path = nm.named_notebook_path('hello')
41 self.assertEqual(name, None)
41 self.assertEqual(name, None)
42 self.assertEqual(path, 'hello/')
42 self.assertEqual(path, 'hello/')
43
44 name, path = nm.named_notebook_path('/')
45 self.assertEqual(name, None)
43
46
44 name, path = nm.named_notebook_path('hello.ipynb')
47 name, path = nm.named_notebook_path('hello.ipynb')
45 self.assertEqual(name, 'hello.ipynb')
48 self.assertEqual(name, 'hello.ipynb')
46 self.assertEqual(path, None)
49 self.assertEqual(path, '/')
50
51 name, path = nm.named_notebook_path('/hello.ipynb')
52 self.assertEqual(name, 'hello.ipynb')
53 self.assertEqual(path, '/')
47
54
48 name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
55 name, path = nm.named_notebook_path('/this/is/a/path/hello.ipynb')
49 self.assertEqual(name, 'hello.ipynb')
56 self.assertEqual(name, 'hello.ipynb')
General Comments 0
You need to be logged in to leave comments. Login now