##// END OF EJS Templates
displaypub b64 encoding is non-destructive...
MinRK -
Show More
@@ -31,12 +31,15 b' class ZMQDisplayHook(object):'
31 31
32 32
33 33 def _encode_binary(format_dict):
34 encoded = format_dict.copy()
34 35 pngdata = format_dict.get('image/png')
35 if pngdata is not None:
36 format_dict['image/png'] = encodestring(pngdata).decode('ascii')
36 if isinstance(pngdata, bytes):
37 encoded['image/png'] = encodestring(pngdata).decode('ascii')
37 38 jpegdata = format_dict.get('image/jpeg')
38 if jpegdata is not None:
39 format_dict['image/jpeg'] = encodestring(jpegdata).decode('ascii')
39 if isinstance(jpegdata, bytes):
40 encoded['image/jpeg'] = encodestring(jpegdata).decode('ascii')
41
42 return encoded
40 43
41 44
42 45 class ZMQShellDisplayHook(DisplayHook):
@@ -61,8 +64,7 b' class ZMQShellDisplayHook(DisplayHook):'
61 64 self.msg['content']['execution_count'] = self.prompt_count
62 65
63 66 def write_format_data(self, format_dict):
64 _encode_binary(format_dict)
65 self.msg['content']['data'] = format_dict
67 self.msg['content']['data'] = _encode_binary(format_dict)
66 68
67 69 def finish_displayhook(self):
68 70 """Finish up all displayhook activities."""
@@ -77,8 +77,7 b' class ZMQDisplayPublisher(DisplayPublisher):'
77 77 self._validate_data(source, data, metadata)
78 78 content = {}
79 79 content['source'] = source
80 _encode_binary(data)
81 content['data'] = data
80 content['data'] = _encode_binary(data)
82 81 content['metadata'] = metadata
83 82 self.session.send(
84 83 self.pub_socket, u'display_data', json_clean(content),
General Comments 0
You need to be logged in to leave comments. Login now