Show More
@@ -25,6 +25,7 b' import pprint' | |||||
25 | import uuid |
|
25 | import uuid | |
26 |
|
26 | |||
27 | from IPython.utils.ipstruct import Struct |
|
27 | from IPython.utils.ipstruct import Struct | |
|
28 | from IPython.utils.py3compat import cast_unicode | |||
28 |
|
29 | |||
29 | #----------------------------------------------------------------------------- |
|
30 | #----------------------------------------------------------------------------- | |
30 | # Code |
|
31 | # Code | |
@@ -67,21 +68,21 b' def new_output(output_type=None, output_text=None, output_png=None,' | |||||
67 |
|
68 | |||
68 | if output_type != 'pyerr': |
|
69 | if output_type != 'pyerr': | |
69 | if output_text is not None: |
|
70 | if output_text is not None: | |
70 | output.text = unicode(output_text) |
|
71 | output.text = cast_unicode(output_text) | |
71 | if output_png is not None: |
|
72 | if output_png is not None: | |
72 | output.png = unicode(output_png) |
|
73 | output.png = cast_unicode(output_png) | |
73 | if output_jpeg is not None: |
|
74 | if output_jpeg is not None: | |
74 | output.jpeg = unicode(output_jpeg) |
|
75 | output.jpeg = cast_unicode(output_jpeg) | |
75 | if output_html is not None: |
|
76 | if output_html is not None: | |
76 | output.html = unicode(output_html) |
|
77 | output.html = cast_unicode(output_html) | |
77 | if output_svg is not None: |
|
78 | if output_svg is not None: | |
78 | output.svg = unicode(output_svg) |
|
79 | output.svg = cast_unicode(output_svg) | |
79 | if output_latex is not None: |
|
80 | if output_latex is not None: | |
80 | output.latex = unicode(output_latex) |
|
81 | output.latex = cast_unicode(output_latex) | |
81 | if output_json is not None: |
|
82 | if output_json is not None: | |
82 | output.json = unicode(output_json) |
|
83 | output.json = cast_unicode(output_json) | |
83 | if output_javascript is not None: |
|
84 | if output_javascript is not None: | |
84 | output.javascript = unicode(output_javascript) |
|
85 | output.javascript = cast_unicode(output_javascript) | |
85 |
|
86 | |||
86 | if output_type == u'pyout': |
|
87 | if output_type == u'pyout': | |
87 | if prompt_number is not None: |
|
88 | if prompt_number is not None: | |
@@ -89,14 +90,14 b' def new_output(output_type=None, output_text=None, output_png=None,' | |||||
89 |
|
90 | |||
90 | if output_type == u'pyerr': |
|
91 | if output_type == u'pyerr': | |
91 | if ename is not None: |
|
92 | if ename is not None: | |
92 | output.ename = unicode(ename) |
|
93 | output.ename = cast_unicode(ename) | |
93 | if evalue is not None: |
|
94 | if evalue is not None: | |
94 | output.evalue = unicode(evalue) |
|
95 | output.evalue = cast_unicode(evalue) | |
95 | if traceback is not None: |
|
96 | if traceback is not None: | |
96 | output.traceback = [unicode(frame) for frame in list(traceback)] |
|
97 | output.traceback = [cast_unicode(frame) for frame in list(traceback)] | |
97 |
|
98 | |||
98 | if output_type == u'stream': |
|
99 | if output_type == u'stream': | |
99 | output.stream = 'stdout' if stream is None else unicode(stream) |
|
100 | output.stream = 'stdout' if stream is None else cast_unicode(stream) | |
100 |
|
101 | |||
101 | return output |
|
102 | return output | |
102 |
|
103 | |||
@@ -107,9 +108,9 b' def new_code_cell(input=None, prompt_number=None, outputs=None,' | |||||
107 | cell = NotebookNode() |
|
108 | cell = NotebookNode() | |
108 | cell.cell_type = u'code' |
|
109 | cell.cell_type = u'code' | |
109 | if language is not None: |
|
110 | if language is not None: | |
110 | cell.language = unicode(language) |
|
111 | cell.language = cast_unicode(language) | |
111 | if input is not None: |
|
112 | if input is not None: | |
112 | cell.input = unicode(input) |
|
113 | cell.input = cast_unicode(input) | |
113 | if prompt_number is not None: |
|
114 | if prompt_number is not None: | |
114 | cell.prompt_number = int(prompt_number) |
|
115 | cell.prompt_number = int(prompt_number) | |
115 | if outputs is None: |
|
116 | if outputs is None: | |
@@ -130,9 +131,9 b' def new_text_cell(cell_type, source=None, rendered=None, metadata=None):' | |||||
130 | if cell_type == 'plaintext': |
|
131 | if cell_type == 'plaintext': | |
131 | cell_type = 'raw' |
|
132 | cell_type = 'raw' | |
132 | if source is not None: |
|
133 | if source is not None: | |
133 | cell.source = unicode(source) |
|
134 | cell.source = cast_unicode(source) | |
134 | if rendered is not None: |
|
135 | if rendered is not None: | |
135 | cell.rendered = unicode(rendered) |
|
136 | cell.rendered = cast_unicode(rendered) | |
136 | cell.metadata = NotebookNode(metadata or {}) |
|
137 | cell.metadata = NotebookNode(metadata or {}) | |
137 | cell.cell_type = cell_type |
|
138 | cell.cell_type = cell_type | |
138 | return cell |
|
139 | return cell | |
@@ -143,9 +144,9 b' def new_heading_cell(source=None, rendered=None, level=1, metadata=None):' | |||||
143 | cell = NotebookNode() |
|
144 | cell = NotebookNode() | |
144 | cell.cell_type = u'heading' |
|
145 | cell.cell_type = u'heading' | |
145 | if source is not None: |
|
146 | if source is not None: | |
146 | cell.source = unicode(source) |
|
147 | cell.source = cast_unicode(source) | |
147 | if rendered is not None: |
|
148 | if rendered is not None: | |
148 | cell.rendered = unicode(rendered) |
|
149 | cell.rendered = cast_unicode(rendered) | |
149 | cell.level = int(level) |
|
150 | cell.level = int(level) | |
150 | cell.metadata = NotebookNode(metadata or {}) |
|
151 | cell.metadata = NotebookNode(metadata or {}) | |
151 | return cell |
|
152 | return cell | |
@@ -155,7 +156,7 b' def new_worksheet(name=None, cells=None, metadata=None):' | |||||
155 | """Create a worksheet by name with with a list of cells.""" |
|
156 | """Create a worksheet by name with with a list of cells.""" | |
156 | ws = NotebookNode() |
|
157 | ws = NotebookNode() | |
157 | if name is not None: |
|
158 | if name is not None: | |
158 | ws.name = unicode(name) |
|
159 | ws.name = cast_unicode(name) | |
159 | if cells is None: |
|
160 | if cells is None: | |
160 | ws.cells = [] |
|
161 | ws.cells = [] | |
161 | else: |
|
162 | else: | |
@@ -178,7 +179,7 b' def new_notebook(name=None, metadata=None, worksheets=None):' | |||||
178 | else: |
|
179 | else: | |
179 | nb.metadata = NotebookNode(metadata) |
|
180 | nb.metadata = NotebookNode(metadata) | |
180 | if name is not None: |
|
181 | if name is not None: | |
181 | nb.metadata.name = unicode(name) |
|
182 | nb.metadata.name = cast_unicode(name) | |
182 | return nb |
|
183 | return nb | |
183 |
|
184 | |||
184 |
|
185 | |||
@@ -187,29 +188,29 b' def new_metadata(name=None, authors=None, license=None, created=None,' | |||||
187 | """Create a new metadata node.""" |
|
188 | """Create a new metadata node.""" | |
188 | metadata = NotebookNode() |
|
189 | metadata = NotebookNode() | |
189 | if name is not None: |
|
190 | if name is not None: | |
190 | metadata.name = unicode(name) |
|
191 | metadata.name = cast_unicode(name) | |
191 | if authors is not None: |
|
192 | if authors is not None: | |
192 | metadata.authors = list(authors) |
|
193 | metadata.authors = list(authors) | |
193 | if created is not None: |
|
194 | if created is not None: | |
194 | metadata.created = unicode(created) |
|
195 | metadata.created = cast_unicode(created) | |
195 | if modified is not None: |
|
196 | if modified is not None: | |
196 | metadata.modified = unicode(modified) |
|
197 | metadata.modified = cast_unicode(modified) | |
197 | if license is not None: |
|
198 | if license is not None: | |
198 | metadata.license = unicode(license) |
|
199 | metadata.license = cast_unicode(license) | |
199 | if gistid is not None: |
|
200 | if gistid is not None: | |
200 | metadata.gistid = unicode(gistid) |
|
201 | metadata.gistid = cast_unicode(gistid) | |
201 | return metadata |
|
202 | return metadata | |
202 |
|
203 | |||
203 | def new_author(name=None, email=None, affiliation=None, url=None): |
|
204 | def new_author(name=None, email=None, affiliation=None, url=None): | |
204 | """Create a new author.""" |
|
205 | """Create a new author.""" | |
205 | author = NotebookNode() |
|
206 | author = NotebookNode() | |
206 | if name is not None: |
|
207 | if name is not None: | |
207 | author.name = unicode(name) |
|
208 | author.name = cast_unicode(name) | |
208 | if email is not None: |
|
209 | if email is not None: | |
209 | author.email = unicode(email) |
|
210 | author.email = cast_unicode(email) | |
210 | if affiliation is not None: |
|
211 | if affiliation is not None: | |
211 | author.affiliation = unicode(affiliation) |
|
212 | author.affiliation = cast_unicode(affiliation) | |
212 | if url is not None: |
|
213 | if url is not None: | |
213 | author.url = unicode(url) |
|
214 | author.url = cast_unicode(url) | |
214 | return author |
|
215 | return author | |
215 |
|
216 |
@@ -190,7 +190,7 b' class PyWriter(NotebookWriter):' | |||||
190 | lines.extend([u'# ' + line for line in input.splitlines()]) |
|
190 | lines.extend([u'# ' + line for line in input.splitlines()]) | |
191 | lines.append(u'') |
|
191 | lines.append(u'') | |
192 | lines.append('') |
|
192 | lines.append('') | |
193 |
return u |
|
193 | return u'\n'.join(lines) | |
194 |
|
194 | |||
195 |
|
195 | |||
196 | _reader = PyReader() |
|
196 | _reader = PyReader() |
General Comments 0
You need to be logged in to leave comments.
Login now