Show More
@@ -19,7 +19,9 b' Authors:' | |||
|
19 | 19 | from base64 import encodestring, decodestring |
|
20 | 20 | import pprint |
|
21 | 21 | |
|
22 |
from IPython.utils |
|
|
22 | from IPython.utils import py3compat | |
|
23 | ||
|
24 | str_to_bytes = py3compat.str_to_bytes | |
|
23 | 25 | |
|
24 | 26 | #----------------------------------------------------------------------------- |
|
25 | 27 | # Code |
@@ -147,7 +149,10 b' class NotebookReader(object):' | |||
|
147 | 149 | |
|
148 | 150 | def read(self, fp, **kwargs): |
|
149 | 151 | """Read a notebook from a file like object""" |
|
150 | return self.read(fp.read(), **kwargs) | |
|
152 | nbs = fp.read() | |
|
153 | if not py3compat.PY3 and not isinstance(nbs, unicode): | |
|
154 | nbs = py3compat.str_to_unicode(nbs) | |
|
155 | return self.reads(nbs, **kwargs) | |
|
151 | 156 | |
|
152 | 157 | |
|
153 | 158 | class NotebookWriter(object): |
@@ -159,7 +164,11 b' class NotebookWriter(object):' | |||
|
159 | 164 | |
|
160 | 165 | def write(self, nb, fp, **kwargs): |
|
161 | 166 | """Write a notebook to a file like object""" |
|
162 |
|
|
|
167 | nbs = self.writes(nb,**kwargs) | |
|
168 | if not py3compat.PY3 and not isinstance(nbs, unicode): | |
|
169 | # this branch is likely only taken for JSON on Python 2 | |
|
170 | nbs = py3compat.str_to_unicode(nbs) | |
|
171 | return fp.write(nbs) | |
|
163 | 172 | |
|
164 | 173 | |
|
165 | 174 |
@@ -1,3 +1,5 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
1 | 3 | import os |
|
2 | 4 | from base64 import encodestring |
|
3 | 5 | |
@@ -49,7 +51,7 b' ws.cells.append(new_code_cell(' | |||
|
49 | 51 | )) |
|
50 | 52 | |
|
51 | 53 | ws.cells.append(new_code_cell( |
|
52 |
input='print |
|
|
54 | input=u'print "ünîcødé"', | |
|
53 | 55 | prompt_number=3, |
|
54 | 56 | collapsed=False, |
|
55 | 57 | outputs=[new_output( |
@@ -91,7 +93,7 b' nb0 = new_notebook(' | |||
|
91 | 93 | metadata=md |
|
92 | 94 | ) |
|
93 | 95 | |
|
94 | nb0_py = """# -*- coding: utf-8 -*- | |
|
96 | nb0_py = u"""# -*- coding: utf-8 -*- | |
|
95 | 97 | # <nbformat>%i</nbformat> |
|
96 | 98 | |
|
97 | 99 | # <htmlcell> |
@@ -120,7 +122,7 b' a = numpy.random.rand(100)' | |||
|
120 | 122 | |
|
121 | 123 | # <codecell> |
|
122 | 124 | |
|
123 | print a | |
|
125 | print "ünîcødé" | |
|
124 | 126 | |
|
125 | 127 | """ % nbformat |
|
126 | 128 |
General Comments 0
You need to be logged in to leave comments.
Login now