Show More
@@ -32,7 +32,9 b' from StringIO import StringIO' | |||
|
32 | 32 | # Our own imports |
|
33 | 33 | from IPython.config.configurable import Configurable |
|
34 | 34 | from IPython.lib import pretty |
|
35 | from IPython.utils.traitlets import Bool, Dict, Integer, Unicode, CUnicode, ObjectName | |
|
35 | from IPython.utils.traitlets import ( | |
|
36 | Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List, | |
|
37 | ) | |
|
36 | 38 | from IPython.utils.py3compat import unicode_to_str |
|
37 | 39 | |
|
38 | 40 | |
@@ -45,6 +47,21 b' class DisplayFormatter(Configurable):' | |||
|
45 | 47 | |
|
46 | 48 | # When set to true only the default plain text formatter will be used. |
|
47 | 49 | plain_text_only = Bool(False, config=True) |
|
50 | def _plain_text_only_changed(self, name, old, new): | |
|
51 | warnings.warn("""DisplayFormatter.plain_text_only is deprecated. | |
|
52 | ||
|
53 | Use DisplayFormatter.active_types = ['text/plain'] | |
|
54 | for the same effect. | |
|
55 | """, DeprecationWarning) | |
|
56 | if new: | |
|
57 | self.active_types = ['text/plain'] | |
|
58 | else: | |
|
59 | self.active_types = self.format_types | |
|
60 | ||
|
61 | active_types = List(Unicode, config=True, | |
|
62 | help="""List of currently active mime-types""") | |
|
63 | def _active_types_default(self): | |
|
64 | return self.format_types | |
|
48 | 65 | |
|
49 | 66 | # A dict of formatter whose keys are format types (MIME types) and whose |
|
50 | 67 | # values are subclasses of BaseFormatter. |
@@ -91,8 +108,9 b' class DisplayFormatter(Configurable):' | |||
|
91 | 108 | A list of format type strings (MIME types) to include in the |
|
92 | 109 | format data dict. If this is set *only* the format types included |
|
93 | 110 | in this list will be computed. |
|
111 | If unspecified, `active_types` will be used. | |
|
94 | 112 | exclude : list or tuple, optional |
|
95 | A list of format type string (MIME types) to exclue in the format | |
|
113 | A list of format type string (MIME types) to exclude in the format | |
|
96 | 114 | data dict. If this is set all format types will be computed, |
|
97 | 115 | except for those included in this argument. |
|
98 | 116 | |
@@ -106,23 +124,12 b' class DisplayFormatter(Configurable):' | |||
|
106 | 124 | that format. |
|
107 | 125 | """ |
|
108 | 126 | format_dict = {} |
|
109 | ||
|
110 | # If plain text only is active | |
|
111 | if self.plain_text_only: | |
|
112 | formatter = self.formatters['text/plain'] | |
|
113 | try: | |
|
114 | data = formatter(obj) | |
|
115 | except: | |
|
116 | # FIXME: log the exception | |
|
117 | raise | |
|
118 | if data is not None: | |
|
119 | format_dict['text/plain'] = data | |
|
120 | return format_dict | |
|
127 | if include is None: | |
|
128 | include = self.active_types | |
|
121 | 129 | |
|
122 | 130 | for format_type, formatter in self.formatters.items(): |
|
123 | if include is not None: | |
|
124 |
|
|
|
125 | continue | |
|
131 | if format_type not in include: | |
|
132 | continue | |
|
126 | 133 | if exclude is not None: |
|
127 | 134 | if format_type in exclude: |
|
128 | 135 | continue |
General Comments 0
You need to be logged in to leave comments.
Login now