##// END OF EJS Templates
Rename get_model() to get()
Thomas Kluyver -
Show More
@@ -28,7 +28,7 class FilesHandler(IPythonHandler):
28 28 else:
29 29 name = path
30 30
31 model = cm.get_model(path)
31 model = cm.get(path)
32 32
33 33 if self.get_argument("download", False):
34 34 self.set_header('Content-Disposition','attachment; filename="%s"' % name)
@@ -81,7 +81,7 class NbconvertFileHandler(IPythonHandler):
81 81 exporter = get_exporter(format, config=self.config, log=self.log)
82 82
83 83 path = path.strip('/')
84 model = self.contents_manager.get_model(path=path)
84 model = self.contents_manager.get(path=path)
85 85 name = model['name']
86 86
87 87 self.set_header('Last-Modified', model['last_modified'])
@@ -200,7 +200,7 class FileContentsManager(ContentsManager):
200 200 self.log.debug("%s not a regular file", os_path)
201 201 continue
202 202 if self.should_list(name) and not is_hidden(os_path, self.root_dir):
203 contents.append(self.get_model(
203 contents.append(self.get(
204 204 path='%s/%s' % (path, name),
205 205 content=False)
206 206 )
@@ -266,7 +266,7 class FileContentsManager(ContentsManager):
266 266 self.validate_notebook_model(model)
267 267 return model
268 268
269 def get_model(self, path, content=True, type_=None, format=None):
269 def get(self, path, content=True, type_=None, format=None):
270 270 """ Takes a path for an entity and returns its model
271 271
272 272 Parameters
@@ -380,7 +380,7 class FileContentsManager(ContentsManager):
380 380 self.validate_notebook_model(model)
381 381 validation_message = model.get('message', None)
382 382
383 model = self.get_model(path, content=False)
383 model = self.get(path, content=False)
384 384 if validation_message:
385 385 model['message'] = validation_message
386 386 return model
@@ -395,7 +395,7 class FileContentsManager(ContentsManager):
395 395 new_path = model.get('path', path).strip('/')
396 396 if path != new_path:
397 397 self.rename(path, new_path)
398 model = self.get_model(new_path, content=False)
398 model = self.get(new_path, content=False)
399 399 return model
400 400
401 401 def delete(self, path):
@@ -66,7 +66,7 class ContentsHandler(IPythonHandler):
66 66 if format not in {None, 'text', 'base64'}:
67 67 raise web.HTTPError(400, u'Format %r is invalid' % format)
68 68
69 model = self.contents_manager.get_model(path=path, type_=type_, format=format)
69 model = self.contents_manager.get(path=path, type_=type_, format=format)
70 70 if model['type'] == 'directory':
71 71 # group listing by type, then by name (case-insensitive)
72 72 # FIXME: sorting should be done in the frontends
@@ -135,7 +135,7 class ContentsManager(LoggingConfigurable):
135 135 """
136 136 return self.file_exists(path) or self.dir_exists(path)
137 137
138 def get_model(self, path, content=True, type_=None, format=None):
138 def get(self, path, content=True, type_=None, format=None):
139 139 """Get the model of a file or directory with or without content."""
140 140 raise NotImplementedError('must be implemented in a subclass')
141 141
@@ -300,7 +300,7 class ContentsManager(LoggingConfigurable):
300 300 from_dir = ''
301 301 from_name = path
302 302
303 model = self.get_model(path)
303 model = self.get(path)
304 304 model.pop('path', None)
305 305 model.pop('name', None)
306 306 if model['type'] == 'directory':
@@ -328,7 +328,7 class ContentsManager(LoggingConfigurable):
328 328 path : string
329 329 The path of a notebook
330 330 """
331 model = self.get_model(path)
331 model = self.get(path)
332 332 nb = model['content']
333 333 self.log.warn("Trusting notebook %s", path)
334 334 self.notary.mark_cells(nb, True)
@@ -105,7 +105,7 class TestContentsManager(TestCase):
105 105 name = model['name']
106 106 path = model['path']
107 107
108 full_model = cm.get_model(path)
108 full_model = cm.get(path)
109 109 nb = full_model['content']
110 110 self.add_code_cell(nb)
111 111
@@ -152,27 +152,27 class TestContentsManager(TestCase):
152 152 path = model['path']
153 153
154 154 # Check that we 'get' on the notebook we just created
155 model2 = cm.get_model(path)
155 model2 = cm.get(path)
156 156 assert isinstance(model2, dict)
157 157 self.assertIn('name', model2)
158 158 self.assertIn('path', model2)
159 159 self.assertEqual(model['name'], name)
160 160 self.assertEqual(model['path'], path)
161 161
162 nb_as_file = cm.get_model(path, content=True, type_='file')
162 nb_as_file = cm.get(path, content=True, type_='file')
163 163 self.assertEqual(nb_as_file['path'], path)
164 164 self.assertEqual(nb_as_file['type'], 'file')
165 165 self.assertEqual(nb_as_file['format'], 'text')
166 166 self.assertNotIsInstance(nb_as_file['content'], dict)
167 167
168 nb_as_bin_file = cm.get_model(path, content=True, type_='file', format='base64')
168 nb_as_bin_file = cm.get(path, content=True, type_='file', format='base64')
169 169 self.assertEqual(nb_as_bin_file['format'], 'base64')
170 170
171 171 # Test in sub-directory
172 172 sub_dir = '/foo/'
173 173 self.make_dir(cm.root_dir, 'foo')
174 174 model = cm.new_untitled(path=sub_dir, ext='.ipynb')
175 model2 = cm.get_model(sub_dir + name)
175 model2 = cm.get(sub_dir + name)
176 176 assert isinstance(model2, dict)
177 177 self.assertIn('name', model2)
178 178 self.assertIn('path', model2)
@@ -181,11 +181,11 class TestContentsManager(TestCase):
181 181 self.assertEqual(model2['path'], '{0}/{1}'.format(sub_dir.strip('/'), name))
182 182
183 183 # Test getting directory model
184 dirmodel = cm.get_model('foo')
184 dirmodel = cm.get('foo')
185 185 self.assertEqual(dirmodel['type'], 'directory')
186 186
187 187 with self.assertRaises(HTTPError):
188 cm.get_model('foo', type_='file')
188 cm.get('foo', type_='file')
189 189
190 190
191 191 @dec.skip_win32
@@ -198,7 +198,7 class TestContentsManager(TestCase):
198 198
199 199 # create a broken symlink
200 200 os.symlink("target", os.path.join(os_path, "bad symlink"))
201 model = cm.get_model(path)
201 model = cm.get(path)
202 202 self.assertEqual(model['content'], [file_model])
203 203
204 204 @dec.skip_win32
@@ -213,8 +213,8 class TestContentsManager(TestCase):
213 213
214 214 # create a good symlink
215 215 os.symlink(file_model['name'], os.path.join(os_path, name))
216 symlink_model = cm.get_model(path, content=False)
217 dir_model = cm.get_model(parent)
216 symlink_model = cm.get(path, content=False)
217 dir_model = cm.get(parent)
218 218 self.assertEqual(
219 219 sorted(dir_model['content'], key=lambda x: x['name']),
220 220 [symlink_model, file_model],
@@ -236,7 +236,7 class TestContentsManager(TestCase):
236 236 self.assertEqual(model['name'], 'test.ipynb')
237 237
238 238 # Make sure the old name is gone
239 self.assertRaises(HTTPError, cm.get_model, path)
239 self.assertRaises(HTTPError, cm.get, path)
240 240
241 241 # Test in sub-directory
242 242 # Create a directory and notebook in that directory
@@ -257,7 +257,7 class TestContentsManager(TestCase):
257 257 self.assertEqual(model['path'], new_path)
258 258
259 259 # Make sure the old name is gone
260 self.assertRaises(HTTPError, cm.get_model, path)
260 self.assertRaises(HTTPError, cm.get, path)
261 261
262 262 def test_save(self):
263 263 cm = self.contents_manager
@@ -267,7 +267,7 class TestContentsManager(TestCase):
267 267 path = model['path']
268 268
269 269 # Get the model with 'content'
270 full_model = cm.get_model(path)
270 full_model = cm.get(path)
271 271
272 272 # Save the notebook
273 273 model = cm.save(full_model, path)
@@ -284,7 +284,7 class TestContentsManager(TestCase):
284 284 model = cm.new_untitled(path=sub_dir, type='notebook')
285 285 name = model['name']
286 286 path = model['path']
287 model = cm.get_model(path)
287 model = cm.get(path)
288 288
289 289 # Change the name in the model for rename
290 290 model = cm.save(model, path)
@@ -303,7 +303,7 class TestContentsManager(TestCase):
303 303 cm.delete(path)
304 304
305 305 # Check that a 'get' on the deleted notebook raises and error
306 self.assertRaises(HTTPError, cm.get_model, path)
306 self.assertRaises(HTTPError, cm.get, path)
307 307
308 308 def test_copy(self):
309 309 cm = self.contents_manager
@@ -326,12 +326,12 class TestContentsManager(TestCase):
326 326 cm = self.contents_manager
327 327 nb, name, path = self.new_notebook()
328 328
329 untrusted = cm.get_model(path)['content']
329 untrusted = cm.get(path)['content']
330 330 assert not cm.notary.check_cells(untrusted)
331 331
332 332 # print(untrusted)
333 333 cm.trust_notebook(path)
334 trusted = cm.get_model(path)['content']
334 trusted = cm.get(path)['content']
335 335 # print(trusted)
336 336 assert cm.notary.check_cells(trusted)
337 337
@@ -345,7 +345,7 class TestContentsManager(TestCase):
345 345 assert not cell.metadata.trusted
346 346
347 347 cm.trust_notebook(path)
348 nb = cm.get_model(path)['content']
348 nb = cm.get(path)['content']
349 349 for cell in nb.cells:
350 350 if cell.cell_type == 'code':
351 351 assert cell.metadata.trusted
@@ -359,7 +359,7 class TestContentsManager(TestCase):
359 359 assert not cm.notary.check_signature(nb)
360 360
361 361 cm.trust_notebook(path)
362 nb = cm.get_model(path)['content']
362 nb = cm.get(path)['content']
363 363 cm.mark_trusted_cells(nb, path)
364 364 cm.check_and_sign(nb, path)
365 365 assert cm.notary.check_signature(nb)
@@ -38,7 +38,7 class TreeHandler(IPythonHandler):
38 38 cm = self.contents_manager
39 39 if cm.file_exists(path):
40 40 # it's not a directory, we have redirecting to do
41 model = cm.get_model(path, content=False)
41 model = cm.get(path, content=False)
42 42 # redirect to /api/notebooks if it's a notebook, otherwise /api/files
43 43 service = 'notebooks' if model['type'] == 'notebook' else 'files'
44 44 url = url_escape(url_path_join(
General Comments 0
You need to be logged in to leave comments. Login now