##// END OF EJS Templates
ContentsManager type kwarg to match model key...
Min RK -
Show More
@@ -317,7 +317,7 b' class FileContentsManager(ContentsManager):'
317 self.validate_notebook_model(model)
317 self.validate_notebook_model(model)
318 return model
318 return model
319
319
320 def get(self, path, content=True, type_=None, format=None):
320 def get(self, path, content=True, type=None, format=None):
321 """ Takes a path for an entity and returns its model
321 """ Takes a path for an entity and returns its model
322
322
323 Parameters
323 Parameters
@@ -326,7 +326,7 b' class FileContentsManager(ContentsManager):'
326 the API path that describes the relative path for the target
326 the API path that describes the relative path for the target
327 content : bool
327 content : bool
328 Whether to include the contents in the reply
328 Whether to include the contents in the reply
329 type_ : str, optional
329 type : str, optional
330 The requested type - 'file', 'notebook', or 'directory'.
330 The requested type - 'file', 'notebook', or 'directory'.
331 Will raise HTTPError 400 if the content doesn't match.
331 Will raise HTTPError 400 if the content doesn't match.
332 format : str, optional
332 format : str, optional
@@ -346,14 +346,14 b' class FileContentsManager(ContentsManager):'
346
346
347 os_path = self._get_os_path(path)
347 os_path = self._get_os_path(path)
348 if os.path.isdir(os_path):
348 if os.path.isdir(os_path):
349 if type_ not in (None, 'directory'):
349 if type not in (None, 'directory'):
350 raise web.HTTPError(400,
350 raise web.HTTPError(400,
351 u'%s is a directory, not a %s' % (path, type_), reason='bad type')
351 u'%s is a directory, not a %s' % (path, type), reason='bad type')
352 model = self._dir_model(path, content=content)
352 model = self._dir_model(path, content=content)
353 elif type_ == 'notebook' or (type_ is None and path.endswith('.ipynb')):
353 elif type == 'notebook' or (type is None and path.endswith('.ipynb')):
354 model = self._notebook_model(path, content=content)
354 model = self._notebook_model(path, content=content)
355 else:
355 else:
356 if type_ == 'directory':
356 if type == 'directory':
357 raise web.HTTPError(400,
357 raise web.HTTPError(400,
358 u'%s is not a directory', reason='bad type')
358 u'%s is not a directory', reason='bad type')
359 model = self._file_model(path, content=content, format=format)
359 model = self._file_model(path, content=content, format=format)
@@ -59,15 +59,15 b' class ContentsHandler(IPythonHandler):'
59 of the files and directories it contains.
59 of the files and directories it contains.
60 """
60 """
61 path = path or ''
61 path = path or ''
62 type_ = self.get_query_argument('type', default=None)
62 type = self.get_query_argument('type', default=None)
63 if type_ not in {None, 'directory', 'file', 'notebook'}:
63 if type not in {None, 'directory', 'file', 'notebook'}:
64 raise web.HTTPError(400, u'Type %r is invalid' % type_)
64 raise web.HTTPError(400, u'Type %r is invalid' % type)
65
65
66 format = self.get_query_argument('format', default=None)
66 format = self.get_query_argument('format', default=None)
67 if format not in {None, 'text', 'base64'}:
67 if format not in {None, 'text', 'base64'}:
68 raise web.HTTPError(400, u'Format %r is invalid' % format)
68 raise web.HTTPError(400, u'Format %r is invalid' % format)
69
69
70 model = self.contents_manager.get(path=path, type_=type_, format=format)
70 model = self.contents_manager.get(path=path, type=type, format=format)
71 if model['type'] == 'directory':
71 if model['type'] == 'directory':
72 # group listing by type, then by name (case-insensitive)
72 # group listing by type, then by name (case-insensitive)
73 # FIXME: sorting should be done in the frontends
73 # FIXME: sorting should be done in the frontends
@@ -137,7 +137,7 b' class ContentsManager(LoggingConfigurable):'
137 """
137 """
138 return self.file_exists(path) or self.dir_exists(path)
138 return self.file_exists(path) or self.dir_exists(path)
139
139
140 def get(self, path, content=True, type_=None, format=None):
140 def get(self, path, content=True, type=None, format=None):
141 """Get the model of a file or directory with or without content."""
141 """Get the model of a file or directory with or without content."""
142 raise NotImplementedError('must be implemented in a subclass')
142 raise NotImplementedError('must be implemented in a subclass')
143
143
@@ -46,10 +46,10 b' class API(object):'
46 def list(self, path='/'):
46 def list(self, path='/'):
47 return self._req('GET', path)
47 return self._req('GET', path)
48
48
49 def read(self, path, type_=None, format=None):
49 def read(self, path, type=None, format=None):
50 params = {}
50 params = {}
51 if type_ is not None:
51 if type is not None:
52 params['type'] = type_
52 params['type'] = type
53 if format is not None:
53 if format is not None:
54 params['format'] = format
54 params['format'] = format
55 return self._req('GET', path, params=params)
55 return self._req('GET', path, params=params)
@@ -250,7 +250,7 b' class APITest(NotebookTestBase):'
250
250
251 # Specifying format=text should fail on a non-UTF-8 file
251 # Specifying format=text should fail on a non-UTF-8 file
252 with assert_http_error(400):
252 with assert_http_error(400):
253 self.api.read('foo/bar/baz.blob', type_='file', format='text')
253 self.api.read('foo/bar/baz.blob', type='file', format='text')
254
254
255 def test_get_binary_file_contents(self):
255 def test_get_binary_file_contents(self):
256 for d, name in self.dirs_nbs:
256 for d, name in self.dirs_nbs:
@@ -270,10 +270,10 b' class APITest(NotebookTestBase):'
270
270
271 def test_get_bad_type(self):
271 def test_get_bad_type(self):
272 with assert_http_error(400):
272 with assert_http_error(400):
273 self.api.read(u'unicodé', type_='file') # this is a directory
273 self.api.read(u'unicodé', type='file') # this is a directory
274
274
275 with assert_http_error(400):
275 with assert_http_error(400):
276 self.api.read(u'unicodé/innonascii.ipynb', type_='directory')
276 self.api.read(u'unicodé/innonascii.ipynb', type='directory')
277
277
278 def _check_created(self, resp, path, type='notebook'):
278 def _check_created(self, resp, path, type='notebook'):
279 self.assertEqual(resp.status_code, 201)
279 self.assertEqual(resp.status_code, 201)
@@ -159,13 +159,13 b' class TestContentsManager(TestCase):'
159 self.assertEqual(model['name'], name)
159 self.assertEqual(model['name'], name)
160 self.assertEqual(model['path'], path)
160 self.assertEqual(model['path'], path)
161
161
162 nb_as_file = cm.get(path, content=True, type_='file')
162 nb_as_file = cm.get(path, content=True, type='file')
163 self.assertEqual(nb_as_file['path'], path)
163 self.assertEqual(nb_as_file['path'], path)
164 self.assertEqual(nb_as_file['type'], 'file')
164 self.assertEqual(nb_as_file['type'], 'file')
165 self.assertEqual(nb_as_file['format'], 'text')
165 self.assertEqual(nb_as_file['format'], 'text')
166 self.assertNotIsInstance(nb_as_file['content'], dict)
166 self.assertNotIsInstance(nb_as_file['content'], dict)
167
167
168 nb_as_bin_file = cm.get(path, content=True, type_='file', format='base64')
168 nb_as_bin_file = cm.get(path, content=True, type='file', format='base64')
169 self.assertEqual(nb_as_bin_file['format'], 'base64')
169 self.assertEqual(nb_as_bin_file['format'], 'base64')
170
170
171 # Test in sub-directory
171 # Test in sub-directory
@@ -185,7 +185,7 b' class TestContentsManager(TestCase):'
185 self.assertEqual(dirmodel['type'], 'directory')
185 self.assertEqual(dirmodel['type'], 'directory')
186
186
187 with self.assertRaises(HTTPError):
187 with self.assertRaises(HTTPError):
188 cm.get('foo', type_='file')
188 cm.get('foo', type='file')
189
189
190
190
191 @dec.skip_win32
191 @dec.skip_win32
General Comments 0
You need to be logged in to leave comments. Login now