##// END OF EJS Templates
fix b64-handling of data in Python 3
MinRK -
Show More
@@ -13,7 +13,9 b" notebook file. The extracted figures are returned in the 'resources' dictionary"
13 # Imports
13 # Imports
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15
15
16 import base64
16 import sys
17 import sys
18
17 from IPython.utils.traitlets import Unicode
19 from IPython.utils.traitlets import Unicode
18 from .base import Transformer
20 from .base import Transformer
19 from IPython.utils import py3compat
21 from IPython.utils import py3compat
@@ -65,15 +67,10 b' class ExtractFigureTransformer(Transformer):'
65
67
66 #Binary files are base64-encoded, SVG is already XML
68 #Binary files are base64-encoded, SVG is already XML
67 if out_type in ('png', 'jpg', 'jpeg', 'pdf'):
69 if out_type in ('png', 'jpg', 'jpeg', 'pdf'):
68
70 # data is b64-encoded as text (str, unicode)
69 #Python3 base64 is in a separate library...
71 # decodestring only accepts bytes
70 if py3compat.PY3:
72 data = py3compat.cast_bytes(data)
71
73 data = base64.decodestring(data)
72 #Base 64 decode the bytes
73 import base64
74 data = base64.b64decode(data)
75 else:
76 data = data.decode('base64')
77 elif sys.platform == 'win32':
74 elif sys.platform == 'win32':
78 data = data.replace('\n', '\r\n').encode("UTF-8")
75 data = data.replace('\n', '\r\n').encode("UTF-8")
79 else:
76 else:
General Comments 0
You need to be logged in to leave comments. Login now