Skip to content

Commit 91cbd41

Browse files
committed
ensure status is included in all replies
according to the spec
1 parent e66c5e9 commit 91cbd41

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

ipykernel/ipkernel.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def do_execute(self, code, silent, store_history=True,
205205
if res.success:
206206
reply_content[u'status'] = u'ok'
207207
elif isinstance(err, KeyboardInterrupt):
208-
reply_content[u'status'] = u'abort'
208+
reply_content[u'status'] = u'aborted'
209209
else:
210210
reply_content[u'status'] = u'error'
211211

@@ -296,7 +296,10 @@ def do_history(self, hist_access_type, output, raw, session=None, start=None,
296296
else:
297297
hist = []
298298

299-
return {'history' : list(hist)}
299+
return {
300+
'status': 'ok',
301+
'history' : list(hist),
302+
}
300303

301304
def do_shutdown(self, restart):
302305
self.shell.exit_now = True

ipykernel/kernelbase.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,14 @@ def do_history(self, hist_access_type, output, raw, session=None, start=None,
467467
stop=None, n=None, pattern=None, unique=False):
468468
"""Override in subclasses to access history.
469469
"""
470-
return {'history': []}
470+
return {'status': 'ok', 'history': []}
471471

472472
def connect_request(self, stream, ident, parent):
473473
if self._recorded_ports is not None:
474474
content = self._recorded_ports.copy()
475475
else:
476476
content = {}
477+
content['status'] = 'ok'
477478
msg = self.session.send(stream, 'connect_reply',
478479
content, parent, ident)
479480
self.log.debug("%s", msg)
@@ -490,8 +491,10 @@ def kernel_info(self):
490491
}
491492

492493
def kernel_info_request(self, stream, ident, parent):
494+
content = {'status': 'ok'}
495+
content.update(self.kernel_info)
493496
msg = self.session.send(stream, 'kernel_info_reply',
494-
self.kernel_info, parent, ident)
497+
content, parent, ident)
495498
self.log.debug("%s", msg)
496499

497500
def comm_info_request(self, stream, ident, parent):
@@ -507,7 +510,7 @@ def comm_info_request(self, stream, ident, parent):
507510
}
508511
else:
509512
comms = {}
510-
reply_content = dict(comms=comms)
513+
reply_content = dict(comms=comms, status='ok')
511514
msg = self.session.send(stream, 'comm_info_reply',
512515
reply_content, parent, ident)
513516
self.log.debug("%s", msg)

ipykernel/tests/test_message_spec.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ def _data_changed(self, name, old, new):
103103
assert mime_pat.match(k)
104104
nt.assert_is_instance(v, string_types)
105105

106+
106107
# shell replies
108+
class Reply(Reference):
109+
status = Enum((u'ok', u'error'), default_value=u'ok')
107110

108-
class ExecuteReply(Reference):
111+
112+
class ExecuteReply(Reply):
109113
execution_count = Integer()
110-
status = Enum((u'ok', u'error'), default_value=u'ok')
111114

112115
def check(self, d):
113116
Reference.check(self, d)
@@ -117,18 +120,18 @@ def check(self, d):
117120
ExecuteReplyError().check(d)
118121

119122

120-
class ExecuteReplyOkay(Reference):
121-
payload = List(Dict())
123+
class ExecuteReplyOkay(Reply):
124+
status = Enum(('ok',))
122125
user_expressions = Dict()
123126

124127

125-
class ExecuteReplyError(Reference):
128+
class ExecuteReplyError(Reply):
126129
ename = Unicode()
127130
evalue = Unicode()
128131
traceback = List(Unicode())
129132

130133

131-
class InspectReply(MimeBundle):
134+
class InspectReply(Reply, MimeBundle):
132135
found = Bool()
133136

134137

@@ -143,17 +146,19 @@ class Status(Reference):
143146
execution_state = Enum((u'busy', u'idle', u'starting'), default_value=u'busy')
144147

145148

146-
class CompleteReply(Reference):
149+
class CompleteReply(Reply):
147150
matches = List(Unicode())
148151
cursor_start = Integer()
149152
cursor_end = Integer()
150153
status = Unicode()
151154

155+
152156
class LanguageInfo(Reference):
153157
name = Unicode('python')
154158
version = Unicode(sys.version.split()[0])
155159

156-
class KernelInfoReply(Reference):
160+
161+
class KernelInfoReply(Reply):
157162
protocol_version = Version(min='5.0')
158163
implementation = Unicode('ipython')
159164
implementation_version = Version(min='2.1')
@@ -173,9 +178,10 @@ class ConnectReply(Reference):
173178
hb_port = Integer()
174179

175180

176-
class CommInfoReply(Reference):
181+
class CommInfoReply(Reply):
177182
comms = Dict()
178183

184+
179185
class IsCompleteReply(Reference):
180186
status = Enum((u'complete', u'incomplete', u'invalid', u'unknown'), default_value=u'complete')
181187

@@ -184,6 +190,7 @@ def check(self, d):
184190
if d['status'] == 'incomplete':
185191
IsCompleteReplyIncomplete().check(d)
186192

193+
187194
class IsCompleteReplyIncomplete(Reference):
188195
indent = Unicode()
189196

@@ -195,7 +202,9 @@ class ExecuteInput(Reference):
195202
execution_count = Integer()
196203

197204

198-
Error = ExecuteReplyError
205+
class Error(ExecuteReplyError):
206+
"""Errors are the same as ExecuteReply, but without status"""
207+
status = None # no status field
199208

200209

201210
class Stream(Reference):
@@ -211,7 +220,7 @@ class ExecuteResult(MimeBundle):
211220
execution_count = Integer()
212221

213222

214-
class HistoryReply(Reference):
223+
class HistoryReply(Reply):
215224
history = List(List())
216225

217226

ipykernel/tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def start_new_kernel(**kwargs):
4040
stdout = nose.iptest_stdstreams_fileno()
4141
except AttributeError:
4242
stdout = open(os.devnull)
43-
kwargs.update(dict(stdout=stdout, stderr=STDOUT))
43+
# kwargs.update(dict(stdout=stdout, stderr=STDOUT))
4444
return manager.start_new_kernel(startup_timeout=STARTUP_TIMEOUT, **kwargs)
4545

4646
def flush_channels(kc=None):

0 commit comments

Comments
 (0)