##// END OF EJS Templates
msgspec 5: stream.data -> stream.text
MinRK -
Show More
@@ -210,7 +210,7 b' define(['
210 var msg_type = json.output_type = msg.header.msg_type;
210 var msg_type = json.output_type = msg.header.msg_type;
211 var content = msg.content;
211 var content = msg.content;
212 if (msg_type === "stream") {
212 if (msg_type === "stream") {
213 json.text = content.data;
213 json.text = content.text;
214 json.stream = content.name;
214 json.stream = content.name;
215 } else if (msg_type === "display_data") {
215 } else if (msg_type === "display_data") {
216 json = content.data;
216 json = content.data;
@@ -163,6 +163,11 b' class V5toV4(Adapter):'
163
163
164 # iopub channel
164 # iopub channel
165
165
166 def stream(self, msg):
167 content = msg['content']
168 content['data'] = content.pop('text')
169 return msg
170
166 def display_data(self, msg):
171 def display_data(self, msg):
167 content = msg['content']
172 content = msg['content']
168 content.setdefault("source", "display")
173 content.setdefault("source", "display")
@@ -287,6 +292,11 b' class V4toV5(Adapter):'
287
292
288 # iopub channel
293 # iopub channel
289
294
295 def stream(self, msg):
296 content = msg['content']
297 content['text'] = content.pop('data')
298 return msg
299
290 def display_data(self, msg):
300 def display_data(self, msg):
291 content = msg['content']
301 content = msg['content']
292 content.pop("source", None)
302 content.pop("source", None)
@@ -1,20 +1,11 b''
1 #-------------------------------------------------------------------------------
1 # Copyright (c) IPython Development Team.
2 # Copyright (C) 2012 The IPython Development Team
2 # Distributed under the terms of the Modified BSD License.
3 #
4 # Distributed under the terms of the BSD License. The full license is in
5 # the file COPYING, distributed as part of this software.
6 #-------------------------------------------------------------------------------
7
3
8 #-----------------------------------------------------------------------------
9 # Imports
10 #-----------------------------------------------------------------------------
11 from __future__ import print_function
4 from __future__ import print_function
12
5
13 # Standard library imports
14 import sys
6 import sys
15 import unittest
7 import unittest
16
8
17 # Local imports
18 from IPython.kernel.inprocess.blocking import BlockingInProcessKernelClient
9 from IPython.kernel.inprocess.blocking import BlockingInProcessKernelClient
19 from IPython.kernel.inprocess.manager import InProcessKernelManager
10 from IPython.kernel.inprocess.manager import InProcessKernelManager
20 from IPython.kernel.inprocess.ipkernel import InProcessKernel
11 from IPython.kernel.inprocess.ipkernel import InProcessKernel
@@ -27,9 +18,6 b' if py3compat.PY3:'
27 else:
18 else:
28 from StringIO import StringIO
19 from StringIO import StringIO
29
20
30 #-----------------------------------------------------------------------------
31 # Test case
32 #-----------------------------------------------------------------------------
33
21
34 class InProcessKernelTestCase(unittest.TestCase):
22 class InProcessKernelTestCase(unittest.TestCase):
35
23
@@ -41,12 +29,11 b' class InProcessKernelTestCase(unittest.TestCase):'
41
29
42 @skipif_not_matplotlib
30 @skipif_not_matplotlib
43 def test_pylab(self):
31 def test_pylab(self):
44 """ Does pylab work in the in-process kernel?
32 """Does %pylab work in the in-process kernel?"""
45 """
46 kc = self.kc
33 kc = self.kc
47 kc.execute('%pylab')
34 kc.execute('%pylab')
48 msg = get_stream_message(kc)
35 msg = get_stream_message(kc)
49 self.assertIn('matplotlib', msg['content']['data'])
36 self.assertIn('matplotlib', msg['content']['text'])
50
37
51 def test_raw_input(self):
38 def test_raw_input(self):
52 """ Does the in-process kernel handle raw_input correctly?
39 """ Does the in-process kernel handle raw_input correctly?
@@ -76,7 +63,7 b' class InProcessKernelTestCase(unittest.TestCase):'
76 kernel.frontends.append(kc)
63 kernel.frontends.append(kc)
77 kc.shell_channel.execute('print("bar")')
64 kc.shell_channel.execute('print("bar")')
78 msg = get_stream_message(kc)
65 msg = get_stream_message(kc)
79 self.assertEqual(msg['content']['data'], 'bar\n')
66 self.assertEqual(msg['content']['text'], 'bar\n')
80
67
81 #-----------------------------------------------------------------------------
68 #-----------------------------------------------------------------------------
82 # Utility functions
69 # Utility functions
@@ -172,7 +172,7 b' Error = ExecuteReplyError'
172
172
173 class Stream(Reference):
173 class Stream(Reference):
174 name = Enum((u'stdout', u'stderr'))
174 name = Enum((u'stdout', u'stderr'))
175 data = Unicode()
175 text = Unicode()
176
176
177
177
178 class DisplayData(MimeBundle):
178 class DisplayData(MimeBundle):
@@ -394,7 +394,7 b' def test_stream():'
394 stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT)
394 stdout = KC.iopub_channel.get_msg(timeout=TIMEOUT)
395 validate_message(stdout, 'stream', msg_id)
395 validate_message(stdout, 'stream', msg_id)
396 content = stdout['content']
396 content = stdout['content']
397 nt.assert_equal(content['data'], u'hi\n')
397 nt.assert_equal(content['text'], u'hi\n')
398
398
399
399
400 def test_display_data():
400 def test_display_data():
@@ -140,9 +140,9 b' def assemble_output(iopub):'
140 break
140 break
141 elif msg['msg_type'] == 'stream':
141 elif msg['msg_type'] == 'stream':
142 if content['name'] == 'stdout':
142 if content['name'] == 'stdout':
143 stdout += content['data']
143 stdout += content['text']
144 elif content['name'] == 'stderr':
144 elif content['name'] == 'stderr':
145 stderr += content['data']
145 stderr += content['text']
146 else:
146 else:
147 raise KeyError("bad stream: %r" % content['name'])
147 raise KeyError("bad stream: %r" % content['name'])
148 else:
148 else:
@@ -163,7 +163,7 b' class OutStream(object):'
163 data = self._flush_buffer()
163 data = self._flush_buffer()
164
164
165 if data:
165 if data:
166 content = {u'name':self.name, u'data':data}
166 content = {u'name':self.name, u'text':data}
167 msg = self.session.send(self.pub_socket, u'stream', content=content,
167 msg = self.session.send(self.pub_socket, u'stream', content=content,
168 parent=self.parent_header, ident=self.topic)
168 parent=self.parent_header, ident=self.topic)
169
169
@@ -123,7 +123,7 b' class ExecutePreprocessor(Preprocessor):'
123
123
124 if msg_type == 'stream':
124 if msg_type == 'stream':
125 out.stream = content['name']
125 out.stream = content['name']
126 out.text = content['data']
126 out.text = content['text']
127 elif msg_type in ('display_data', 'execute_result'):
127 elif msg_type in ('display_data', 'execute_result'):
128 out['metadata'] = content['metadata']
128 out['metadata'] = content['metadata']
129 for mime, data in content['data'].items():
129 for mime, data in content['data'].items():
@@ -874,7 +874,7 b' class Client(HasTraits):'
874 if msg_type == 'stream':
874 if msg_type == 'stream':
875 name = content['name']
875 name = content['name']
876 s = md[name] or ''
876 s = md[name] or ''
877 md[name] = s + content['data']
877 md[name] = s + content['text']
878 elif msg_type == 'error':
878 elif msg_type == 'error':
879 md.update({'error' : self._unwrap_exception(content)})
879 md.update({'error' : self._unwrap_exception(content)})
880 elif msg_type == 'execute_input':
880 elif msg_type == 'execute_input':
@@ -862,7 +862,7 b' class Hub(SessionFactory):'
862 if msg_type == 'stream':
862 if msg_type == 'stream':
863 name = content['name']
863 name = content['name']
864 s = '' if rec is None else rec[name]
864 s = '' if rec is None else rec[name]
865 d[name] = s + content['data']
865 d[name] = s + content['text']
866
866
867 elif msg_type == 'error':
867 elif msg_type == 'error':
868 d['error'] = content
868 d['error'] = content
@@ -531,7 +531,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
531 self.log.debug("stream: %s", msg.get('content', ''))
531 self.log.debug("stream: %s", msg.get('content', ''))
532 if not self._hidden and self._is_from_this_session(msg):
532 if not self._hidden and self._is_from_this_session(msg):
533 self.flush_clearoutput()
533 self.flush_clearoutput()
534 self.append_stream(msg['content']['data'])
534 self.append_stream(msg['content']['text'])
535
535
536 def _handle_shutdown_reply(self, msg):
536 def _handle_shutdown_reply(self, msg):
537 """ Handle shutdown signal, only if from other console.
537 """ Handle shutdown signal, only if from other console.
@@ -235,13 +235,13 b' class ZMQTerminalInteractiveShell(TerminalInteractiveShell):'
235 if self._pending_clearoutput:
235 if self._pending_clearoutput:
236 print("\r", file=io.stdout, end="")
236 print("\r", file=io.stdout, end="")
237 self._pending_clearoutput = False
237 self._pending_clearoutput = False
238 print(sub_msg["content"]["data"], file=io.stdout, end="")
238 print(sub_msg["content"]["text"], file=io.stdout, end="")
239 io.stdout.flush()
239 io.stdout.flush()
240 elif sub_msg["content"]["name"] == "stderr" :
240 elif sub_msg["content"]["name"] == "stderr":
241 if self._pending_clearoutput:
241 if self._pending_clearoutput:
242 print("\r", file=io.stderr, end="")
242 print("\r", file=io.stderr, end="")
243 self._pending_clearoutput = False
243 self._pending_clearoutput = False
244 print(sub_msg["content"]["data"], file=io.stderr, end="")
244 print(sub_msg["content"]["text"], file=io.stderr, end="")
245 io.stderr.flush()
245 io.stderr.flush()
246
246
247 elif msg_type == 'execute_result':
247 elif msg_type == 'execute_result':
@@ -711,10 +711,14 b' Message type: ``stream``::'
711 # The name of the stream is one of 'stdout', 'stderr'
711 # The name of the stream is one of 'stdout', 'stderr'
712 'name' : str,
712 'name' : str,
713
713
714 # The data is an arbitrary string to be written to that stream
714 # The text is an arbitrary string to be written to that stream
715 'data' : str,
715 'text' : str,
716 }
716 }
717
717
718 .. versionchanged:: 5.0
719
720 'data' key renamed to 'text' for conistency with the notebook format.
721
718 Display Data
722 Display Data
719 ------------
723 ------------
720
724
General Comments 0
You need to be logged in to leave comments. Login now