Skip to content

Commit

Permalink
Merge pull request ipython#2 from minrk/nbconvert
Browse files Browse the repository at this point in the history
fix b64-handling of data in Python 3
  • Loading branch information
jdfreder committed Jul 19, 2013
2 parents 20482f3 + cdadccc commit 4aaef86
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions IPython/nbconvert/transformers/extractfigure.py
Expand Up @@ -13,7 +13,9 @@
# Imports
#-----------------------------------------------------------------------------

import base64
import sys

from IPython.utils.traitlets import Unicode
from .base import Transformer
from IPython.utils import py3compat
Expand Down Expand Up @@ -65,15 +67,10 @@ def transform_cell(self, cell, resources, cell_index):

#Binary files are base64-encoded, SVG is already XML
if out_type in ('png', 'jpg', 'jpeg', 'pdf'):

#Python3 base64 is in a separate library...
if py3compat.PY3:

#Base 64 decode the bytes
import base64
data = base64.b64decode(data)
else:
data = data.decode('base64')
# data is b64-encoded as text (str, unicode)
# decodestring only accepts bytes
data = py3compat.cast_bytes(data)
data = base64.decodestring(data)
elif sys.platform == 'win32':
data = data.replace('\n', '\r\n').encode("UTF-8")
else:
Expand Down

0 comments on commit 4aaef86

Please sign in to comment.