##// END OF EJS Templates
scrub bytes when upgrading notebooks from v2...
MinRK -
Show More
@@ -1,22 +1,7 b''
1 """Code for converting notebooks to and from the v2 format.
1 """Code for converting notebooks to and from the v2 format."""
2
2
3 Authors:
3 # Copyright (c) IPython Development Team.
4
4 # Distributed under the terms of the Modified BSD License.
5 * Brian Granger
6 * Min RK
7 * Jonathan Frederic
8 """
9
10 #-----------------------------------------------------------------------------
11 # Copyright (C) 2008-2011 The IPython Development Team
12 #
13 # Distributed under the terms of the BSD License. The full license is in
14 # the file COPYING, distributed as part of this software.
15 #-----------------------------------------------------------------------------
16
17 #-----------------------------------------------------------------------------
18 # Imports
19 #-----------------------------------------------------------------------------
20
5
21 from .nbbase import (
6 from .nbbase import (
22 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output,
7 new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output,
@@ -25,9 +10,21 b' from .nbbase import ('
25
10
26 from IPython.nbformat import v2
11 from IPython.nbformat import v2
27
12
28 #-----------------------------------------------------------------------------
13 def _unbytes(obj):
29 # Code
14 """There should be no bytes objects in a notebook
30 #-----------------------------------------------------------------------------
15
16 v2 stores png/jpeg as b64 ascii bytes
17 """
18 if isinstance(obj, dict):
19 for k,v in obj.items():
20 obj[k] = _unbytes(v)
21 elif isinstance(obj, list):
22 for i,v in enumerate(obj):
23 obj[i] = _unbytes(v)
24 elif isinstance(obj, bytes):
25 # only valid bytes are b64-encoded ascii
26 obj = obj.decode('ascii')
27 return obj
31
28
32 def upgrade(nb, from_version=2, from_minor=0):
29 def upgrade(nb, from_version=2, from_minor=0):
33 """Convert a notebook to v3.
30 """Convert a notebook to v3.
@@ -47,6 +44,7 b' def upgrade(nb, from_version=2, from_minor=0):'
47 nb.nbformat_minor = nbformat_minor
44 nb.nbformat_minor = nbformat_minor
48
45
49 nb.orig_nbformat = 2
46 nb.orig_nbformat = 2
47 nb = _unbytes(nb)
50 return nb
48 return nb
51 elif from_version == 3:
49 elif from_version == 3:
52 if from_minor != nbformat_minor:
50 if from_minor != nbformat_minor:
General Comments 0
You need to be logged in to leave comments. Login now