Skip to content
This repository

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

Merged
merged 1 commit into from over 2 years ago

2 participants

Min RK Brian E. Granger
Min RK
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

Min RK 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
Brian E. Granger
Owner

Looks good, I am going to merge.

Brian E. Granger ellisonbg merged commit 7ff2814 into from September 06, 2011
Brian E. Granger ellisonbg closed this September 06, 2011
Brian E. Granger ellisonbg referenced this pull request from a commit January 10, 2012
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

Showing 1 unique commit by 1 author.

Sep 02, 2011
Min RK 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
This page is out of date. Refresh to see the latest.
10  IPython/zmq/session.py
@@ -357,7 +357,10 @@ def msg(self, msg_type, content=None, parent=None, subheader=None, header=None):
357 357
         format, which is a list of message parts.
358 358
         """
359 359
         msg = {}
360  
-        msg['header'] = self.msg_header(msg_type) if header is None else header
  360
+        header = self.msg_header(msg_type) if header is None else header
  361
+        msg['header'] = header
  362
+        msg['msg_id'] = header['msg_id']
  363
+        msg['msg_type'] = header['msg_type']
361 364
         msg['parent_header'] = {} if parent is None else extract_header(parent)
362 365
         msg['content'] = {} if content is None else content
363 366
         sub = {} if subheader is None else subheader
@@ -669,7 +672,10 @@ def unserialize(self, msg_list, content=True, copy=True):
669 672
                 raise ValueError("Invalid Signature: %r"%signature)
670 673
         if not len(msg_list) >= minlen:
671 674
             raise TypeError("malformed message, must have at least %i elements"%minlen)
672  
-        message['header'] = self.unpack(msg_list[1])
  675
+        header = self.unpack(msg_list[1])
  676
+        message['header'] = header
  677
+        message['msg_id'] = header['msg_id']
  678
+        message['msg_type'] = header['msg_type']
673 679
         message['parent_header'] = self.unpack(msg_list[2])
674 680
         if content:
675 681
             message['content'] = self.unpack(msg_list[3])
13  IPython/zmq/tests/test_session.py
@@ -47,13 +47,16 @@ class TestSession(SessionTestCase):
47 47
     def test_msg(self):
48 48
         """message format"""
49 49
         msg = self.session.msg('execute')
50  
-        thekeys = set('header parent_header content'.split())
  50
+        thekeys = set('header parent_header content msg_type msg_id'.split())
51 51
         s = set(msg.keys())
52 52
         self.assertEquals(s, thekeys)
53 53
         self.assertTrue(isinstance(msg['content'],dict))
54 54
         self.assertTrue(isinstance(msg['header'],dict))
55 55
         self.assertTrue(isinstance(msg['parent_header'],dict))
  56
+        self.assertTrue(isinstance(msg['msg_id'],str))
  57
+        self.assertTrue(isinstance(msg['msg_type'],str))
56 58
         self.assertEquals(msg['header']['msg_type'], 'execute')
  59
+        self.assertEquals(msg['msg_type'], 'execute')
57 60
 
58 61
     def test_serialize(self):
59 62
         msg = self.session.msg('execute',content=dict(a=10))
@@ -61,6 +64,8 @@ def test_serialize(self):
61 64
         ident, msg_list = self.session.feed_identities(msg_list)
62 65
         new_msg = self.session.unserialize(msg_list)
63 66
         self.assertEquals(ident[0], b'foo')
  67
+        self.assertEquals(new_msg['msg_id'],msg['msg_id'])
  68
+        self.assertEquals(new_msg['msg_type'],msg['msg_type'])
64 69
         self.assertEquals(new_msg['header'],msg['header'])
65 70
         self.assertEquals(new_msg['content'],msg['content'])
66 71
         self.assertEquals(new_msg['parent_header'],msg['parent_header'])
@@ -73,6 +78,8 @@ def test_send(self):
73 78
         ident, msg_list = self.session.feed_identities(socket.data)
74 79
         new_msg = self.session.unserialize(msg_list)
75 80
         self.assertEquals(ident[0], b'foo')
  81
+        self.assertEquals(new_msg['msg_id'],msg['msg_id'])
  82
+        self.assertEquals(new_msg['msg_type'],msg['msg_type'])
76 83
         self.assertEquals(new_msg['header'],msg['header'])
77 84
         self.assertEquals(new_msg['content'],msg['content'])
78 85
         self.assertEquals(new_msg['parent_header'],msg['parent_header'])        
@@ -89,6 +96,8 @@ def test_send(self):
89 96
         ident, msg_list = self.session.feed_identities(socket.data)
90 97
         new_msg = self.session.unserialize(msg_list)
91 98
         self.assertEquals(ident[0], b'foo')
  99
+        self.assertEquals(new_msg['msg_id'],msg['msg_id'])
  100
+        self.assertEquals(new_msg['msg_type'],msg['msg_type'])
92 101
         self.assertEquals(new_msg['header'],msg['header'])
93 102
         self.assertEquals(new_msg['content'],msg['content'])
94 103
         self.assertEquals(new_msg['parent_header'],msg['parent_header'])        
@@ -99,6 +108,8 @@ def test_send(self):
99 108
         self.session.send(socket, msg, ident=b'foo', buffers=[b'bar'])
100 109
         ident, new_msg = self.session.recv(socket)
101 110
         self.assertEquals(ident[0], b'foo')
  111
+        self.assertEquals(new_msg['msg_id'],msg['msg_id'])
  112
+        self.assertEquals(new_msg['msg_type'],msg['msg_type'])
102 113
         self.assertEquals(new_msg['header'],msg['header'])
103 114
         self.assertEquals(new_msg['content'],msg['content'])
104 115
         self.assertEquals(new_msg['parent_header'],msg['parent_header'])        
4  docs/source/development/messaging.txt
@@ -108,6 +108,10 @@ generic structure::
108 108
                     # All recognized message type strings are listed below.
109 109
                     'msg_type' : str,
110 110
          },
  111
+      # The msg's unique identifier and type are stored in the header, but
  112
+      # are also accessible at the top-level for convenience.
  113
+      'msg_id' : uuid,
  114
+      'msg_type' : str,
111 115
 
112 116
       # In a chain of messages, the header from the parent is copied so that
113 117
       # clients can track where messages come from.
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.