##// END OF EJS Templates
Backport PR #8132: Only split lines on text output...
Min RK -
Show More
@@ -1,262 +1,178
1 {
1 {
2 "cells": [
2 "cells": [
3 {
3 {
4 "cell_type": "markdown",
4 "cell_type": "markdown",
5 "metadata": {},
5 "metadata": {},
6 "source": [
6 "source": [
7 "# NumPy and Matplotlib examples"
7 "# NumPy and Matplotlib examples"
8 ]
8 ]
9 },
9 },
10 {
10 {
11 "cell_type": "markdown",
11 "cell_type": "markdown",
12 "metadata": {},
12 "metadata": {},
13 "source": [
13 "source": [
14 "First import NumPy and Matplotlib:"
14 "First import NumPy and Matplotlib:"
15 ]
15 ]
16 },
16 },
17 {
17 {
18 "cell_type": "code",
18 "cell_type": "code",
19 "execution_count": 1,
19 "execution_count": 1,
20 "metadata": {
20 "metadata": {
21 "collapsed": false
21 "collapsed": false
22 },
22 },
23 "outputs": [
23 "outputs": [
24 {
24 {
25 "name": "stdout",
25 "name": "stdout",
26 "output_type": "stream",
26 "output_type": "stream",
27 "text": [
27 "text": [
28 "\n",
28 "\n",
29 "Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].\n",
29 "Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].\n",
30 "For more information, type 'help(pylab)'.\n"
30 "For more information, type 'help(pylab)'.\n"
31 ]
31 ]
32 }
32 }
33 ],
33 ],
34 "source": [
34 "source": [
35 "%pylab inline"
35 "%pylab inline"
36 ]
36 ]
37 },
37 },
38 {
38 {
39 "cell_type": "code",
39 "cell_type": "code",
40 "execution_count": 2,
40 "execution_count": 2,
41 "metadata": {
41 "metadata": {
42 "collapsed": false
42 "collapsed": false
43 },
43 },
44 "outputs": [],
44 "outputs": [],
45 "source": [
45 "source": [
46 "import numpy as np"
46 "import numpy as np"
47 ]
47 ]
48 },
48 },
49 {
49 {
50 "cell_type": "markdown",
50 "cell_type": "markdown",
51 "metadata": {},
51 "metadata": {},
52 "source": [
52 "source": [
53 "Now we show some very basic examples of how they can be used."
53 "Now we show some very basic examples of how they can be used."
54 ]
54 ]
55 },
55 },
56 {
56 {
57 "cell_type": "code",
57 "cell_type": "code",
58 "execution_count": 6,
58 "execution_count": 6,
59 "metadata": {
59 "metadata": {
60 "collapsed": false
60 "collapsed": false
61 },
61 },
62 "outputs": [],
62 "outputs": [],
63 "source": [
63 "source": [
64 "a = np.random.uniform(size=(100,100))"
64 "a = np.random.uniform(size=(100,100))"
65 ]
65 ]
66 },
66 },
67 {
67 {
68 "cell_type": "code",
68 "cell_type": "code",
69 "execution_count": 7,
69 "execution_count": 7,
70 "metadata": {
70 "metadata": {
71 "collapsed": false
71 "collapsed": false
72 },
72 },
73 "outputs": [
73 "outputs": [
74 {
74 {
75 "data": {
75 "data": {
76 "text/plain": [
76 "text/plain": [
77 "(100, 100)"
77 "(100, 100)"
78 ]
78 ]
79 },
79 },
80 "execution_count": 7,
80 "execution_count": 7,
81 "metadata": {},
81 "metadata": {},
82 "output_type": "execute_result"
82 "output_type": "execute_result"
83 }
83 }
84 ],
84 ],
85 "source": [
85 "source": [
86 "a.shape"
86 "a.shape"
87 ]
87 ]
88 },
88 },
89 {
89 {
90 "cell_type": "code",
90 "cell_type": "code",
91 "execution_count": 8,
91 "execution_count": 8,
92 "metadata": {
92 "metadata": {
93 "collapsed": false
93 "collapsed": false
94 },
94 },
95 "outputs": [],
95 "outputs": [],
96 "source": [
96 "source": [
97 "evs = np.linalg.eigvals(a)"
97 "evs = np.linalg.eigvals(a)"
98 ]
98 ]
99 },
99 },
100 {
100 {
101 "cell_type": "code",
101 "cell_type": "code",
102 "execution_count": 10,
102 "execution_count": 10,
103 "metadata": {
103 "metadata": {
104 "collapsed": false
104 "collapsed": false
105 },
105 },
106 "outputs": [
106 "outputs": [
107 {
107 {
108 "data": {
108 "data": {
109 "text/plain": [
109 "text/plain": [
110 "(100,)"
110 "(100,)"
111 ]
111 ]
112 },
112 },
113 "execution_count": 10,
113 "execution_count": 10,
114 "metadata": {},
114 "metadata": {},
115 "output_type": "execute_result"
115 "output_type": "execute_result"
116 }
116 }
117 ],
117 ],
118 "source": [
118 "source": [
119 "evs.shape"
119 "evs.shape"
120 ]
120 ]
121 },
121 },
122 {
122 {
123 "cell_type": "markdown",
123 "cell_type": "markdown",
124 "metadata": {},
124 "metadata": {},
125 "source": [
125 "source": [
126 "Here is a cell that has both text and PNG output:"
126 "Here is a cell that has both text and PNG output:"
127 ]
127 ]
128 },
128 },
129 {
129 {
130 "cell_type": "code",
130 "cell_type": "code",
131 "execution_count": 14,
131 "execution_count": 14,
132 "metadata": {
132 "metadata": {
133 "collapsed": false
133 "collapsed": false
134 },
134 },
135 "outputs": [
135 "outputs": [
136 {
136 {
137 "data": {
137 "data": {
138 "text/plain": [
138 "text/plain": [
139 "(array([95, 4, 0, 0, 0, 0, 0, 0, 0, 1]),\n",
139 "(array([95, 4, 0, 0, 0, 0, 0, 0, 0, 1]),\n",
140 " array([ -2.93566063, 2.35937011, 7.65440086, 12.9494316 ,\n",
140 " array([ -2.93566063, 2.35937011, 7.65440086, 12.9494316 ,\n",
141 " 18.24446235, 23.53949309, 28.83452384, 34.12955458,\n",
141 " 18.24446235, 23.53949309, 28.83452384, 34.12955458,\n",
142 " 39.42458533, 44.71961607, 50.01464682]),\n",
142 " 39.42458533, 44.71961607, 50.01464682]),\n",
143 " <a list of 10 Patch objects>)"
143 " <a list of 10 Patch objects>)"
144 ]
144 ]
145 },
145 },
146 "execution_count": 14,
146 "execution_count": 14,
147 "metadata": {},
147 "metadata": {},
148 "output_type": "execute_result"
148 "output_type": "execute_result"
149 },
149 },
150 {
150 {
151 "data": {
151 "data": {
152 "image/png": [
152 "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXgAAAD9CAYAAAC2l2x5AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEhdJREFUeJzt3X1olfX/x/HXtVbT8CZDmsK6KmrubEu3U2xnZOpxLBnG\nOqsIE7RoE3QRZkT/yE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X29mrTpk2q\nq6vTypUr9dJLL7maP2tH8Hv37tWnn376p9vfxV2SAoGADh8+nL5/5MgRVVVVZWukrKmqqtKRI0fS\n97u7u1VTUzOGE7lTVVWlnp4eSVJPT8+4/F3/3tmzZ3X77bdr+fLlCoVCkry3D9L5P/gtXrxYsVjM\nE/O///772r59u6666iotXbpUb731lpYvX+6J2X81c+ZMSVJpaaluueUWvfbaa56Z/5prrlFJSYka\nGho0ceJELV26VLt373Y1f85P0fz+Vai6ulp79uxRf3+/otGo8vLyNHny5FyP9K9Mub4/EAgoEoko\nlUopEomM6xcpx3HU3Nysa6+9VmvWrElv98o+fPPNN/ruu+8kSd9++63eeOMNhUIhT8y/YcMGHT9+\nXF988YW2bdum2tpabd261ROzS9KZM2fSf8v7+uuvtWfPHtXX13tmfkkqLi5WLBbTuXPntHPnTtXV\n1bmb38mBV155xSkqKnImTJjgFBYWOvX19envPfroo87VV1/tlJaWOvv378/FOK5Eo1HH5/M5V199\ntbN58+axHudf3Xnnnc7MmTOdiy66yCkqKnIikYhz+vRp55ZbbnEuv/xyJxQKOclkcqzH/Fvvvvuu\nY1mWU1FR4VRWVjqVlZXOrl27PLMPXV1djt/vd+bMmeMsWrTIefbZZx3HcTwz/6+i0ajT0NDgOI53\nZv/888+diooKp6KiwqmtrXW2bNniOI535nccx/nss8+cQCDgVFRUOA8++KAzMDDgav6c/5usAIDc\n4F90AgBDEXgAMBSBBwBDEXgAMBSBBwBDEXgAMNT/AQKseNIf7mhWAAAAAElFTkSuQmCC\n",
153 "iVBORw0KGgoAAAANSUhEUgAAAXgAAAD9CAYAAAC2l2x5AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\n",
154 "AAALEgAACxIB0t1+/AAAEhdJREFUeJzt3X1olfX/x/HXtVbT8CZDmsK6KmrubEu3U2xnZOpxLBnG\n",
155 "OqsIE7RoE3QRZkT/yEAjcIh/LIs6i/BEGSU1CkxT0+pkFp1zMmsxZ5uUTIXoxm95lmdlef3+8Nep\n",
156 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Qiod7eXu3Zs0fh\n",
169 "cFi2bauvr09FRUXq6OjI9rwAgGFyFfiJEyfKcRx9//33SqVSOnPmjC655BLF43E1NzeroKBATU1N\n",
170 "isVi2Z4XADBMrgMfDod15ZVXasaMGZo7d64CgYASiYR8Pp8kyefzKR6PZ3VYAMDw5bt50Ndff62W\n",
171 "lhYdPnxY06ZN0x133KEdO3bIcZxhPX79+vXpr4PBoILBoJsxAMBY0WhU0Wh0RM9hOcOt8u/s3LlT\n",
172 "W7du1bZt2yRJ4XBYx44d09GjR9Xa2iq/36+DBw+qra1NnZ2dQxe0rGG/EIwmy7Ik5WKO8bG/ALzN\n",
173 "TTtdnaKZN2+ePvzwQ506dUo//vijdu3apUWLFikQCCgSiSiVSikSiaimpsbN0wMAssBV4KdMmaLW\n",
174 "1lbdeuutuvHGG1VRUaGFCxeqpaVF/f39Kikp0cmTJ7Vq1apszwsAGCZXp2hGtCCnaAAgYzk7RQMA\n",
175 "GP8IPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEI\n",
176 "PAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAY\n",
177 "isADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYisADgKEIPAAYynXgf/jhB919992a\n",
178 "NWuWysrKFIvFlEwmFQqFZNu2GhsbNTAwkM1ZAQAZcB34devWybZtdXV1qaurSz6fT+FwWLZtq6+v\n",
179 "T0VFRero6MjmrACADLgO/L59+7R27VpNmDBB+fn5mjp1quLxuJqbm1VQUKCmpibFYrFszgoAyICr\n",
180 "wJ84cUKDg4NqaWlRIBDQxo0blUqllEgk5PP5JEk+n0/xeDyrwwIAhi/fzYMGBwfV29urTZs2qa6u\n",
181 "TitXrtRLL70kx3GG9fj169envw4GgwoGg27GAABjRaNRRaPRET2H5Qy3yn9QWlqqnp4eSdKuXbv0\n",
182 "3HPP6aefflJra6v8fr8OH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zyhb775JttL\n",
208 "jLHoWA8wIl7/j5z5x5aX5/fy7G5lNfDff/+9JGn+/Pm64oortGjRIsVisWwuAcBAU6ZcKsuyRvXW\n",
209 "1rZxrHcz57Ia+EQiIZ/Pl75fVlamDz74IJtLADBQMvk/nb+cePRuP/00mLsdGieyeh38vn37tGXL\n",
210 "Fr344ouSpI6ODp08eVKPPPLIbwuO8pt+AMBUmeY6q+9kraqq0kMPPZS+393drfr6+iE/wxtyACA3\n",
211 "snqKZurUqZLOX0lz7Ngx7d27V4FAIJtLAACGKeufRfPoo49q5cqVOnv2rFavXq3p06dnewkAwDBk\n",
212 "/TLJBQsWqKenR0ePHtXq1aslSS+//LLKy8t1wQUX6KOPPhry84899piKi4tVVlamAwcOZHucrPHa\n",
213 "9f1NTU0qLCzU7Nmz09uSyaRCoZBs21ZjY6MGBgbGcMJ/dvz4cS1cuFDl5eUKBoN64YUXJHlnHwYH\n",
214 "BxUIBFRZWamamhq1t7dL8s78kvTLL7/I7/eroaFBkrdmv/LKKzVnzhz5/X5VV1dL8tb8P/zwg+6+\n",
215 "+27NmjVLZWVlisVirubPyTtZZ8+erVdffVXz588fsv2rr77Sk08+qTfffFPhcDj9gjAeee36/nvu\n",
216 "uUe7d+8esi0cDsu2bfX19amoqEgdHR1jNN2/u/DCC9Xe3q7u7m51dnaqtbVVyWTSM/swYcIEvf32\n",
217 "2/r444/1zjvvaMuWLerr6/PM/JK0efNmlZWVpS+M8NLslmUpGo3q0KFDisfjkrw1/7p162Tbtrq6\n",
218 "utTV1SWfz+dq/pwE3ufzadasWX/aHovFVF9fL9u2tWDBAjmOo2QymYuRMuLF6/vnzZunadOmDdkW\n",
219 "j8fV3NysgoICNTU1jet9mDFjhiorKyVJ06dPV3l5uRKJhKf24eKLL5YkDQwM6Oeff1ZBQYFn5j9x\n",
220 "4oRef/11rVixIn1hhFdm/9UfL+jw0vz79u3T2rVrNWHCBOXn52vq1Kmu5h/Tz6KJx+MqLS1N3y8p\n",
221 "KUm/2o4nplzf//v98Pl84/J3/VeOHj2q7u5uVVdXe2ofzp07p4qKChUWFuq+++6Tbduemf+BBx7Q\n",
222 "pk2blJf3WyK8Mrt0/gi+trZWjY2N2r59uyTvzH/ixAkNDg6qpaVFgUBAGzduVCqVcjV/1v7IetNN\n",
223 "N+nLL7/80/YNGzakz+H90V9dMsl18qPHi5eoJpNJLVmyRO3t7Zo0aZKn9iEvL0+ffPKJjh07psWL\n",
224 "F2vu3LmemH/Hjh267LLL5Pf7h7y93wuz/+q9997TzJkz1dPTo4aGBlVXV3tm/sHBQfX29mrTpk2q\n",
225 "q6vTypUr9dJLL7maP2tH8Hv37tWnn376p9vfxV2SAoGADh8+nL5/5MgRVVVVZWukrKmqqtKRI0fS\n",
226 "97u7u1VTUzOGE7lTVVWlnp4eSVJPT8+4/F3/3tmzZ3X77bdr+fLlCoVCkry3D9L5P/gtXrxYsVjM\n",
227 "E/O///772r59u6666iotXbpUb731lpYvX+6J2X81c+ZMSVJpaaluueUWvfbaa56Z/5prrlFJSYka\n",
228 "Gho0ceJELV26VLt373Y1f85P0fz+Vai6ulp79uxRf3+/otGo8vLyNHny5FyP9K9Mub4/EAgoEoko\n",
229 "lUopEomM6xcpx3HU3Nysa6+9VmvWrElv98o+fPPNN/ruu+8kSd9++63eeOMNhUIhT8y/YcMGHT9+\n",
230 "XF988YW2bdum2tpabd261ROzS9KZM2fSf8v7+uuvtWfPHtXX13tmfkkqLi5WLBbTuXPntHPnTtXV\n",
231 "1bmb38mBV155xSkqKnImTJjgFBYWOvX19envPfroo87VV1/tlJaWOvv378/FOK5Eo1HH5/M5V199\n",
232 "tbN58+axHudf3Xnnnc7MmTOdiy66yCkqKnIikYhz+vRp55ZbbnEuv/xyJxQKOclkcqzH/Fvvvvuu\n",
233 "Y1mWU1FR4VRWVjqVlZXOrl27PLMPXV1djt/vd+bMmeMsWrTIefbZZx3HcTwz/6+i0ajT0NDgOI53\n",
234 "Zv/888+diooKp6KiwqmtrXW2bNniOI535nccx/nss8+cQCDgVFRUOA8++KAzMDDgav6c/5usAIDc\n",
235 "4F90AgBDEXgAMBSBBwBDEXgAMBSBBwBDEXgAMNT/AQKseNIf7mhWAAAAAElFTkSuQmCC\n"
236 ],
237 "text/plain": [
153 "text/plain": [
238 "<matplotlib.figure.Figure at 0x108c8f1d0>"
154 "<matplotlib.figure.Figure at 0x108c8f1d0>"
239 ]
155 ]
240 },
156 },
241 "metadata": {},
157 "metadata": {},
242 "output_type": "display_data"
158 "output_type": "display_data"
243 }
159 }
244 ],
160 ],
245 "source": [
161 "source": [
246 "hist(evs.real)"
162 "hist(evs.real)"
247 ]
163 ]
248 },
164 },
249 {
165 {
250 "cell_type": "code",
166 "cell_type": "code",
251 "execution_count": null,
167 "execution_count": null,
252 "metadata": {
168 "metadata": {
253 "collapsed": false
169 "collapsed": false
254 },
170 },
255 "outputs": [],
171 "outputs": [],
256 "source": []
172 "source": []
257 }
173 }
258 ],
174 ],
259 "metadata": {},
175 "metadata": {},
260 "nbformat": 4,
176 "nbformat": 4,
261 "nbformat_minor": 0
177 "nbformat_minor": 0
262 } No newline at end of file
178 }
@@ -1,39 +1,39
1 """Tests for notebook.py"""
1 """Tests for notebook.py"""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import json
6 import json
7
7
8 from .base import ExportersTestsBase
8 from .base import ExportersTestsBase
9 from ..notebook import NotebookExporter
9 from ..notebook import NotebookExporter
10
10
11 from IPython.nbformat import validate
11 from IPython.nbformat import validate
12 from IPython.testing.tools import assert_big_text_equal
12 from IPython.testing.tools import assert_big_text_equal
13
13
14 class TestNotebookExporter(ExportersTestsBase):
14 class TestNotebookExporter(ExportersTestsBase):
15 """Contains test functions for notebook.py"""
15 """Contains test functions for notebook.py"""
16
16
17 exporter_class = NotebookExporter
17 exporter_class = NotebookExporter
18
18
19 def test_export(self):
19 def test_export(self):
20 """
20 """
21 Does the NotebookExporter return the file unchanged?
21 Does the NotebookExporter return the file unchanged?
22 """
22 """
23 with open(self._get_notebook()) as f:
23 with open(self._get_notebook()) as f:
24 file_contents = f.read()
24 file_contents = f.read()
25 (output, resources) = self.exporter_class().from_filename(self._get_notebook())
25 (output, resources) = self.exporter_class().from_filename(self._get_notebook())
26 assert len(output) > 0
26 assert len(output) > 0
27 assert_big_text_equal(output, file_contents)
27 assert_big_text_equal(output.strip(), file_contents.strip())
28
28
29 def test_downgrade_3(self):
29 def test_downgrade_3(self):
30 exporter = self.exporter_class(nbformat_version=3)
30 exporter = self.exporter_class(nbformat_version=3)
31 (output, resources) = exporter.from_filename(self._get_notebook())
31 (output, resources) = exporter.from_filename(self._get_notebook())
32 nb = json.loads(output)
32 nb = json.loads(output)
33 validate(nb)
33 validate(nb)
34
34
35 def test_downgrade_2(self):
35 def test_downgrade_2(self):
36 exporter = self.exporter_class(nbformat_version=2)
36 exporter = self.exporter_class(nbformat_version=2)
37 (output, resources) = exporter.from_filename(self._get_notebook())
37 (output, resources) = exporter.from_filename(self._get_notebook())
38 nb = json.loads(output)
38 nb = json.loads(output)
39 self.assertEqual(nb['nbformat'], 2)
39 self.assertEqual(nb['nbformat'], 2)
@@ -1,96 +1,102
1 """Base classes and utilities for readers and writers."""
1 """Base classes and utilities for readers and writers."""
2
2
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 from IPython.utils.py3compat import string_types, cast_unicode_py2
6 from IPython.utils.py3compat import string_types, cast_unicode_py2
7
7
8
8
9 def rejoin_lines(nb):
9 def rejoin_lines(nb):
10 """rejoin multiline text into strings
10 """rejoin multiline text into strings
11
11
12 For reversing effects of ``split_lines(nb)``.
12 For reversing effects of ``split_lines(nb)``.
13
13
14 This only rejoins lines that have been split, so if text objects were not split
14 This only rejoins lines that have been split, so if text objects were not split
15 they will pass through unchanged.
15 they will pass through unchanged.
16
16
17 Used when reading JSON files that may have been passed through split_lines.
17 Used when reading JSON files that may have been passed through split_lines.
18 """
18 """
19 for cell in nb.cells:
19 for cell in nb.cells:
20 if 'source' in cell and isinstance(cell.source, list):
20 if 'source' in cell and isinstance(cell.source, list):
21 cell.source = ''.join(cell.source)
21 cell.source = ''.join(cell.source)
22 if cell.get('cell_type', None) == 'code':
22 if cell.get('cell_type', None) == 'code':
23 for output in cell.get('outputs', []):
23 for output in cell.get('outputs', []):
24 output_type = output.get('output_type', '')
24 output_type = output.get('output_type', '')
25 if output_type in {'execute_result', 'display_data'}:
25 if output_type in {'execute_result', 'display_data'}:
26 for key, value in output.get('data', {}).items():
26 for key, value in output.get('data', {}).items():
27 if key != 'application/json' and isinstance(value, list):
27 if key != 'application/json' and isinstance(value, list):
28 output.data[key] = ''.join(value)
28 output.data[key] = ''.join(value)
29 elif output_type:
29 elif output_type:
30 if isinstance(output.get('text', ''), list):
30 if isinstance(output.get('text', ''), list):
31 output.text = ''.join(output.text)
31 output.text = ''.join(output.text)
32 return nb
32 return nb
33
33
34 _non_text_split_mimes = {
35 'application/javascript',
36 'image/svg+xml',
37 }
34
38
35 def split_lines(nb):
39 def split_lines(nb):
36 """split likely multiline text into lists of strings
40 """split likely multiline text into lists of strings
37
41
38 For file output more friendly to line-based VCS. ``rejoin_lines(nb)`` will
42 For file output more friendly to line-based VCS. ``rejoin_lines(nb)`` will
39 reverse the effects of ``split_lines(nb)``.
43 reverse the effects of ``split_lines(nb)``.
40
44
41 Used when writing JSON files.
45 Used when writing JSON files.
42 """
46 """
43 for cell in nb.cells:
47 for cell in nb.cells:
44 source = cell.get('source', None)
48 source = cell.get('source', None)
45 if isinstance(source, string_types):
49 if isinstance(source, string_types):
46 cell['source'] = source.splitlines(True)
50 cell['source'] = source.splitlines(True)
47
51
48 if cell.cell_type == 'code':
52 if cell.cell_type == 'code':
49 for output in cell.outputs:
53 for output in cell.outputs:
50 if output.output_type in {'execute_result', 'display_data'}:
54 if output.output_type in {'execute_result', 'display_data'}:
51 for key, value in output.data.items():
55 for key, value in output.data.items():
52 if key != 'application/json' and isinstance(value, string_types):
56 if isinstance(value, string_types) and (
57 key.startswith('text/') or key in _non_text_split_mimes
58 ):
53 output.data[key] = value.splitlines(True)
59 output.data[key] = value.splitlines(True)
54 elif output.output_type == 'stream':
60 elif output.output_type == 'stream':
55 if isinstance(output.text, string_types):
61 if isinstance(output.text, string_types):
56 output.text = output.text.splitlines(True)
62 output.text = output.text.splitlines(True)
57 return nb
63 return nb
58
64
59
65
60 def strip_transient(nb):
66 def strip_transient(nb):
61 """Strip transient values that shouldn't be stored in files.
67 """Strip transient values that shouldn't be stored in files.
62
68
63 This should be called in *both* read and write.
69 This should be called in *both* read and write.
64 """
70 """
65 nb.metadata.pop('orig_nbformat', None)
71 nb.metadata.pop('orig_nbformat', None)
66 nb.metadata.pop('orig_nbformat_minor', None)
72 nb.metadata.pop('orig_nbformat_minor', None)
67 nb.metadata.pop('signature', None)
73 nb.metadata.pop('signature', None)
68 for cell in nb.cells:
74 for cell in nb.cells:
69 cell.metadata.pop('trusted', None)
75 cell.metadata.pop('trusted', None)
70 return nb
76 return nb
71
77
72
78
73 class NotebookReader(object):
79 class NotebookReader(object):
74 """A class for reading notebooks."""
80 """A class for reading notebooks."""
75
81
76 def reads(self, s, **kwargs):
82 def reads(self, s, **kwargs):
77 """Read a notebook from a string."""
83 """Read a notebook from a string."""
78 raise NotImplementedError("loads must be implemented in a subclass")
84 raise NotImplementedError("loads must be implemented in a subclass")
79
85
80 def read(self, fp, **kwargs):
86 def read(self, fp, **kwargs):
81 """Read a notebook from a file like object"""
87 """Read a notebook from a file like object"""
82 nbs = cast_unicode_py2(fp.read())
88 nbs = cast_unicode_py2(fp.read())
83 return self.reads(nbs, **kwargs)
89 return self.reads(nbs, **kwargs)
84
90
85
91
86 class NotebookWriter(object):
92 class NotebookWriter(object):
87 """A class for writing notebooks."""
93 """A class for writing notebooks."""
88
94
89 def writes(self, nb, **kwargs):
95 def writes(self, nb, **kwargs):
90 """Write a notebook to a string."""
96 """Write a notebook to a string."""
91 raise NotImplementedError("loads must be implemented in a subclass")
97 raise NotImplementedError("loads must be implemented in a subclass")
92
98
93 def write(self, nb, fp, **kwargs):
99 def write(self, nb, fp, **kwargs):
94 """Write a notebook to a file like object"""
100 """Write a notebook to a file like object"""
95 nbs = cast_unicode_py2(self.writes(nb, **kwargs))
101 nbs = cast_unicode_py2(self.writes(nb, **kwargs))
96 return fp.write(nbs)
102 return fp.write(nbs)
General Comments 0
You need to be logged in to leave comments. Login now