##// END OF EJS Templates
More review changes....
Brian E. Granger -
Show More
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -43,14 +43,6 b' sys.path.append(os.path.join(os.path.dirname(__file__), "extensions"))'
43 from .config.loader import Config
43 from .config.loader import Config
44 from .core import release
44 from .core import release
45 from .core.application import Application
45 from .core.application import Application
46 # Todo: Should these be imported here? We need to rethink what is imported in
47 # this module.
48 #from .core.display import (
49 # display, display_pretty, display_html, display_latex,
50 # display_png, display_jpeg, display_svg, display_json,
51 # display_javascript, HTML, SVG, Math, Image, JSON,
52 # Javascript, Pretty
53 #)
54 from .frontend.terminal.embed import embed
46 from .frontend.terminal.embed import embed
55 from .core.error import TryNext
47 from .core.error import TryNext
56 from .core.interactiveshell import InteractiveShell
48 from .core.interactiveshell import InteractiveShell
@@ -48,8 +48,7 b' from IPython.core.error import UsageError'
48 from IPython.core.fakemodule import FakeModule
48 from IPython.core.fakemodule import FakeModule
49 from IPython.core.profiledir import ProfileDir
49 from IPython.core.profiledir import ProfileDir
50 from IPython.core.macro import Macro
50 from IPython.core.macro import Macro
51 from IPython.core import magic_arguments
51 from IPython.core import magic_arguments, page
52 from IPython.core import page
53 from IPython.core.prefilter import ESC_MAGIC
52 from IPython.core.prefilter import ESC_MAGIC
54 from IPython.lib.pylabtools import mpl_runner
53 from IPython.lib.pylabtools import mpl_runner
55 from IPython.testing.skipdoctest import skip_doctest
54 from IPython.testing.skipdoctest import skip_doctest
@@ -195,11 +195,12 b' class ProfileCreate(BaseIPythonApplication):'
195 apps.append(IPythonQtConsoleApp)
195 apps.append(IPythonQtConsoleApp)
196 try:
196 try:
197 from IPython.frontend.html.notebook.notebookapp import IPythonNotebookApp
197 from IPython.frontend.html.notebook.notebookapp import IPythonNotebookApp
198 except Exception:
198 except ImportError:
199 # this should be ImportError, but under weird circumstances
200 # this might be an AttributeError, or possibly others
201 # in any case, nothing should cause the profile creation to crash.
202 pass
199 pass
200 except Exception:
201 self.log.debug('Unexpected error when importing IPythonNotebookApp',
202 exc_info=True
203 )
203 else:
204 else:
204 apps.append(IPythonNotebookApp)
205 apps.append(IPythonNotebookApp)
205 if self.parallel:
206 if self.parallel:
@@ -1,9 +1,20 b''
1 """Tornado handlers for the notebook."""
1 """Tornado handlers for the notebook.
2
3 Authors:
4
5 * Brian Granger
6 """
2
7
3 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
4 # Imports
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
5 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
6
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
7
18
8 from tornado import web
19 from tornado import web
9 from tornado import websocket
20 from tornado import websocket
@@ -1,10 +1,15 b''
1 """A kernel manager for multiple kernels."""
1 """A kernel manager for multiple kernels.
2
3 Authors:
4
5 * Brian Granger
6 """
2
7
3 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
4 # Copyright (C) 2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
5 #
10 #
6 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING.txt, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
9
14
10 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
@@ -1,10 +1,15 b''
1 """A tornado based IPython notebook server."""
1 """A tornado based IPython notebook server.
2
3 Authors:
4
5 * Brian Granger
6 """
2
7
3 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
4 # Copyright (C) 2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
5 #
10 #
6 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING.txt, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
9
14
10 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
@@ -194,9 +199,9 b' class IPythonNotebookApp(BaseIPythonApplication):'
194 argv = sys.argv[1:]
199 argv = sys.argv[1:]
195
200
196 self.kernel_argv = list(argv) # copy
201 self.kernel_argv = list(argv) # copy
197 # kernel should inherit default config file from frontend
202 # Kernel should inherit default config file from frontend
198 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
203 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
199 # scrub frontend-specific flags
204 # Scrub frontend-specific flags
200 for a in argv:
205 for a in argv:
201 if a.startswith('-') and a.lstrip('-') in notebook_flags:
206 if a.startswith('-') and a.lstrip('-') in notebook_flags:
202 self.kernel_argv.remove(a)
207 self.kernel_argv.remove(a)
@@ -205,7 +210,6 b' class IPythonNotebookApp(BaseIPythonApplication):'
205 alias = a.lstrip('-').split('=')[0]
210 alias = a.lstrip('-').split('=')[0]
206 if alias in notebook_aliases:
211 if alias in notebook_aliases:
207 self.kernel_argv.remove(a)
212 self.kernel_argv.remove(a)
208 print self.kernel_argv
209
213
210 def init_configurables(self):
214 def init_configurables(self):
211 # Don't let Qt or ZMQ swallow KeyboardInterupts.
215 # Don't let Qt or ZMQ swallow KeyboardInterupts.
@@ -241,18 +245,20 b' class IPythonNotebookApp(BaseIPythonApplication):'
241 self.log.critical('WARNING: the notebook server is listening on all IP addresses '
245 self.log.critical('WARNING: the notebook server is listening on all IP addresses '
242 'but not using any encryption or authentication. This is highly '
246 'but not using any encryption or authentication. This is highly '
243 'insecure and not recommended.')
247 'insecure and not recommended.')
244 for i in range(10):
248
249 # Try random ports centered around the default.
250 from random import randint
251 n = 50 # Max number of attempts, keep reasonably large.
252 for port in [self.port] + [self.port + randint(-2*n, 2*n) for i in range(n)]:
245 try:
253 try:
246 port = self.port + i
247 self.http_server.listen(port, self.ip)
254 self.http_server.listen(port, self.ip)
248 except socket.error, e:
255 except socket.error, e:
249 if e.errno != errno.EADDRINUSE:
256 if e.errno != errno.EADDRINUSE:
250 raise
257 raise
251 self.log.info('The port %i is already in use, trying: %i' % (port, port+1))
258 self.log.info('The port %i is already in use, trying another random port.' % port)
252 else:
259 else:
253 self.port = port
260 self.port = port
254 break
261 break
255
256
262
257 def start(self):
263 def start(self):
258 ip = self.ip if self.ip else '[all ip addresses on your system]'
264 ip = self.ip if self.ip else '[all ip addresses on your system]'
@@ -1,8 +1,15 b''
1 """A notebook manager that uses the local file system for storage.
2
3 Authors:
4
5 * Brian Granger
6 """
7
1 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
2 # Copyright (C) 2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
3 #
10 #
4 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
5 # the file COPYING.txt, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
6 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
7
14
8 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
@@ -46,7 +53,7 b' class NotebookManager(LoggingConfigurable):'
46 dict(notebook_id=notebook,name=name)
53 dict(notebook_id=notebook,name=name)
47 """
54 """
48 names = os.listdir(self.notebook_dir)
55 names = os.listdir(self.notebook_dir)
49 names = [name.split(u'.')[0] \
56 names = [name.split(u'.')[0]
50 for name in names if name.endswith(self.filename_ext)]
57 for name in names if name.endswith(self.filename_ext)]
51 data = []
58 data = []
52 for name in names:
59 for name in names:
@@ -76,9 +83,7 b' class NotebookManager(LoggingConfigurable):'
76 if notebook_id not in self.mapping:
83 if notebook_id not in self.mapping:
77 return False
84 return False
78 path = self.get_path_by_name(self.mapping[notebook_id])
85 path = self.get_path_by_name(self.mapping[notebook_id])
79 if not os.path.isfile(path):
86 return os.path.isfile(path)
80 return False
81 return True
82
87
83 def find_path(self, notebook_id):
88 def find_path(self, notebook_id):
84 """Return a full path to a notebook given its notebook_id."""
89 """Return a full path to a notebook given its notebook_id."""
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Cell
9 // Cell
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // CodeCell
9 // CodeCell
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Kernel
9 // Kernel
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Kernel Status widget
9 // Kernel Status widget
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Layout
9 // Layout
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // LeftPanel
9 // LeftPanel
@@ -1,3 +1,10 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
7
1 var IPython = IPython || {};
8 var IPython = IPython || {};
2
9
3 IPython.namespace = function (ns_string) {
10 IPython.namespace = function (ns_string) {
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // On document ready
9 // On document ready
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Notebook
9 // Notebook
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // On document ready
9 // On document ready
@@ -1,6 +1,12 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Cell
9 // NotebookList
4 //============================================================================
10 //============================================================================
5
11
6 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Pager
9 // Pager
@@ -1,6 +1,12 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Cell
9 // PanelSection
4 //============================================================================
10 //============================================================================
5
11
6 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
@@ -1,6 +1,12 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Cell
9 // SaveWidget
4 //============================================================================
10 //============================================================================
5
11
6 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // TextCell
9 // TextCell
@@ -1,3 +1,9 b''
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
1
7
2 //============================================================================
8 //============================================================================
3 // Utilities
9 // Utilities
@@ -3,7 +3,6 b''
3 from unittest import TestCase
3 from unittest import TestCase
4
4
5 from IPython.frontend.html.notebook.kernelmanager import KernelManager
5 from IPython.frontend.html.notebook.kernelmanager import KernelManager
6 from IPython.frontend.html.notebook.sessionmanager import SessionManagerRunningError
7
6
8 class TestKernelManager(TestCase):
7 class TestKernelManager(TestCase):
9
8
@@ -24,16 +23,4 b' class TestKernelManager(TestCase):'
24 self.assert_('hb_port' in port_dict)
23 self.assert_('hb_port' in port_dict)
25 km.get_kernel_process(kid)
24 km.get_kernel_process(kid)
26
25
27 def test_session_manager(self):
28 km = KernelManager()
29 kid = km.start_kernel()
30 sm = km.create_session_manager(kid)
31 self.assert_(sm._running)
32 sm.stop()
33 self.assert_(not sm._running)
34 sm.start()
35 self.assertRaises(SessionManagerRunningError, sm.start)
36 sm.get_iopub_stream()
37 sm.get_shell_stream()
38 sm.session
39
26
@@ -1,9 +1,29 b''
1 import json
1 """Unfinished code for ZMQ/HTTP bridging. We use WebSockets instead.
2
2
3 from tornado import web
3 Authors:
4
5 * Brian Granger
6 """
4
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
19 import json
5 import logging
20 import logging
6
21
22 from tornado import web
23
24 #-----------------------------------------------------------------------------
25 # Code
26 #-----------------------------------------------------------------------------
7
27
8 class ZMQHandler(web.RequestHandler):
28 class ZMQHandler(web.RequestHandler):
9
29
@@ -74,7 +94,3 b' class ZMQXReqHandler(ZMQHandler):'
74 stream.send_json(msg)
94 stream.send_json(msg)
75 stream.on_recv(self._handle_msgs)
95 stream.on_recv(self._handle_msgs)
76
96
77
78
79
80 No newline at end of file
@@ -1,3 +1,21 b''
1 """The official API for working with notebooks in the current format version.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
1 import json
19 import json
2 from xml.etree import ElementTree as ET
20 from xml.etree import ElementTree as ET
3 import re
21 import re
@@ -11,6 +29,9 b' from IPython.nbformat.v2 import ('
11 parse_filename
29 parse_filename
12 )
30 )
13
31
32 #-----------------------------------------------------------------------------
33 # Code
34 #-----------------------------------------------------------------------------
14
35
15 current_nbformat = 2
36 current_nbformat = 2
16
37
@@ -1,3 +1,15 b''
1 """The main module for the v1 notebook format."""
2
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2008-2011 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
1
13
2 from .nbbase import (
14 from .nbbase import (
3 NotebookNode,
15 NotebookNode,
@@ -1,4 +1,15 b''
1 """Convert notebook to the v1 format."""
1
2
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2008-2011 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Code
12 #-----------------------------------------------------------------------------
2
13
3 def convert_to_this_nbformat(nb, orig_version=None):
14 def convert_to_this_nbformat(nb, orig_version=None):
4 raise ValueError('Cannot convert to v1 notebook format')
15 raise ValueError('Cannot convert to v1 notebook format')
@@ -1,10 +1,29 b''
1 """The basic dict based notebook format."""
1 """The basic dict based notebook format.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
2
18
3 import pprint
19 import pprint
4 import uuid
20 import uuid
5
21
6 from IPython.utils.ipstruct import Struct
22 from IPython.utils.ipstruct import Struct
7
23
24 #-----------------------------------------------------------------------------
25 # Code
26 #-----------------------------------------------------------------------------
8
27
9 class NotebookNode(Struct):
28 class NotebookNode(Struct):
10 pass
29 pass
@@ -1,10 +1,29 b''
1 """Read and write notebooks in JSON format."""
1 """Read and write notebooks in JSON format.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
2
18
3 from base64 import encodestring
19 from base64 import encodestring
4 from .rwbase import NotebookReader, NotebookWriter
20 from .rwbase import NotebookReader, NotebookWriter
5 from .nbbase import from_dict
21 from .nbbase import from_dict
6 import json
22 import json
7
23
24 #-----------------------------------------------------------------------------
25 # Code
26 #-----------------------------------------------------------------------------
8
27
9 class JSONReader(NotebookReader):
28 class JSONReader(NotebookReader):
10
29
@@ -1,5 +1,26 b''
1 """Base classes and function for readers and writers.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
1 from base64 import encodestring, decodestring
19 from base64 import encodestring, decodestring
2
20
21 #-----------------------------------------------------------------------------
22 # Code
23 #-----------------------------------------------------------------------------
3
24
4 class NotebookReader(object):
25 class NotebookReader(object):
5
26
@@ -1,3 +1,20 b''
1 """The main API for the v2 notebook format.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
1
18
2 from .nbbase import (
19 from .nbbase import (
3 NotebookNode,
20 NotebookNode,
@@ -18,6 +35,9 b' from .nbpy import to_notebook as to_notebook_py'
18
35
19 from .convert import convert_to_this_nbformat
36 from .convert import convert_to_this_nbformat
20
37
38 #-----------------------------------------------------------------------------
39 # Code
40 #-----------------------------------------------------------------------------
21
41
22 def parse_filename(fname):
42 def parse_filename(fname):
23 """Parse a notebook filename.
43 """Parse a notebook filename.
@@ -1,8 +1,39 b''
1 """Code for converting notebooks to and from the v2 format.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
1 from .nbbase import (
19 from .nbbase import (
2 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output
20 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output
3 )
21 )
4
22
23 #-----------------------------------------------------------------------------
24 # Code
25 #-----------------------------------------------------------------------------
26
5 def convert_to_this_nbformat(nb, orig_version=1):
27 def convert_to_this_nbformat(nb, orig_version=1):
28 """Convert a notebook to the v2 format.
29
30 Parameters
31 ----------
32 nb : NotebookNode
33 The Python representation of the notebook to convert.
34 orig_version : int
35 The original version of the notebook to convert.
36 """
6 if orig_version == 1:
37 if orig_version == 1:
7 newnb = new_notebook()
38 newnb = new_notebook()
8 ws = new_worksheet()
39 ws = new_worksheet()
@@ -17,4 +48,3 b' def convert_to_this_nbformat(nb, orig_version=1):'
17 else:
48 else:
18 raise ValueError('Cannot convert a notebook from v%s to v2' % orig_version)
49 raise ValueError('Cannot convert a notebook from v%s to v2' % orig_version)
19
50
20
@@ -1,10 +1,34 b''
1 """The basic dict based notebook format."""
1 """The basic dict based notebook format.
2
3 The Python representation of a notebook is a nested structure of
4 dictionary subclasses that support attribute access
5 (IPython.utils.ipstruct.Struct). The functions in this module are merely
6 helpers to build the structs in the right form.
7
8 Authors:
9
10 * Brian Granger
11 """
12
13 #-----------------------------------------------------------------------------
14 # Copyright (C) 2008-2011 The IPython Development Team
15 #
16 # Distributed under the terms of the BSD License. The full license is in
17 # the file COPYING, distributed as part of this software.
18 #-----------------------------------------------------------------------------
19
20 #-----------------------------------------------------------------------------
21 # Imports
22 #-----------------------------------------------------------------------------
2
23
3 import pprint
24 import pprint
4 import uuid
25 import uuid
5
26
6 from IPython.utils.ipstruct import Struct
27 from IPython.utils.ipstruct import Struct
7
28
29 #-----------------------------------------------------------------------------
30 # Code
31 #-----------------------------------------------------------------------------
8
32
9 class NotebookNode(Struct):
33 class NotebookNode(Struct):
10 pass
34 pass
@@ -1,10 +1,29 b''
1 """Read and write notebooks in JSON format."""
1 """Read and write notebooks in JSON format.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
2
18
3 from base64 import encodestring
19 from base64 import encodestring
4 from .nbbase import from_dict
20 from .nbbase import from_dict
5 from .rwbase import NotebookReader, NotebookWriter, base64_decode
21 from .rwbase import NotebookReader, NotebookWriter, base64_decode
6 import json
22 import json
7
23
24 #-----------------------------------------------------------------------------
25 # Code
26 #-----------------------------------------------------------------------------
8
27
9 class BytesEncoder(json.JSONEncoder):
28 class BytesEncoder(json.JSONEncoder):
10 def default(self, obj):
29 def default(self, obj):
@@ -1,8 +1,27 b''
1 """Read and write notebooks as regular .py files."""
1 """Read and write notebooks as regular .py files.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
2
18
3 from .rwbase import NotebookReader, NotebookWriter
19 from .rwbase import NotebookReader, NotebookWriter
4 from .nbbase import new_code_cell, new_text_cell, new_worksheet, new_notebook
20 from .nbbase import new_code_cell, new_text_cell, new_worksheet, new_notebook
5
21
22 #-----------------------------------------------------------------------------
23 # Code
24 #-----------------------------------------------------------------------------
6
25
7 class PyReaderError(Exception):
26 class PyReaderError(Exception):
8 pass
27 pass
@@ -1,4 +1,20 b''
1 """Read and write notebook files as XML."""
1 """Read and write notebook files as XML.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
2
18
3 from base64 import encodestring, decodestring
19 from base64 import encodestring, decodestring
4 from xml.etree import ElementTree as ET
20 from xml.etree import ElementTree as ET
@@ -8,6 +24,10 b' from .nbbase import ('
8 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output
24 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output
9 )
25 )
10
26
27 #-----------------------------------------------------------------------------
28 # Code
29 #-----------------------------------------------------------------------------
30
11 def indent(elem, level=0):
31 def indent(elem, level=0):
12 i = "\n" + level*" "
32 i = "\n" + level*" "
13 if len(elem):
33 if len(elem):
@@ -1,6 +1,28 b''
1 """Base classes and utilities for readers and writers.
2
3 Authors:
4
5 * Brian Granger
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
1 from base64 import encodestring, decodestring
19 from base64 import encodestring, decodestring
2 import pprint
20 import pprint
3
21
22 #-----------------------------------------------------------------------------
23 # Code
24 #-----------------------------------------------------------------------------
25
4 def base64_decode(nb):
26 def base64_decode(nb):
5 """Base64 encode all bytes objects in the notebook."""
27 """Base64 encode all bytes objects in the notebook."""
6 for ws in nb.worksheets:
28 for ws in nb.worksheets:
@@ -26,6 +48,7 b' def base64_encode(nb):'
26
48
27
49
28 class NotebookReader(object):
50 class NotebookReader(object):
51 """A class for reading notebooks."""
29
52
30 def reads(self, s, **kwargs):
53 def reads(self, s, **kwargs):
31 """Read a notebook from a string."""
54 """Read a notebook from a string."""
@@ -37,6 +60,7 b' class NotebookReader(object):'
37
60
38
61
39 class NotebookWriter(object):
62 class NotebookWriter(object):
63 """A class for writing notebooks."""
40
64
41 def writes(self, nb, **kwargs):
65 def writes(self, nb, **kwargs):
42 """Write a notebook to a string."""
66 """Write a notebook to a string."""
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now