##// END OF EJS Templates
remove `source` key from display_data
MinRK -
Show More
@@ -126,13 +126,13 b' def display(*objs, **kwargs):'
126 126 else:
127 127 continue
128 128 if raw:
129 publish_display_data('display', obj, metadata)
129 publish_display_data(data=obj, metadata=metadata)
130 130 else:
131 131 format_dict, md_dict = format(obj, include=include, exclude=exclude)
132 132 if metadata:
133 133 # kwarg-specified metadata gets precedence
134 134 _merge(md_dict, metadata)
135 publish_display_data('display', format_dict, md_dict)
135 publish_display_data(data=format_dict, metadata=md_dict)
136 136
137 137
138 138 def display_pretty(*objs, **kwargs):
@@ -10,22 +10,10 b' There are two components of the display system:'
10 10 This module defines the logic display publishing. The display publisher uses
11 11 the ``display_data`` message type that is defined in the IPython messaging
12 12 spec.
13
14 Authors:
15
16 * Brian Granger
17 13 """
18 14
19 #-----------------------------------------------------------------------------
20 # Copyright (C) 2008-2011 The IPython Development Team
21 #
22 # Distributed under the terms of the BSD License. The full license is in
23 # the file COPYING, distributed as part of this software.
24 #-----------------------------------------------------------------------------
25
26 #-----------------------------------------------------------------------------
27 # Imports
28 #-----------------------------------------------------------------------------
15 # Copyright (c) IPython Development Team.
16 # Distributed under the terms of the Modified BSD License.
29 17
30 18 from __future__ import print_function
31 19
@@ -45,29 +33,24 b' class DisplayPublisher(Configurable):'
45 33 be accessed there.
46 34 """
47 35
48 def _validate_data(self, source, data, metadata=None):
36 def _validate_data(self, data, metadata=None):
49 37 """Validate the display data.
50 38
51 39 Parameters
52 40 ----------
53 source : str
54 The fully dotted name of the callable that created the data, like
55 :func:`foo.bar.my_formatter`.
56 41 data : dict
57 42 The formata data dictionary.
58 43 metadata : dict
59 44 Any metadata for the data.
60 45 """
61 46
62 if not isinstance(source, string_types):
63 raise TypeError('source must be a str, got: %r' % source)
64 47 if not isinstance(data, dict):
65 48 raise TypeError('data must be a dict, got: %r' % data)
66 49 if metadata is not None:
67 50 if not isinstance(metadata, dict):
68 51 raise TypeError('metadata must be a dict, got: %r' % data)
69 52
70 def publish(self, source, data, metadata=None):
53 def publish(self, data, metadata=None, source=None):
71 54 """Publish data and metadata to all frontends.
72 55
73 56 See the ``display_data`` message in the messaging documentation for
@@ -87,9 +70,6 b' class DisplayPublisher(Configurable):'
87 70
88 71 Parameters
89 72 ----------
90 source : str
91 A string that give the function or method that created the data,
92 such as 'IPython.core.page'.
93 73 data : dict
94 74 A dictionary having keys that are valid MIME types (like
95 75 'text/plain' or 'image/svg+xml') and values that are the data for
@@ -104,6 +84,8 b' class DisplayPublisher(Configurable):'
104 84 the data. Metadata specific to each mime-type can be specified
105 85 in the metadata dict with the same mime-type keys as
106 86 the data itself.
87 source : str, deprecated
88 Unused.
107 89 """
108 90
109 91 # The default is to simply write the plain text data using io.stdout.
@@ -122,8 +104,8 b' class CapturingDisplayPublisher(DisplayPublisher):'
122 104 """A DisplayPublisher that stores"""
123 105 outputs = List()
124 106
125 def publish(self, source, data, metadata=None):
126 self.outputs.append((source, data, metadata))
107 def publish(self, data, metadata=None, source=None):
108 self.outputs.append((data, metadata))
127 109
128 110 def clear_output(self, wait=False):
129 111 super(CapturingDisplayPublisher, self).clear_output(wait)
@@ -132,7 +114,7 b' class CapturingDisplayPublisher(DisplayPublisher):'
132 114 del self.outputs[:]
133 115
134 116
135 def publish_display_data(source, data, metadata=None):
117 def publish_display_data(data, metadata=None, source=None):
136 118 """Publish data and metadata to all frontends.
137 119
138 120 See the ``display_data`` message in the messaging documentation for
@@ -152,9 +134,6 b' def publish_display_data(source, data, metadata=None):'
152 134
153 135 Parameters
154 136 ----------
155 source : str
156 A string that give the function or method that created the data,
157 such as 'IPython.core.page'.
158 137 data : dict
159 138 A dictionary having keys that are valid MIME types (like
160 139 'text/plain' or 'image/svg+xml') and values that are the data for
@@ -168,12 +147,13 b' def publish_display_data(source, data, metadata=None):'
168 147 arbitrary key, value pairs that frontends can use to interpret
169 148 the data. mime-type keys matching those in data can be used
170 149 to specify metadata about particular representations.
150 source : str, deprecated
151 Unused.
171 152 """
172 153 from IPython.core.interactiveshell import InteractiveShell
173 154 InteractiveShell.instance().display_pub.publish(
174 source,
175 data,
176 metadata
155 data=data,
156 metadata=metadata,
177 157 )
178 158
179 159
@@ -165,7 +165,7 b' class Stream(Reference):'
165 165
166 166
167 167 class DisplayData(MimeBundle):
168 source = Unicode()
168 pass
169 169
170 170
171 171 class ExecuteResult(MimeBundle):
@@ -73,13 +73,12 b' class ZMQDisplayPublisher(DisplayPublisher):'
73 73 sys.stdout.flush()
74 74 sys.stderr.flush()
75 75
76 def publish(self, source, data, metadata=None):
76 def publish(self, data, metadata=None, source=None):
77 77 self._flush_streams()
78 78 if metadata is None:
79 79 metadata = {}
80 self._validate_data(source, data, metadata)
80 self._validate_data(data, metadata)
81 81 content = {}
82 content['source'] = source
83 82 content['data'] = encode_images(data)
84 83 content['metadata'] = metadata
85 84 self.session.send(
@@ -90,7 +90,7 b' class ExecuteReply(RichOutput):'
90 90
91 91 def display(self):
92 92 from IPython.display import publish_display_data
93 publish_display_data(self.source, self.data, self.metadata)
93 publish_display_data(self.data, self.metadata)
94 94
95 95 def _repr_mime_(self, mime):
96 96 if mime not in self.data:
@@ -1,19 +1,10 b''
1 1 # encoding: utf-8
2 """
3 IO capturing utilities.
4 """
2 """IO capturing utilities."""
5 3
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2013 The IPython Development Team
8 #
9 # Distributed under the terms of the BSD License. The full license is in
10 # the file COPYING, distributed as part of this software.
11 #-----------------------------------------------------------------------------
12 from __future__ import print_function, absolute_import
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
13 6
14 #-----------------------------------------------------------------------------
15 # Imports
16 #-----------------------------------------------------------------------------
7 from __future__ import print_function, absolute_import
17 8
18 9 import sys
19 10
@@ -30,14 +21,13 b' else:'
30 21
31 22
32 23 class RichOutput(object):
33 def __init__(self, source="", data=None, metadata=None):
34 self.source = source
24 def __init__(self, data=None, metadata=None):
35 25 self.data = data or {}
36 26 self.metadata = metadata or {}
37 27
38 28 def display(self):
39 29 from IPython.display import publish_display_data
40 publish_display_data(self.source, self.data, self.metadata)
30 publish_display_data(data=self.data, metadata=self.metadata)
41 31
42 32 def _repr_mime_(self, mime):
43 33 if mime not in self.data:
@@ -118,7 +108,7 b' class CapturedIO(object):'
118 108 for o in c.outputs:
119 109 display(o)
120 110 """
121 return [ RichOutput(s, d, md) for s, d, md in self._outputs ]
111 return [ RichOutput(d, md) for d, md in self._outputs ]
122 112
123 113 def show(self):
124 114 """write my output to sys.stdout/err as appropriate"""
@@ -126,8 +116,8 b' class CapturedIO(object):'
126 116 sys.stderr.write(self.stderr)
127 117 sys.stdout.flush()
128 118 sys.stderr.flush()
129 for source, data, metadata in self._outputs:
130 RichOutput(source, data, metadata).display()
119 for data, metadata in self._outputs:
120 RichOutput(data, metadata).display()
131 121
132 122 __call__ = show
133 123
@@ -78,8 +78,7 b' def test_rich_output():'
78 78 """test RichOutput basics"""
79 79 data = basic_data
80 80 metadata = basic_metadata
81 rich = capture.RichOutput(source="test", data=data, metadata=metadata)
82 yield nt.assert_equal, rich.source, "test"
81 rich = capture.RichOutput(data=data, metadata=metadata)
83 82 yield nt.assert_equal, rich._repr_html_(), data['text/html']
84 83 yield nt.assert_equal, rich._repr_png_(), (data['image/png'], metadata['image/png'])
85 84 yield nt.assert_equal, rich._repr_latex_(), None
@@ -89,7 +88,7 b' def test_rich_output():'
89 88 def test_rich_output_no_metadata():
90 89 """test RichOutput with no metadata"""
91 90 data = full_data
92 rich = capture.RichOutput(source="test", data=data)
91 rich = capture.RichOutput(data=data)
93 92 for method, mime in _mime_map.items():
94 93 yield nt.assert_equal, getattr(rich, method)(), data[mime]
95 94
@@ -97,7 +96,7 b' def test_rich_output_metadata():'
97 96 """test RichOutput with metadata"""
98 97 data = full_data
99 98 metadata = full_metadata
100 rich = capture.RichOutput(source="test", data=data, metadata=metadata)
99 rich = capture.RichOutput(data=data, metadata=metadata)
101 100 for method, mime in _mime_map.items():
102 101 yield nt.assert_equal, getattr(rich, method)(), (data[mime], metadata[mime])
103 102
General Comments 0
You need to be logged in to leave comments. Login now