Show More
@@ -357,7 +357,10 b' class Session(Configurable):' | |||
|
357 | 357 | format, which is a list of message parts. |
|
358 | 358 | """ |
|
359 | 359 | msg = {} |
|
360 |
|
|
|
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 b' class Session(Configurable):' | |||
|
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 |
|
|
|
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]) |
@@ -47,13 +47,16 b' 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 b' class TestSession(SessionTestCase):' | |||
|
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 b' class TestSession(SessionTestCase):' | |||
|
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 b' class TestSession(SessionTestCase):' | |||
|
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 b' class TestSession(SessionTestCase):' | |||
|
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']) |
@@ -108,6 +108,10 b' 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. |
General Comments 0
You need to be logged in to leave comments.
Login now