Show More
@@ -26,13 +26,16 b' Authors:' | |||||
26 | # Stdlib imports |
|
26 | # Stdlib imports | |
27 | import abc |
|
27 | import abc | |
28 | import sys |
|
28 | import sys | |
|
29 | import warnings | |||
29 | # We must use StringIO, as cStringIO doesn't handle unicode properly. |
|
30 | # We must use StringIO, as cStringIO doesn't handle unicode properly. | |
30 | from StringIO import StringIO |
|
31 | from StringIO import StringIO | |
31 |
|
32 | |||
32 | # Our own imports |
|
33 | # Our own imports | |
33 | from IPython.config.configurable import Configurable |
|
34 | from IPython.config.configurable import Configurable | |
34 | from IPython.lib import pretty |
|
35 | from IPython.lib import pretty | |
35 | from IPython.utils.traitlets import Bool, Dict, Integer, Unicode, CUnicode, ObjectName |
|
36 | from IPython.utils.traitlets import ( | |
|
37 | Bool, Dict, Integer, Unicode, CUnicode, ObjectName, List, | |||
|
38 | ) | |||
36 | from IPython.utils.py3compat import unicode_to_str |
|
39 | from IPython.utils.py3compat import unicode_to_str | |
37 |
|
40 | |||
38 |
|
41 | |||
@@ -45,7 +48,33 b' class DisplayFormatter(Configurable):' | |||||
45 |
|
48 | |||
46 | # When set to true only the default plain text formatter will be used. |
|
49 | # When set to true only the default plain text formatter will be used. | |
47 | plain_text_only = Bool(False, config=True) |
|
50 | plain_text_only = Bool(False, config=True) | |
48 |
|
51 | def _plain_text_only_changed(self, name, old, new): | ||
|
52 | warnings.warn("""DisplayFormatter.plain_text_only is deprecated. | |||
|
53 | ||||
|
54 | Use DisplayFormatter.active_types = ['text/plain'] | |||
|
55 | for the same effect. | |||
|
56 | """, DeprecationWarning) | |||
|
57 | if new: | |||
|
58 | self.active_types = ['text/plain'] | |||
|
59 | else: | |||
|
60 | self.active_types = self.format_types | |||
|
61 | ||||
|
62 | active_types = List(Unicode, config=True, | |||
|
63 | help="""List of currently active mime-types to display. | |||
|
64 | You can use this to set a white-list for formats to display. | |||
|
65 | ||||
|
66 | Most users will not need to change this value. | |||
|
67 | """) | |||
|
68 | def _active_types_default(self): | |||
|
69 | return self.format_types | |||
|
70 | ||||
|
71 | def _active_types_changed(self, name, old, new): | |||
|
72 | for key, formatter in self.formatters.items(): | |||
|
73 | if key in new: | |||
|
74 | formatter.enabled = True | |||
|
75 | else: | |||
|
76 | formatter.enabled = False | |||
|
77 | ||||
49 | # A dict of formatter whose keys are format types (MIME types) and whose |
|
78 | # A dict of formatter whose keys are format types (MIME types) and whose | |
50 | # values are subclasses of BaseFormatter. |
|
79 | # values are subclasses of BaseFormatter. | |
51 | formatters = Dict() |
|
80 | formatters = Dict() | |
@@ -92,7 +121,7 b' class DisplayFormatter(Configurable):' | |||||
92 | format data dict. If this is set *only* the format types included |
|
121 | format data dict. If this is set *only* the format types included | |
93 | in this list will be computed. |
|
122 | in this list will be computed. | |
94 | exclude : list or tuple, optional |
|
123 | exclude : list or tuple, optional | |
95 | A list of format type string (MIME types) to exclue in the format |
|
124 | 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, |
|
125 | data dict. If this is set all format types will be computed, | |
97 | except for those included in this argument. |
|
126 | except for those included in this argument. | |
98 |
|
127 | |||
@@ -107,25 +136,11 b' class DisplayFormatter(Configurable):' | |||||
107 | """ |
|
136 | """ | |
108 | format_dict = {} |
|
137 | format_dict = {} | |
109 |
|
138 | |||
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 |
|
|||
121 |
|
||||
122 | for format_type, formatter in self.formatters.items(): |
|
139 | for format_type, formatter in self.formatters.items(): | |
123 |
if include |
|
140 | if include and format_type not in include: | |
124 |
|
|
141 | continue | |
125 | continue |
|
142 | if exclude and format_type in exclude: | |
126 | if exclude is not None: |
|
143 | continue | |
127 | if format_type in exclude: |
|
|||
128 | continue |
|
|||
129 | try: |
|
144 | try: | |
130 | data = formatter(obj) |
|
145 | data = formatter(obj) | |
131 | except: |
|
146 | except: |
@@ -427,7 +427,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
427 | save_dstore('rc_separate_out2',shell.separate_out2) |
|
427 | save_dstore('rc_separate_out2',shell.separate_out2) | |
428 | save_dstore('rc_prompts_pad_left',pm.justify) |
|
428 | save_dstore('rc_prompts_pad_left',pm.justify) | |
429 | save_dstore('rc_separate_in',shell.separate_in) |
|
429 | save_dstore('rc_separate_in',shell.separate_in) | |
430 |
save_dstore('rc_ |
|
430 | save_dstore('rc_active_types',disp_formatter.active_types) | |
431 | save_dstore('prompt_templates',(pm.in_template, pm.in2_template, pm.out_template)) |
|
431 | save_dstore('prompt_templates',(pm.in_template, pm.in2_template, pm.out_template)) | |
432 |
|
432 | |||
433 | if mode == False: |
|
433 | if mode == False: | |
@@ -444,7 +444,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
444 | pm.justify = False |
|
444 | pm.justify = False | |
445 |
|
445 | |||
446 | ptformatter.pprint = False |
|
446 | ptformatter.pprint = False | |
447 |
disp_formatter. |
|
447 | disp_formatter.active_types = ['text/plain'] | |
448 |
|
448 | |||
449 | shell.magic('xmode Plain') |
|
449 | shell.magic('xmode Plain') | |
450 | else: |
|
450 | else: | |
@@ -459,7 +459,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
459 | pm.justify = dstore.rc_prompts_pad_left |
|
459 | pm.justify = dstore.rc_prompts_pad_left | |
460 |
|
460 | |||
461 | ptformatter.pprint = dstore.rc_pprint |
|
461 | ptformatter.pprint = dstore.rc_pprint | |
462 |
disp_formatter. |
|
462 | disp_formatter.active_types = dstore.rc_active_types | |
463 |
|
463 | |||
464 | shell.magic('xmode ' + dstore.xmode) |
|
464 | shell.magic('xmode ' + dstore.xmode) | |
465 |
|
465 |
@@ -383,6 +383,15 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
383 | self.init_banner(banner1, banner2, display_banner) |
|
383 | self.init_banner(banner1, banner2, display_banner) | |
384 |
|
384 | |||
385 | #------------------------------------------------------------------------- |
|
385 | #------------------------------------------------------------------------- | |
|
386 | # Overrides of init stages | |||
|
387 | #------------------------------------------------------------------------- | |||
|
388 | ||||
|
389 | def init_display_formatter(self): | |||
|
390 | super(TerminalInteractiveShell, self).init_display_formatter() | |||
|
391 | # terminal only supports plaintext | |||
|
392 | self.display_formatter.active_types = ['text/plain'] | |||
|
393 | ||||
|
394 | #------------------------------------------------------------------------- | |||
386 | # Things related to the terminal |
|
395 | # Things related to the terminal | |
387 | #------------------------------------------------------------------------- |
|
396 | #------------------------------------------------------------------------- | |
388 |
|
397 |
@@ -150,18 +150,18 b' class KernelMagics(Magics):' | |||||
150 | # save a few values we'll need to recover later |
|
150 | # save a few values we'll need to recover later | |
151 | mode = save_dstore('mode', False) |
|
151 | mode = save_dstore('mode', False) | |
152 | save_dstore('rc_pprint', ptformatter.pprint) |
|
152 | save_dstore('rc_pprint', ptformatter.pprint) | |
153 |
save_dstore('rc_ |
|
153 | save_dstore('rc_active_types',disp_formatter.active_types) | |
154 | save_dstore('xmode', shell.InteractiveTB.mode) |
|
154 | save_dstore('xmode', shell.InteractiveTB.mode) | |
155 |
|
155 | |||
156 | if mode == False: |
|
156 | if mode == False: | |
157 | # turn on |
|
157 | # turn on | |
158 | ptformatter.pprint = False |
|
158 | ptformatter.pprint = False | |
159 |
disp_formatter. |
|
159 | disp_formatter.active_types = ['text/plain'] | |
160 | shell.magic('xmode Plain') |
|
160 | shell.magic('xmode Plain') | |
161 | else: |
|
161 | else: | |
162 | # turn off |
|
162 | # turn off | |
163 | ptformatter.pprint = dstore.rc_pprint |
|
163 | ptformatter.pprint = dstore.rc_pprint | |
164 |
disp_formatter. |
|
164 | disp_formatter.active_types = dstore.rc_active_types | |
165 | shell.magic("xmode " + dstore.xmode) |
|
165 | shell.magic("xmode " + dstore.xmode) | |
166 |
|
166 | |||
167 | # Store new mode and inform on console |
|
167 | # Store new mode and inform on console |
General Comments 0
You need to be logged in to leave comments.
Login now