Show More
@@ -1,79 +1,80 b'' | |||
|
1 | 1 | """The main API for the v2 notebook format. |
|
2 | 2 | |
|
3 | 3 | Authors: |
|
4 | 4 | |
|
5 | 5 | * Brian Granger |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | # Copyright (C) 2008-2011 The IPython Development Team |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 12 | # the file COPYING, distributed as part of this software. |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | # Imports |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | import os |
|
20 | 20 | |
|
21 | 21 | from .nbbase import ( |
|
22 | 22 | NotebookNode, |
|
23 | 23 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, |
|
24 | 24 | new_metadata, new_author |
|
25 | 25 | ) |
|
26 | 26 | |
|
27 | 27 | from .nbjson import reads as reads_json, writes as writes_json |
|
28 | 28 | from .nbjson import reads as read_json, writes as write_json |
|
29 | 29 | from .nbjson import to_notebook as to_notebook_json |
|
30 | 30 | |
|
31 | 31 | from .nbxml import reads as reads_xml |
|
32 | 32 | from .nbxml import reads as read_xml |
|
33 | 33 | from .nbxml import to_notebook as to_notebook_xml |
|
34 | 34 | |
|
35 | 35 | from .nbpy import reads as reads_py, writes as writes_py |
|
36 | 36 | from .nbpy import reads as read_py, writes as write_py |
|
37 | 37 | from .nbpy import to_notebook as to_notebook_py |
|
38 | 38 | |
|
39 | 39 | from .convert import downgrade, upgrade |
|
40 | 40 | |
|
41 | 41 | #----------------------------------------------------------------------------- |
|
42 | 42 | # Code |
|
43 | 43 | #----------------------------------------------------------------------------- |
|
44 | 44 | |
|
45 | 45 | def parse_filename(fname): |
|
46 | 46 | """Parse a notebook filename. |
|
47 | 47 | |
|
48 | 48 | This function takes a notebook filename and returns the notebook |
|
49 | 49 | format (json/py) and the notebook name. This logic can be |
|
50 | 50 | summarized as follows: |
|
51 | 51 | |
|
52 | 52 | * notebook.ipynb -> (notebook.ipynb, notebook, json) |
|
53 | 53 | * notebook.json -> (notebook.json, notebook, json) |
|
54 | 54 | * notebook.py -> (notebook.py, notebook, py) |
|
55 | 55 | * notebook -> (notebook.ipynb, notebook, json) |
|
56 | 56 | |
|
57 | 57 | Parameters |
|
58 | 58 | ---------- |
|
59 | 59 | fname : unicode |
|
60 | 60 | The notebook filename. The filename can use a specific filename |
|
61 | 61 | extention (.ipynb, .json, .py) or none, in which case .ipynb will |
|
62 | 62 | be assumed. |
|
63 | 63 | |
|
64 | 64 | Returns |
|
65 | 65 | ------- |
|
66 | 66 | (fname, name, format) : (unicode, unicode, unicode) |
|
67 | 67 | The filename, notebook name and format. |
|
68 | 68 | """ |
|
69 | 69 | basename, ext = os.path.splitext(fname) |
|
70 | 70 | if ext == u'.ipynb': |
|
71 | 71 | format = u'json' |
|
72 | 72 | elif ext == u'.json': |
|
73 | 73 | format = u'json' |
|
74 | 74 | elif ext == u'.py': |
|
75 | 75 | format = u'py' |
|
76 | 76 | else: |
|
77 | basename = fname | |
|
77 | 78 | fname = fname + u'.ipynb' |
|
78 | 79 | format = u'json' |
|
79 | 80 | return fname, basename, format |
@@ -1,76 +1,77 b'' | |||
|
1 | 1 | """The main API for the v3 notebook format. |
|
2 | 2 | |
|
3 | 3 | Authors: |
|
4 | 4 | |
|
5 | 5 | * Brian Granger |
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | #----------------------------------------------------------------------------- |
|
9 | 9 | # Copyright (C) 2008-2011 The IPython Development Team |
|
10 | 10 | # |
|
11 | 11 | # Distributed under the terms of the BSD License. The full license is in |
|
12 | 12 | # the file COPYING, distributed as part of this software. |
|
13 | 13 | #----------------------------------------------------------------------------- |
|
14 | 14 | |
|
15 | 15 | #----------------------------------------------------------------------------- |
|
16 | 16 | # Imports |
|
17 | 17 | #----------------------------------------------------------------------------- |
|
18 | 18 | |
|
19 | 19 | import os |
|
20 | 20 | |
|
21 | 21 | from .nbbase import ( |
|
22 | 22 | NotebookNode, |
|
23 | 23 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, |
|
24 | 24 | new_metadata, new_author, new_heading_cell, nbformat, nbformat_minor, |
|
25 | 25 | nbformat_schema |
|
26 | 26 | ) |
|
27 | 27 | |
|
28 | 28 | from .nbjson import reads as reads_json, writes as writes_json |
|
29 | 29 | from .nbjson import reads as read_json, writes as write_json |
|
30 | 30 | from .nbjson import to_notebook as to_notebook_json |
|
31 | 31 | |
|
32 | 32 | from .nbpy import reads as reads_py, writes as writes_py |
|
33 | 33 | from .nbpy import reads as read_py, writes as write_py |
|
34 | 34 | from .nbpy import to_notebook as to_notebook_py |
|
35 | 35 | |
|
36 | 36 | from .convert import downgrade, upgrade |
|
37 | 37 | |
|
38 | 38 | #----------------------------------------------------------------------------- |
|
39 | 39 | # Code |
|
40 | 40 | #----------------------------------------------------------------------------- |
|
41 | 41 | |
|
42 | 42 | def parse_filename(fname): |
|
43 | 43 | """Parse a notebook filename. |
|
44 | 44 | |
|
45 | 45 | This function takes a notebook filename and returns the notebook |
|
46 | 46 | format (json/py) and the notebook name. This logic can be |
|
47 | 47 | summarized as follows: |
|
48 | 48 | |
|
49 | 49 | * notebook.ipynb -> (notebook.ipynb, notebook, json) |
|
50 | 50 | * notebook.json -> (notebook.json, notebook, json) |
|
51 | 51 | * notebook.py -> (notebook.py, notebook, py) |
|
52 | 52 | * notebook -> (notebook.ipynb, notebook, json) |
|
53 | 53 | |
|
54 | 54 | Parameters |
|
55 | 55 | ---------- |
|
56 | 56 | fname : unicode |
|
57 | 57 | The notebook filename. The filename can use a specific filename |
|
58 | 58 | extention (.ipynb, .json, .py) or none, in which case .ipynb will |
|
59 | 59 | be assumed. |
|
60 | 60 | |
|
61 | 61 | Returns |
|
62 | 62 | ------- |
|
63 | 63 | (fname, name, format) : (unicode, unicode, unicode) |
|
64 | 64 | The filename, notebook name and format. |
|
65 | 65 | """ |
|
66 | 66 | basename, ext = os.path.splitext(fname) |
|
67 | 67 | if ext == u'.ipynb': |
|
68 | 68 | format = u'json' |
|
69 | 69 | elif ext == u'.json': |
|
70 | 70 | format = u'json' |
|
71 | 71 | elif ext == u'.py': |
|
72 | 72 | format = u'py' |
|
73 | 73 | else: |
|
74 | basename = fname | |
|
74 | 75 | fname = fname + u'.ipynb' |
|
75 | 76 | format = u'json' |
|
76 | 77 | return fname, basename, format |
General Comments 0
You need to be logged in to leave comments.
Login now