##// END OF EJS Templates
add DisplayFormatter.active_types...
MinRK -
Show More
@@ -32,7 +32,9 b' from StringIO import StringIO'
32 # Our own imports
32 # Our own imports
33 from IPython.config.configurable import Configurable
33 from IPython.config.configurable import Configurable
34 from IPython.lib import pretty
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 from IPython.utils.py3compat import unicode_to_str
38 from IPython.utils.py3compat import unicode_to_str
37
39
38
40
@@ -45,6 +47,21 b' class DisplayFormatter(Configurable):'
45
47
46 # When set to true only the default plain text formatter will be used.
48 # When set to true only the default plain text formatter will be used.
47 plain_text_only = Bool(False, config=True)
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 # A dict of formatter whose keys are format types (MIME types) and whose
66 # A dict of formatter whose keys are format types (MIME types) and whose
50 # values are subclasses of BaseFormatter.
67 # values are subclasses of BaseFormatter.
@@ -91,8 +108,9 b' class DisplayFormatter(Configurable):'
91 A list of format type strings (MIME types) to include in the
108 A list of format type strings (MIME types) to include in the
92 format data dict. If this is set *only* the format types included
109 format data dict. If this is set *only* the format types included
93 in this list will be computed.
110 in this list will be computed.
111 If unspecified, `active_types` will be used.
94 exclude : list or tuple, optional
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 data dict. If this is set all format types will be computed,
114 data dict. If this is set all format types will be computed,
97 except for those included in this argument.
115 except for those included in this argument.
98
116
@@ -106,23 +124,12 b' class DisplayFormatter(Configurable):'
106 that format.
124 that format.
107 """
125 """
108 format_dict = {}
126 format_dict = {}
109
127 if include is None:
110 # If plain text only is active
128 include = self.active_types
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
121
129
122 for format_type, formatter in self.formatters.items():
130 for format_type, formatter in self.formatters.items():
123 if include is not None:
131 if format_type not in include:
124 if format_type not in include:
132 continue
125 continue
126 if exclude is not None:
133 if exclude is not None:
127 if format_type in exclude:
134 if format_type in exclude:
128 continue
135 continue
General Comments 0
You need to be logged in to leave comments. Login now