Show More
@@ -33,6 +33,7 b' from IPython.external.decorator import decorator' | |||
|
33 | 33 | # Our own imports |
|
34 | 34 | from IPython.config.configurable import Configurable |
|
35 | 35 | from IPython.lib import pretty |
|
36 | from IPython.utils import io | |
|
36 | 37 | from IPython.utils.traitlets import ( |
|
37 | 38 | Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List, |
|
38 | 39 | ) |
@@ -182,15 +183,21 b' class DisplayFormatter(Configurable):' | |||
|
182 | 183 | # Formatters for specific format types (text, html, svg, etc.) |
|
183 | 184 | #----------------------------------------------------------------------------- |
|
184 | 185 | |
|
185 | ||
|
186 | 186 | @decorator |
|
187 | 187 | def warn_format_error(method, self, *args, **kwargs): |
|
188 | 188 | """decorator for warning on failed format call""" |
|
189 | 189 | try: |
|
190 |
r |
|
|
190 | r = method(self, *args, **kwargs) | |
|
191 | 191 | except Exception as e: |
|
192 | 192 | warn("Exception in %s formatter: %s" % (self.format_type, e)) |
|
193 | 193 | return None |
|
194 | if r is None or isinstance(r, self._return_type): | |
|
195 | return r | |
|
196 | else: | |
|
197 | warn("%s formatter returned invalid type %s for object: %s" % ( | |
|
198 | self.format_type, type(r), pretty._safe_repr(obj) | |
|
199 | )) | |
|
200 | ||
|
194 | 201 | |
|
195 | 202 | |
|
196 | 203 | class FormatterABC(with_metaclass(abc.ABCMeta, object)): |
@@ -262,6 +269,7 b' class BaseFormatter(Configurable):' | |||
|
262 | 269 | """ |
|
263 | 270 | |
|
264 | 271 | format_type = Unicode('text/plain') |
|
272 | _return_type = string_types | |
|
265 | 273 | |
|
266 | 274 | enabled = Bool(True, config=True) |
|
267 | 275 | |
@@ -680,6 +688,8 b' class PNGFormatter(BaseFormatter):' | |||
|
680 | 688 | |
|
681 | 689 | print_method = ObjectName('_repr_png_') |
|
682 | 690 | |
|
691 | _return_type = bytes | |
|
692 | ||
|
683 | 693 | |
|
684 | 694 | class JPEGFormatter(BaseFormatter): |
|
685 | 695 | """A JPEG formatter. |
@@ -696,6 +706,8 b' class JPEGFormatter(BaseFormatter):' | |||
|
696 | 706 | |
|
697 | 707 | print_method = ObjectName('_repr_jpeg_') |
|
698 | 708 | |
|
709 | _return_type = bytes | |
|
710 | ||
|
699 | 711 | |
|
700 | 712 | class LatexFormatter(BaseFormatter): |
|
701 | 713 | """A LaTeX formatter. |
General Comments 0
You need to be logged in to leave comments.
Login now