Rename get_model() to get()

This commit is contained in:
Thomas Kluyver 2014-11-11 14:51:21 -08:00
parent 6f48b58b18
commit f1f81e2efa
7 changed files with 30 additions and 30 deletions

View File

@ -28,7 +28,7 @@ class FilesHandler(IPythonHandler):
else:
name = path
model = cm.get_model(path)
model = cm.get(path)
if self.get_argument("download", False):
self.set_header('Content-Disposition','attachment; filename="%s"' % name)

View File

@ -81,7 +81,7 @@ class NbconvertFileHandler(IPythonHandler):
exporter = get_exporter(format, config=self.config, log=self.log)
path = path.strip('/')
model = self.contents_manager.get_model(path=path)
model = self.contents_manager.get(path=path)
name = model['name']
self.set_header('Last-Modified', model['last_modified'])

View File

@ -200,7 +200,7 @@ class FileContentsManager(ContentsManager):
self.log.debug("%s not a regular file", os_path)
continue
if self.should_list(name) and not is_hidden(os_path, self.root_dir):
contents.append(self.get_model(
contents.append(self.get(
path='%s/%s' % (path, name),
content=False)
)
@ -266,7 +266,7 @@ class FileContentsManager(ContentsManager):
self.validate_notebook_model(model)
return model
def get_model(self, path, content=True, type_=None, format=None):
def get(self, path, content=True, type_=None, format=None):
""" Takes a path for an entity and returns its model
Parameters
@ -380,7 +380,7 @@ class FileContentsManager(ContentsManager):
self.validate_notebook_model(model)
validation_message = model.get('message', None)
model = self.get_model(path, content=False)
model = self.get(path, content=False)
if validation_message:
model['message'] = validation_message
return model
@ -395,7 +395,7 @@ class FileContentsManager(ContentsManager):
new_path = model.get('path', path).strip('/')
if path != new_path:
self.rename(path, new_path)
model = self.get_model(new_path, content=False)
model = self.get(new_path, content=False)
return model
def delete(self, path):

View File

@ -66,7 +66,7 @@ class ContentsHandler(IPythonHandler):
if format not in {None, 'text', 'base64'}:
raise web.HTTPError(400, u'Format %r is invalid' % format)
model = self.contents_manager.get_model(path=path, type_=type_, format=format)
model = self.contents_manager.get(path=path, type_=type_, format=format)
if model['type'] == 'directory':
# group listing by type, then by name (case-insensitive)
# FIXME: sorting should be done in the frontends

View File

@ -135,7 +135,7 @@ class ContentsManager(LoggingConfigurable):
"""
return self.file_exists(path) or self.dir_exists(path)
def get_model(self, path, content=True, type_=None, format=None):
def get(self, path, content=True, type_=None, format=None):
"""Get the model of a file or directory with or without content."""
raise NotImplementedError('must be implemented in a subclass')
@ -300,7 +300,7 @@ class ContentsManager(LoggingConfigurable):
from_dir = ''
from_name = path
model = self.get_model(path)
model = self.get(path)
model.pop('path', None)
model.pop('name', None)
if model['type'] == 'directory':
@ -328,7 +328,7 @@ class ContentsManager(LoggingConfigurable):
path : string
The path of a notebook
"""
model = self.get_model(path)
model = self.get(path)
nb = model['content']
self.log.warn("Trusting notebook %s", path)
self.notary.mark_cells(nb, True)

View File

@ -105,7 +105,7 @@ class TestContentsManager(TestCase):
name = model['name']
path = model['path']
full_model = cm.get_model(path)
full_model = cm.get(path)
nb = full_model['content']
self.add_code_cell(nb)
@ -152,27 +152,27 @@ class TestContentsManager(TestCase):
path = model['path']
# Check that we 'get' on the notebook we just created
model2 = cm.get_model(path)
model2 = cm.get(path)
assert isinstance(model2, dict)
self.assertIn('name', model2)
self.assertIn('path', model2)
self.assertEqual(model['name'], name)
self.assertEqual(model['path'], path)
nb_as_file = cm.get_model(path, content=True, type_='file')
nb_as_file = cm.get(path, content=True, type_='file')
self.assertEqual(nb_as_file['path'], path)
self.assertEqual(nb_as_file['type'], 'file')
self.assertEqual(nb_as_file['format'], 'text')
self.assertNotIsInstance(nb_as_file['content'], dict)
nb_as_bin_file = cm.get_model(path, content=True, type_='file', format='base64')
nb_as_bin_file = cm.get(path, content=True, type_='file', format='base64')
self.assertEqual(nb_as_bin_file['format'], 'base64')
# Test in sub-directory
sub_dir = '/foo/'
self.make_dir(cm.root_dir, 'foo')
model = cm.new_untitled(path=sub_dir, ext='.ipynb')
model2 = cm.get_model(sub_dir + name)
model2 = cm.get(sub_dir + name)
assert isinstance(model2, dict)
self.assertIn('name', model2)
self.assertIn('path', model2)
@ -181,11 +181,11 @@ class TestContentsManager(TestCase):
self.assertEqual(model2['path'], '{0}/{1}'.format(sub_dir.strip('/'), name))
# Test getting directory model
dirmodel = cm.get_model('foo')
dirmodel = cm.get('foo')
self.assertEqual(dirmodel['type'], 'directory')
with self.assertRaises(HTTPError):
cm.get_model('foo', type_='file')
cm.get('foo', type_='file')
@dec.skip_win32
@ -198,7 +198,7 @@ class TestContentsManager(TestCase):
# create a broken symlink
os.symlink("target", os.path.join(os_path, "bad symlink"))
model = cm.get_model(path)
model = cm.get(path)
self.assertEqual(model['content'], [file_model])
@dec.skip_win32
@ -213,8 +213,8 @@ class TestContentsManager(TestCase):
# create a good symlink
os.symlink(file_model['name'], os.path.join(os_path, name))
symlink_model = cm.get_model(path, content=False)
dir_model = cm.get_model(parent)
symlink_model = cm.get(path, content=False)
dir_model = cm.get(parent)
self.assertEqual(
sorted(dir_model['content'], key=lambda x: x['name']),
[symlink_model, file_model],
@ -236,7 +236,7 @@ class TestContentsManager(TestCase):
self.assertEqual(model['name'], 'test.ipynb')
# Make sure the old name is gone
self.assertRaises(HTTPError, cm.get_model, path)
self.assertRaises(HTTPError, cm.get, path)
# Test in sub-directory
# Create a directory and notebook in that directory
@ -257,7 +257,7 @@ class TestContentsManager(TestCase):
self.assertEqual(model['path'], new_path)
# Make sure the old name is gone
self.assertRaises(HTTPError, cm.get_model, path)
self.assertRaises(HTTPError, cm.get, path)
def test_save(self):
cm = self.contents_manager
@ -267,7 +267,7 @@ class TestContentsManager(TestCase):
path = model['path']
# Get the model with 'content'
full_model = cm.get_model(path)
full_model = cm.get(path)
# Save the notebook
model = cm.save(full_model, path)
@ -284,7 +284,7 @@ class TestContentsManager(TestCase):
model = cm.new_untitled(path=sub_dir, type='notebook')
name = model['name']
path = model['path']
model = cm.get_model(path)
model = cm.get(path)
# Change the name in the model for rename
model = cm.save(model, path)
@ -303,7 +303,7 @@ class TestContentsManager(TestCase):
cm.delete(path)
# Check that a 'get' on the deleted notebook raises and error
self.assertRaises(HTTPError, cm.get_model, path)
self.assertRaises(HTTPError, cm.get, path)
def test_copy(self):
cm = self.contents_manager
@ -326,12 +326,12 @@ class TestContentsManager(TestCase):
cm = self.contents_manager
nb, name, path = self.new_notebook()
untrusted = cm.get_model(path)['content']
untrusted = cm.get(path)['content']
assert not cm.notary.check_cells(untrusted)
# print(untrusted)
cm.trust_notebook(path)
trusted = cm.get_model(path)['content']
trusted = cm.get(path)['content']
# print(trusted)
assert cm.notary.check_cells(trusted)
@ -345,7 +345,7 @@ class TestContentsManager(TestCase):
assert not cell.metadata.trusted
cm.trust_notebook(path)
nb = cm.get_model(path)['content']
nb = cm.get(path)['content']
for cell in nb.cells:
if cell.cell_type == 'code':
assert cell.metadata.trusted
@ -359,7 +359,7 @@ class TestContentsManager(TestCase):
assert not cm.notary.check_signature(nb)
cm.trust_notebook(path)
nb = cm.get_model(path)['content']
nb = cm.get(path)['content']
cm.mark_trusted_cells(nb, path)
cm.check_and_sign(nb, path)
assert cm.notary.check_signature(nb)

View File

@ -38,7 +38,7 @@ class TreeHandler(IPythonHandler):
cm = self.contents_manager
if cm.file_exists(path):
# it's not a directory, we have redirecting to do
model = cm.get_model(path, content=False)
model = cm.get(path, content=False)
# redirect to /api/notebooks if it's a notebook, otherwise /api/files
service = 'notebooks' if model['type'] == 'notebook' else 'files'
url = url_escape(url_path_join(