Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #754 from minrk/msg_id

restore msg_id/msg_type aliases in top level of msg dict
  • Loading branch information...
commit 7ff2814e41de30797d1cc534435635453737d45e 2 parents 14867db + 2e95bac
@ellisonbg ellisonbg authored
View
10 IPython/zmq/session.py
@@ -357,7 +357,10 @@ def msg(self, msg_type, content=None, parent=None, subheader=None, header=None):
format, which is a list of message parts.
"""
msg = {}
- msg['header'] = self.msg_header(msg_type) if header is None else header
+ header = self.msg_header(msg_type) if header is None else header
+ msg['header'] = header
+ msg['msg_id'] = header['msg_id']
+ msg['msg_type'] = header['msg_type']
msg['parent_header'] = {} if parent is None else extract_header(parent)
msg['content'] = {} if content is None else content
sub = {} if subheader is None else subheader
@@ -669,7 +672,10 @@ def unserialize(self, msg_list, content=True, copy=True):
raise ValueError("Invalid Signature: %r"%signature)
if not len(msg_list) >= minlen:
raise TypeError("malformed message, must have at least %i elements"%minlen)
- message['header'] = self.unpack(msg_list[1])
+ header = self.unpack(msg_list[1])
+ message['header'] = header
+ message['msg_id'] = header['msg_id']
+ message['msg_type'] = header['msg_type']
message['parent_header'] = self.unpack(msg_list[2])
if content:
message['content'] = self.unpack(msg_list[3])
View
13 IPython/zmq/tests/test_session.py
@@ -47,13 +47,16 @@ class TestSession(SessionTestCase):
def test_msg(self):
"""message format"""
msg = self.session.msg('execute')
- thekeys = set('header parent_header content'.split())
+ thekeys = set('header parent_header content msg_type msg_id'.split())
s = set(msg.keys())
self.assertEquals(s, thekeys)
self.assertTrue(isinstance(msg['content'],dict))
self.assertTrue(isinstance(msg['header'],dict))
self.assertTrue(isinstance(msg['parent_header'],dict))
+ self.assertTrue(isinstance(msg['msg_id'],str))
+ self.assertTrue(isinstance(msg['msg_type'],str))
self.assertEquals(msg['header']['msg_type'], 'execute')
+ self.assertEquals(msg['msg_type'], 'execute')
def test_serialize(self):
msg = self.session.msg('execute',content=dict(a=10))
@@ -61,6 +64,8 @@ def test_serialize(self):
ident, msg_list = self.session.feed_identities(msg_list)
new_msg = self.session.unserialize(msg_list)
self.assertEquals(ident[0], b'foo')
+ self.assertEquals(new_msg['msg_id'],msg['msg_id'])
+ self.assertEquals(new_msg['msg_type'],msg['msg_type'])
self.assertEquals(new_msg['header'],msg['header'])
self.assertEquals(new_msg['content'],msg['content'])
self.assertEquals(new_msg['parent_header'],msg['parent_header'])
@@ -73,6 +78,8 @@ def test_send(self):
ident, msg_list = self.session.feed_identities(socket.data)
new_msg = self.session.unserialize(msg_list)
self.assertEquals(ident[0], b'foo')
+ self.assertEquals(new_msg['msg_id'],msg['msg_id'])
+ self.assertEquals(new_msg['msg_type'],msg['msg_type'])
self.assertEquals(new_msg['header'],msg['header'])
self.assertEquals(new_msg['content'],msg['content'])
self.assertEquals(new_msg['parent_header'],msg['parent_header'])
@@ -89,6 +96,8 @@ def test_send(self):
ident, msg_list = self.session.feed_identities(socket.data)
new_msg = self.session.unserialize(msg_list)
self.assertEquals(ident[0], b'foo')
+ self.assertEquals(new_msg['msg_id'],msg['msg_id'])
+ self.assertEquals(new_msg['msg_type'],msg['msg_type'])
self.assertEquals(new_msg['header'],msg['header'])
self.assertEquals(new_msg['content'],msg['content'])
self.assertEquals(new_msg['parent_header'],msg['parent_header'])
@@ -99,6 +108,8 @@ def test_send(self):
self.session.send(socket, msg, ident=b'foo', buffers=[b'bar'])
ident, new_msg = self.session.recv(socket)
self.assertEquals(ident[0], b'foo')
+ self.assertEquals(new_msg['msg_id'],msg['msg_id'])
+ self.assertEquals(new_msg['msg_type'],msg['msg_type'])
self.assertEquals(new_msg['header'],msg['header'])
self.assertEquals(new_msg['content'],msg['content'])
self.assertEquals(new_msg['parent_header'],msg['parent_header'])
View
4 docs/source/development/messaging.txt
@@ -108,6 +108,10 @@ generic structure::
# All recognized message type strings are listed below.
'msg_type' : str,
},
+ # The msg's unique identifier and type are stored in the header, but
+ # are also accessible at the top-level for convenience.
+ 'msg_id' : uuid,
+ 'msg_type' : str,
# In a chain of messages, the header from the parent is copied so that
# clients can track where messages come from.
Please sign in to comment.
Something went wrong with that request. Please try again.