Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

restore msg_id/msg_type aliases in top level of msg dict #754

Merged
merged 1 commit into from

2 participants

@minrk
Owner

msg_id/type must continue to be stored in the header, as only the header/parent/content are actually sent over the wire. But the msg_id and msg_type should remain as aliases in the top-level msg dict, for logical reasons and continued 0.11 compatibility.

Docs and tests updated to match.

Supercedes PR #753

@minrk minrk restore msg_id/msg_type aliases in top level of msg dict
msg_id/type must be stored in the header, as only the header/parent/content are actually sent over the wire.  But the msg_id and msg_type should remain as aliases in the top-level msg dict, for logic and 0.11 compatibility.

* docs and tests updated to match.
2e95bac
@ellisonbg
Owner

Looks good, I am going to merge.

@ellisonbg ellisonbg merged commit 7ff2814 into from
@ellisonbg ellisonbg referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 2, 2011
  1. @minrk

    restore msg_id/msg_type aliases in top level of msg dict

    minrk authored
    msg_id/type must be stored in the header, as only the header/parent/content are actually sent over the wire.  But the msg_id and msg_type should remain as aliases in the top-level msg dict, for logic and 0.11 compatibility.
    
    * docs and tests updated to match.
This page is out of date. Refresh to see the latest.
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.
Something went wrong with that request. Please try again.