nbbase.py
38 lines
| 951 B
| text/x-python
|
PythonLexer
MinRK
|
r18568 | """The basic dict based notebook format. | ||
The Python representation of a notebook is a nested structure of | ||||
dictionary subclasses that support attribute access | ||||
(IPython.utils.ipstruct.Struct). The functions in this module are merely | ||||
helpers to build the structs in the right form. | ||||
""" | ||||
# Copyright (c) IPython Development Team. | ||||
# Distributed under the terms of the Modified BSD License. | ||||
import pprint | ||||
import uuid | ||||
from IPython.utils.ipstruct import Struct | ||||
from IPython.utils.py3compat import cast_unicode, unicode_type | ||||
# Change this when incrementing the nbformat version | ||||
MinRK
|
r18573 | nbformat = 4 | ||
MinRK
|
r18568 | nbformat_minor = 0 | ||
MinRK
|
r18573 | nbformat_schema = 'v4.withref.json' | ||
MinRK
|
r18568 | |||
class NotebookNode(Struct): | ||||
pass | ||||
def from_dict(d): | ||||
if isinstance(d, dict): | ||||
newd = NotebookNode() | ||||
for k,v in d.items(): | ||||
newd[k] = from_dict(v) | ||||
return newd | ||||
elif isinstance(d, (tuple, list)): | ||||
return [from_dict(i) for i in d] | ||||
else: | ||||
return d | ||||