Skip to content

Commit

Permalink
Merge pull request #174 from ccordoba12/fix_handling_metadata
Browse files Browse the repository at this point in the history
Fix handling metadata in _formatter
  • Loading branch information
dsblank authored Sep 22, 2018
2 parents 18180f6 + 99fb502 commit 0d5dafe
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions metakernel/_metakernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ def post_execute(self, retval, code, silent):
return
content = {
'execution_count': self.execution_count,
'data': data,
'metadata': {},
'data': data[0],
'metadata': data[1],
}
if not silent:
if Widget and isinstance(retval, Widget):
Expand Down Expand Up @@ -630,8 +630,8 @@ def Display(self, *args, **kwargs):
self.Error(e)
return
content = {
'data': data,
'metadata': {}
'data': data[0],
'metadata': data[1]
}
self.send_response(
self.iopub_socket,
Expand Down Expand Up @@ -810,25 +810,32 @@ def _formatter(data, repr_func):
if obj:
reprs[mimetype] = obj

retval = {}
format_dict = {}
metadata_dict = {}
for (mimetype, value) in reprs.items():
metadata = None
try:
value = value()
except Exception:
pass
if not value:
continue
if isinstance(value, tuple):
metadata = value[1]
value = value[0]
if isinstance(value, bytes):
try:
value = value.decode('utf-8')
except Exception:
value = base64.encodestring(value)
value = value.decode('utf-8')
try:
retval[mimetype] = str(value)
format_dict[mimetype] = str(value)
except:
retval[mimetype] = value
return retval
format_dict[mimetype] = value
if metadata is not None:
metadata_dict[mimetype] = metadata
return (format_dict, metadata_dict)


def format_message(*args, **kwargs):
Expand Down

0 comments on commit 0d5dafe

Please sign in to comment.