encode image_tag as utf8 in [x]html export #1165

Merged
merged 1 commit into from Dec 16, 2011

2 participants

@minrk
IPython member

Should only affect Python 2

Also removes redundant 'setDefaultButton' in Inline/External dialog, which caused strange display of the two buttons.

closes #1164

@minrk minrk encode image_tag as utf8 in [x]html export
Should only affect Python 2

also removes redundant 'setDefaultButton' in Inline/External dialog,
which caused strange display of the two buttons.
971ca49
@fperez fperez commented on the diff Dec 16, 2011
IPython/frontend/qt/rich_text.py
@@ -210,6 +216,20 @@ def default_image_tag(match, path = None, format = "png"):
return ''
+def ensure_utf8(image_tag):
+ """wrapper for ensuring image_tag returns utf8-encoded str on Python 2"""
+ if py3compat.PY3:
+ # nothing to do on Python 3
+ return image_tag
+
+ def utf8_image_tag(*args, **kwargs):
+ s = image_tag(*args, **kwargs)
+ if isinstance(s, unicode):
+ s = s.encode('utf8')
+ return s
+ return utf8_image_tag
@fperez
IPython member
fperez added a line comment Dec 16, 2011

Why are you returning the function here? I think it should instead read

return utf8_image_tag(image_tag)
@minrk
IPython member
minrk added a line comment Dec 16, 2011
@fperez
IPython member
fperez added a line comment Dec 16, 2011

Ah, got it. I didn't realize it was being used as a decorator, I mistakenly thought image_tag was a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fperez
IPython member

OK, code looks otherwise good. I checked previously failing situations now work correctly. Thanks!

Merging now.

@fperez fperez closed this Dec 16, 2011
@fperez fperez merged commit 376addf into ipython:master Dec 16, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment