Show More
|
1 | 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 | 43 | from .config.loader import Config |
|
44 | 44 | from .core import release |
|
45 | 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 | 46 | from .frontend.terminal.embed import embed |
|
55 | 47 | from .core.error import TryNext |
|
56 | 48 | from .core.interactiveshell import InteractiveShell |
@@ -48,8 +48,7 b' from IPython.core.error import UsageError' | |||
|
48 | 48 | from IPython.core.fakemodule import FakeModule |
|
49 | 49 | from IPython.core.profiledir import ProfileDir |
|
50 | 50 | from IPython.core.macro import Macro |
|
51 | from IPython.core import magic_arguments | |
|
52 | from IPython.core import page | |
|
51 | from IPython.core import magic_arguments, page | |
|
53 | 52 | from IPython.core.prefilter import ESC_MAGIC |
|
54 | 53 | from IPython.lib.pylabtools import mpl_runner |
|
55 | 54 | from IPython.testing.skipdoctest import skip_doctest |
@@ -195,11 +195,12 b' class ProfileCreate(BaseIPythonApplication):' | |||
|
195 | 195 | apps.append(IPythonQtConsoleApp) |
|
196 | 196 | try: |
|
197 | 197 | from IPython.frontend.html.notebook.notebookapp import IPythonNotebookApp |
|
198 |
except |
|
|
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. | |
|
198 | except ImportError: | |
|
202 | 199 | pass |
|
200 | except Exception: | |
|
201 | self.log.debug('Unexpected error when importing IPythonNotebookApp', | |
|
202 | exc_info=True | |
|
203 | ) | |
|
203 | 204 | else: |
|
204 | 205 | apps.append(IPythonNotebookApp) |
|
205 | 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 | 19 | from tornado import web |
|
9 | 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 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
7 |
# the file COPYING |
|
|
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 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
7 |
# the file COPYING |
|
|
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 | 199 | argv = sys.argv[1:] |
|
195 | 200 | |
|
196 | 201 | self.kernel_argv = list(argv) # copy |
|
197 |
# |
|
|
202 | # Kernel should inherit default config file from frontend | |
|
198 | 203 | self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name) |
|
199 |
# |
|
|
204 | # Scrub frontend-specific flags | |
|
200 | 205 | for a in argv: |
|
201 | 206 | if a.startswith('-') and a.lstrip('-') in notebook_flags: |
|
202 | 207 | self.kernel_argv.remove(a) |
@@ -205,7 +210,6 b' class IPythonNotebookApp(BaseIPythonApplication):' | |||
|
205 | 210 | alias = a.lstrip('-').split('=')[0] |
|
206 | 211 | if alias in notebook_aliases: |
|
207 | 212 | self.kernel_argv.remove(a) |
|
208 | print self.kernel_argv | |
|
209 | 213 | |
|
210 | 214 | def init_configurables(self): |
|
211 | 215 | # Don't let Qt or ZMQ swallow KeyboardInterupts. |
@@ -241,18 +245,20 b' class IPythonNotebookApp(BaseIPythonApplication):' | |||
|
241 | 245 | self.log.critical('WARNING: the notebook server is listening on all IP addresses ' |
|
242 | 246 | 'but not using any encryption or authentication. This is highly ' |
|
243 | 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 | 253 | try: |
|
246 | port = self.port + i | |
|
247 | 254 | self.http_server.listen(port, self.ip) |
|
248 | 255 | except socket.error, e: |
|
249 | 256 | if e.errno != errno.EADDRINUSE: |
|
250 | 257 | raise |
|
251 |
self.log.info('The port %i is already in use, trying |
|
|
258 | self.log.info('The port %i is already in use, trying another random port.' % port) | |
|
252 | 259 | else: |
|
253 | 260 | self.port = port |
|
254 | 261 | break |
|
255 | ||
|
256 | 262 | |
|
257 | 263 | def start(self): |
|
258 | 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 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
5 |
# the file COPYING |
|
|
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 | 53 | dict(notebook_id=notebook,name=name) |
|
47 | 54 | """ |
|
48 | 55 | names = os.listdir(self.notebook_dir) |
|
49 |
names = [name.split(u'.')[0] |
|
|
56 | names = [name.split(u'.')[0] | |
|
50 | 57 | for name in names if name.endswith(self.filename_ext)] |
|
51 | 58 | data = [] |
|
52 | 59 | for name in names: |
@@ -76,9 +83,7 b' class NotebookManager(LoggingConfigurable):' | |||
|
76 | 83 | if notebook_id not in self.mapping: |
|
77 | 84 | return False |
|
78 | 85 | path = self.get_path_by_name(self.mapping[notebook_id]) |
|
79 |
|
|
|
80 | return False | |
|
81 | return True | |
|
86 | return os.path.isfile(path) | |
|
82 | 87 | |
|
83 | 88 | def find_path(self, notebook_id): |
|
84 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 8 | var IPython = IPython || {}; |
|
2 | 9 | |
|
3 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 9 | // Utilities |
@@ -3,7 +3,6 b'' | |||
|
3 | 3 | from unittest import TestCase |
|
4 | 4 | |
|
5 | 5 | from IPython.frontend.html.notebook.kernelmanager import KernelManager |
|
6 | from IPython.frontend.html.notebook.sessionmanager import SessionManagerRunningError | |
|
7 | 6 | |
|
8 | 7 | class TestKernelManager(TestCase): |
|
9 | 8 | |
@@ -24,16 +23,4 b' class TestKernelManager(TestCase):' | |||
|
24 | 23 | self.assert_('hb_port' in port_dict) |
|
25 | 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 | 20 | import logging |
|
6 | 21 | |
|
22 | from tornado import web | |
|
23 | ||
|
24 | #----------------------------------------------------------------------------- | |
|
25 | # Code | |
|
26 | #----------------------------------------------------------------------------- | |
|
7 | 27 | |
|
8 | 28 | class ZMQHandler(web.RequestHandler): |
|
9 | 29 | |
@@ -74,7 +94,3 b' class ZMQXReqHandler(ZMQHandler):' | |||
|
74 | 94 | stream.send_json(msg) |
|
75 | 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 | 19 | import json |
|
2 | 20 | from xml.etree import ElementTree as ET |
|
3 | 21 | import re |
@@ -11,6 +29,9 b' from IPython.nbformat.v2 import (' | |||
|
11 | 29 | parse_filename |
|
12 | 30 | ) |
|
13 | 31 | |
|
32 | #----------------------------------------------------------------------------- | |
|
33 | # Code | |
|
34 | #----------------------------------------------------------------------------- | |
|
14 | 35 | |
|
15 | 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 | 14 | from .nbbase import ( |
|
3 | 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 | 14 | def convert_to_this_nbformat(nb, orig_version=None): |
|
4 | 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 | 19 | import pprint |
|
4 | 20 | import uuid |
|
5 | 21 | |
|
6 | 22 | from IPython.utils.ipstruct import Struct |
|
7 | 23 | |
|
24 | #----------------------------------------------------------------------------- | |
|
25 | # Code | |
|
26 | #----------------------------------------------------------------------------- | |
|
8 | 27 | |
|
9 | 28 | class NotebookNode(Struct): |
|
10 | 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 | 19 | from base64 import encodestring |
|
4 | 20 | from .rwbase import NotebookReader, NotebookWriter |
|
5 | 21 | from .nbbase import from_dict |
|
6 | 22 | import json |
|
7 | 23 | |
|
24 | #----------------------------------------------------------------------------- | |
|
25 | # Code | |
|
26 | #----------------------------------------------------------------------------- | |
|
8 | 27 | |
|
9 | 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 | 19 | from base64 import encodestring, decodestring |
|
2 | 20 | |
|
21 | #----------------------------------------------------------------------------- | |
|
22 | # Code | |
|
23 | #----------------------------------------------------------------------------- | |
|
3 | 24 | |
|
4 | 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 | 19 | from .nbbase import ( |
|
3 | 20 | NotebookNode, |
@@ -18,6 +35,9 b' from .nbpy import to_notebook as to_notebook_py' | |||
|
18 | 35 | |
|
19 | 36 | from .convert import convert_to_this_nbformat |
|
20 | 37 | |
|
38 | #----------------------------------------------------------------------------- | |
|
39 | # Code | |
|
40 | #----------------------------------------------------------------------------- | |
|
21 | 41 | |
|
22 | 42 | def parse_filename(fname): |
|
23 | 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 | 19 | from .nbbase import ( |
|
2 | 20 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output |
|
3 | 21 | ) |
|
4 | 22 | |
|
23 | #----------------------------------------------------------------------------- | |
|
24 | # Code | |
|
25 | #----------------------------------------------------------------------------- | |
|
26 | ||
|
5 | 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 | 37 | if orig_version == 1: |
|
7 | 38 | newnb = new_notebook() |
|
8 | 39 | ws = new_worksheet() |
@@ -17,4 +48,3 b' def convert_to_this_nbformat(nb, orig_version=1):' | |||
|
17 | 48 | else: |
|
18 | 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 | 24 | import pprint |
|
4 | 25 | import uuid |
|
5 | 26 | |
|
6 | 27 | from IPython.utils.ipstruct import Struct |
|
7 | 28 | |
|
29 | #----------------------------------------------------------------------------- | |
|
30 | # Code | |
|
31 | #----------------------------------------------------------------------------- | |
|
8 | 32 | |
|
9 | 33 | class NotebookNode(Struct): |
|
10 | 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 | 19 | from base64 import encodestring |
|
4 | 20 | from .nbbase import from_dict |
|
5 | 21 | from .rwbase import NotebookReader, NotebookWriter, base64_decode |
|
6 | 22 | import json |
|
7 | 23 | |
|
24 | #----------------------------------------------------------------------------- | |
|
25 | # Code | |
|
26 | #----------------------------------------------------------------------------- | |
|
8 | 27 | |
|
9 | 28 | class BytesEncoder(json.JSONEncoder): |
|
10 | 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 | 19 | from .rwbase import NotebookReader, NotebookWriter |
|
4 | 20 | from .nbbase import new_code_cell, new_text_cell, new_worksheet, new_notebook |
|
5 | 21 | |
|
22 | #----------------------------------------------------------------------------- | |
|
23 | # Code | |
|
24 | #----------------------------------------------------------------------------- | |
|
6 | 25 | |
|
7 | 26 | class PyReaderError(Exception): |
|
8 | 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 | 19 | from base64 import encodestring, decodestring |
|
4 | 20 | from xml.etree import ElementTree as ET |
@@ -8,6 +24,10 b' from .nbbase import (' | |||
|
8 | 24 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output |
|
9 | 25 | ) |
|
10 | 26 | |
|
27 | #----------------------------------------------------------------------------- | |
|
28 | # Code | |
|
29 | #----------------------------------------------------------------------------- | |
|
30 | ||
|
11 | 31 | def indent(elem, level=0): |
|
12 | 32 | i = "\n" + level*" " |
|
13 | 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 | 19 | from base64 import encodestring, decodestring |
|
2 | 20 | import pprint |
|
3 | 21 | |
|
22 | #----------------------------------------------------------------------------- | |
|
23 | # Code | |
|
24 | #----------------------------------------------------------------------------- | |
|
25 | ||
|
4 | 26 | def base64_decode(nb): |
|
5 | 27 | """Base64 encode all bytes objects in the notebook.""" |
|
6 | 28 | for ws in nb.worksheets: |
@@ -26,6 +48,7 b' def base64_encode(nb):' | |||
|
26 | 48 | |
|
27 | 49 | |
|
28 | 50 | class NotebookReader(object): |
|
51 | """A class for reading notebooks.""" | |
|
29 | 52 | |
|
30 | 53 | def reads(self, s, **kwargs): |
|
31 | 54 | """Read a notebook from a string.""" |
@@ -37,6 +60,7 b' class NotebookReader(object):' | |||
|
37 | 60 | |
|
38 | 61 | |
|
39 | 62 | class NotebookWriter(object): |
|
63 | """A class for writing notebooks.""" | |
|
40 | 64 | |
|
41 | 65 | def writes(self, nb, **kwargs): |
|
42 | 66 | """Write a notebook to a string.""" |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now