##// END OF EJS Templates
Adds configuration options to use Google Drive content manager...
Adds configuration options to use Google Drive content manager Adds the key contentmanager_js_source to webapp_settings that allows for specifying the content manager JavaScript source file. Also adds a NotebookManager subclass, ClientSideNotebookManager, which does minimal logic. This class is used when the JavaScript content manager doesn't use the Python notebook manager, but rather implements that logic client side, as is the case for the Google Drive based content manager. A sample command line that uses the Google Drive content manager, and the ClientSideNotebookManager, is ipython notebook --NotebookApp.webapp_settings="{'contentmanager_js_source': 'base/js/drive_contentmanager'}" --NotebookApp.notebook_manager_class="IPython.html.services.notebooks.clientsidenbmanager.ClientSideNotebookManager"

File last commit:

r18603:cd1bfb05
r18639:28c27a69
Show More
reader.py
82 lines | 2.0 KiB | text/x-python | PythonLexer
"""API for reading notebooks of different versions"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import json
class NotJSONError(ValueError):
pass
def parse_json(s, **kwargs):
"""Parse a JSON string into a dict."""
try:
nb_dict = json.loads(s, **kwargs)
except ValueError:
# Limit the error message to 80 characters. Display whatever JSON will fit.
raise NotJSONError(("Notebook does not appear to be JSON: %r" % s)[:77] + "...")
return nb_dict
# High level API
def get_version(nb):
"""Get the version of a notebook.
Parameters
----------
nb : dict
NotebookNode or dict containing notebook data.
Returns
-------
Tuple containing major (int) and minor (int) version numbers
"""
major = nb.get('nbformat', 1)
minor = nb.get('nbformat_minor', 0)
return (major, minor)
def reads(s, **kwargs):
"""Read a notebook from a json string and return the
NotebookNode object.
This function properly reads notebooks of any version. No version
conversion is performed.
Parameters
----------
s : unicode
The raw unicode string to read the notebook from.
Returns
-------
nb : NotebookNode
The notebook that was read.
"""
from . import versions, NBFormatError
nb_dict = parse_json(s, **kwargs)
(major, minor) = get_version(nb_dict)
if major in versions:
return versions[major].to_notebook_json(nb_dict, minor=minor)
else:
raise NBFormatError('Unsupported nbformat version %s' % major)
def read(fp, **kwargs):
"""Read a notebook from a file and return the NotebookNode object.
This function properly reads notebooks of any version. No version
conversion is performed.
Parameters
----------
fp : file
Any file-like object with a read method.
Returns
-------
nb : NotebookNode
The notebook that was read.
"""
return reads(fp.read(), **kwargs)