Show More
@@ -14,7 +14,6 b' import abc' | |||||
14 | import inspect |
|
14 | import inspect | |
15 | import sys |
|
15 | import sys | |
16 | import traceback |
|
16 | import traceback | |
17 | import types |
|
|||
18 | import warnings |
|
17 | import warnings | |
19 |
|
18 | |||
20 | from IPython.external.decorator import decorator |
|
19 | from IPython.external.decorator import decorator | |
@@ -24,7 +23,7 b' from IPython.core.getipython import get_ipython' | |||||
24 | from IPython.lib import pretty |
|
23 | from IPython.lib import pretty | |
25 | from IPython.utils.traitlets import ( |
|
24 | from IPython.utils.traitlets import ( | |
26 | Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List, |
|
25 | Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List, | |
27 | Instance, |
|
26 | ForwardDeclaredInstance, | |
28 | ) |
|
27 | ) | |
29 | from IPython.utils.py3compat import ( |
|
28 | from IPython.utils.py3compat import ( | |
30 | unicode_to_str, with_metaclass, PY3, string_types, unicode_type, |
|
29 | unicode_to_str, with_metaclass, PY3, string_types, unicode_type, | |
@@ -90,9 +89,9 b' class DisplayFormatter(Configurable):' | |||||
90 | else: |
|
89 | else: | |
91 | formatter.enabled = False |
|
90 | formatter.enabled = False | |
92 |
|
91 | |||
93 | self_formatter = Instance(__name__ +'.SelfDisplayingFormatter') |
|
92 | ipython_display_formatter = ForwardDeclaredInstance('FormatterABC') | |
94 |
def _ |
|
93 | def _ipython_display_formatter_default(self): | |
95 |
return |
|
94 | return IPythonDisplayFormatter(parent=self) | |
96 |
|
95 | |||
97 | # A dict of formatter whose keys are format types (MIME types) and whose |
|
96 | # A dict of formatter whose keys are format types (MIME types) and whose | |
98 | # values are subclasses of BaseFormatter. |
|
97 | # values are subclasses of BaseFormatter. | |
@@ -164,7 +163,7 b' class DisplayFormatter(Configurable):' | |||||
164 | format_dict = {} |
|
163 | format_dict = {} | |
165 | md_dict = {} |
|
164 | md_dict = {} | |
166 |
|
165 | |||
167 |
if self. |
|
166 | if self.ipython_display_formatter(obj): | |
168 | # object handled itself, don't proceed |
|
167 | # object handled itself, don't proceed | |
169 | return {}, {} |
|
168 | return {}, {} | |
170 |
|
169 | |||
@@ -840,7 +839,7 b' class PDFFormatter(BaseFormatter):' | |||||
840 |
|
839 | |||
841 | _return_type = (bytes, unicode_type) |
|
840 | _return_type = (bytes, unicode_type) | |
842 |
|
841 | |||
843 |
class |
|
842 | class IPythonDisplayFormatter(BaseFormatter): | |
844 | """A Formatter for objects that know how to display themselves. |
|
843 | """A Formatter for objects that know how to display themselves. | |
845 |
|
844 | |||
846 | To define the callables that compute the representation of your |
|
845 | To define the callables that compute the representation of your | |
@@ -886,7 +885,7 b' FormatterABC.register(JPEGFormatter)' | |||||
886 | FormatterABC.register(LatexFormatter) |
|
885 | FormatterABC.register(LatexFormatter) | |
887 | FormatterABC.register(JSONFormatter) |
|
886 | FormatterABC.register(JSONFormatter) | |
888 | FormatterABC.register(JavascriptFormatter) |
|
887 | FormatterABC.register(JavascriptFormatter) | |
889 |
FormatterABC.register( |
|
888 | FormatterABC.register(IPythonDisplayFormatter) | |
890 |
|
889 | |||
891 |
|
890 | |||
892 | def format_display_data(obj, include=None, exclude=None): |
|
891 | def format_display_data(obj, include=None, exclude=None): |
General Comments 0
You need to be logged in to leave comments.
Login now