Show More
@@ -55,13 +55,18 b' def parse_json(s, **kwargs):' | |||||
55 |
|
55 | |||
56 | def parse_py(s, **kwargs): |
|
56 | def parse_py(s, **kwargs): | |
57 | """Parse a string into a (nbformat, string) tuple.""" |
|
57 | """Parse a string into a (nbformat, string) tuple.""" | |
58 | pattern = r'# <nbformat>(?P<nbformat>\d+)</nbformat>' |
|
58 | nbf = current_nbformat | |
|
59 | nbm = current_nbformat_minor | |||
|
60 | ||||
|
61 | pattern = r'# <nbformat>(?P<nbformat>\d+[\.\d+]*)</nbformat>' | |||
59 | m = re.search(pattern,s) |
|
62 | m = re.search(pattern,s) | |
60 | if m is not None: |
|
63 | if m is not None: | |
61 |
|
|
64 | digits = m.group('nbformat').split('.') | |
62 | else: |
|
65 | nbf = int(digits[0]) | |
63 | nbf = current_nbformat |
|
66 | if len(digits) > 1: | |
64 | return nbf, s |
|
67 | nbm = int(digits[1]) | |
|
68 | ||||
|
69 | return nbf, nbm, s | |||
65 |
|
70 | |||
66 |
|
71 | |||
67 | def reads_json(s, **kwargs): |
|
72 | def reads_json(s, **kwargs): | |
@@ -87,8 +92,7 b' def writes_json(nb, **kwargs):' | |||||
87 |
|
92 | |||
88 | def reads_py(s, **kwargs): |
|
93 | def reads_py(s, **kwargs): | |
89 | """Read a .py notebook from a string and return the NotebookNode object.""" |
|
94 | """Read a .py notebook from a string and return the NotebookNode object.""" | |
90 | nbf, s = parse_py(s, **kwargs) |
|
95 | nbf, nbm, s = parse_py(s, **kwargs) | |
91 | nbf = nbf |
|
|||
92 | if nbf == 2: |
|
96 | if nbf == 2: | |
93 | nb = v2.to_notebook_py(s, **kwargs) |
|
97 | nb = v2.to_notebook_py(s, **kwargs) | |
94 | elif nbf == 3: |
|
98 | elif nbf == 3: |
@@ -20,7 +20,7 b' import re' | |||||
20 | from .rwbase import NotebookReader, NotebookWriter |
|
20 | from .rwbase import NotebookReader, NotebookWriter | |
21 | from .nbbase import ( |
|
21 | from .nbbase import ( | |
22 | new_code_cell, new_text_cell, new_worksheet, |
|
22 | new_code_cell, new_text_cell, new_worksheet, | |
23 | new_notebook, new_heading_cell, nbformat |
|
23 | new_notebook, new_heading_cell, nbformat, nbformat_minor, | |
24 | ) |
|
24 | ) | |
25 |
|
25 | |||
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
@@ -152,7 +152,10 b' class PyWriter(NotebookWriter):' | |||||
152 |
|
152 | |||
153 | def writes(self, nb, **kwargs): |
|
153 | def writes(self, nb, **kwargs): | |
154 | lines = [u'# -*- coding: utf-8 -*-'] |
|
154 | lines = [u'# -*- coding: utf-8 -*-'] | |
155 | lines.extend([u'# <nbformat>%i</nbformat>' % nbformat,'']) |
|
155 | lines.extend([ | |
|
156 | u'# <nbformat>%i.%i</nbformat>' % (nbformat, nbformat_minor), | |||
|
157 | u'', | |||
|
158 | ]) | |||
156 | for ws in nb.worksheets: |
|
159 | for ws in nb.worksheets: | |
157 | for cell in ws.cells: |
|
160 | for cell in ws.cells: | |
158 | if cell.cell_type == u'code': |
|
161 | if cell.cell_type == u'code': |
@@ -6,7 +6,7 b' from base64 import encodestring' | |||||
6 | from ..nbbase import ( |
|
6 | from ..nbbase import ( | |
7 | NotebookNode, |
|
7 | NotebookNode, | |
8 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, |
|
8 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, | |
9 | new_metadata, new_author, new_heading_cell, nbformat |
|
9 | new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor | |
10 | ) |
|
10 | ) | |
11 |
|
11 | |||
12 | # some random base64-encoded *bytes* |
|
12 | # some random base64-encoded *bytes* | |
@@ -108,7 +108,7 b' nb0 = new_notebook(' | |||||
108 | ) |
|
108 | ) | |
109 |
|
109 | |||
110 | nb0_py = u"""# -*- coding: utf-8 -*- |
|
110 | nb0_py = u"""# -*- coding: utf-8 -*- | |
111 | # <nbformat>%i</nbformat> |
|
111 | # <nbformat>%i.%i</nbformat> | |
112 |
|
112 | |||
113 | # <htmlcell> |
|
113 | # <htmlcell> | |
114 |
|
114 | |||
@@ -148,6 +148,6 b' b = 5' | |||||
148 |
|
148 | |||
149 | print "ünîcødé" |
|
149 | print "ünîcødé" | |
150 |
|
150 | |||
151 | """ % nbformat |
|
151 | """ % (nbformat, nbformat_minor) | |
152 |
|
152 | |||
153 |
|
153 |
General Comments 0
You need to be logged in to leave comments.
Login now