Commit e6430096 authored by Romain Casati's avatar Romain Casati
Browse files

Fix in format_repr: try/except in case an repr call fail.

parent 38211e33
......@@ -45,13 +45,20 @@ def display_event(data):
def format_repr(obj):
""" Format data to support different repr types. """
res = {"text/plain": repr(obj)}
if hasattr(obj, "_repr_html_"):
res["text/html"] = obj._repr_html_()
if hasattr(obj, "_repr_svg_"):
res["image/svg+xml"] = obj._repr_svg_()
if hasattr(obj, "_repr_png_"):
res["image/png"] = obj._repr_png_()
res = {}
try:
res["text/plain"] = repr(obj)
except Exception:
pass
mimes = {"text/html": "_repr_html_",
"image/svg+xml": "_repr_svg_",
"image/png": "_repr_png_"}
for mime, _repr in mimes.items():
if hasattr(obj, _repr):
try:
res[mime] = getattr(obj, _repr)()
except Exception:
pass
return res
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment