Show More
@@ -351,7 +351,7 b' var IPython = (function (IPython) {' | |||
|
351 | 351 | var reply = $.parseJSON(e.data); |
|
352 | 352 | var content = reply.content; |
|
353 | 353 | var msg_type = reply.header.msg_type; |
|
354 |
var metadata = reply.metadata |
|
|
354 | var metadata = reply.metadata; | |
|
355 | 355 | var callbacks = this.get_callbacks_for_msg(reply.parent_header.msg_id); |
|
356 | 356 | if (msg_type !== 'status' && callbacks === undefined) { |
|
357 | 357 | // Message not from one of this notebook's cells and there are no |
@@ -421,11 +421,9 b' class Session(Configurable):' | |||
|
421 | 421 | msg['msg_type'] = header['msg_type'] |
|
422 | 422 | msg['parent_header'] = {} if parent is None else extract_header(parent) |
|
423 | 423 | msg['content'] = {} if content is None else content |
|
424 |
metadata |
|
|
424 | msg['metadata'] = self.metadata.copy() | |
|
425 | 425 | if metadata is not None: |
|
426 |
metadata |
|
|
427 | if metadata_dict: | |
|
428 | msg['metadata'] = metadata_dict | |
|
426 | msg['metadata'].update(metadata) | |
|
429 | 427 | return msg |
|
430 | 428 | |
|
431 | 429 | def sign(self, msg_list): |
@@ -459,7 +457,7 b' class Session(Configurable):' | |||
|
459 | 457 | ------- |
|
460 | 458 | msg_list : list |
|
461 | 459 | The list of bytes objects to be sent with the format: |
|
462 | [ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_content, | |
|
460 | [ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_metadata,p_content, | |
|
463 | 461 | buffer1,buffer2,...]. In this list, the p_* entities are |
|
464 | 462 | the packed or serialized versions, so if JSON is used, these |
|
465 | 463 | are utf8 encoded JSON strings. |
@@ -480,7 +478,8 b' class Session(Configurable):' | |||
|
480 | 478 | |
|
481 | 479 | real_message = [self.pack(msg['header']), |
|
482 | 480 | self.pack(msg['parent_header']), |
|
483 |
|
|
|
481 | self.pack(msg['metadata']), | |
|
482 | content, | |
|
484 | 483 | ] |
|
485 | 484 | |
|
486 | 485 | to_send = [] |
@@ -607,7 +606,7 b' class Session(Configurable):' | |||
|
607 | 606 | The ZMQ stream or socket to use for sending the message. |
|
608 | 607 | msg_list : list |
|
609 | 608 | The serialized list of messages to send. This only includes the |
|
610 | [p_header,p_parent,p_content,buffer1,buffer2,...] portion of | |
|
609 | [p_header,p_parent,p_metadata,p_content,buffer1,buffer2,...] portion of | |
|
611 | 610 | the message. |
|
612 | 611 | ident : ident or list |
|
613 | 612 | A single ident or a list of idents to use in sending. |
@@ -705,7 +704,7 b' class Session(Configurable):' | |||
|
705 | 704 | ----------- |
|
706 | 705 | msg_list : list of bytes or Message objects |
|
707 | 706 | The list of message parts of the form [HMAC,p_header,p_parent, |
|
708 | p_content,buffer1,buffer2,...]. | |
|
707 | p_metadata,p_content,buffer1,buffer2,...]. | |
|
709 | 708 | content : bool (True) |
|
710 | 709 | Whether to unpack the content dict (True), or leave it packed |
|
711 | 710 | (False). |
@@ -719,7 +718,7 b' class Session(Configurable):' | |||
|
719 | 718 | The nested message dict with top-level keys [header, parent_header, |
|
720 | 719 | content, buffers]. |
|
721 | 720 | """ |
|
722 |
minlen = |
|
|
721 | minlen = 5 | |
|
723 | 722 | message = {} |
|
724 | 723 | if not copy: |
|
725 | 724 | for i in range(minlen): |
@@ -741,12 +740,13 b' class Session(Configurable):' | |||
|
741 | 740 | message['msg_id'] = header['msg_id'] |
|
742 | 741 | message['msg_type'] = header['msg_type'] |
|
743 | 742 | message['parent_header'] = self.unpack(msg_list[2]) |
|
743 | message['metadata'] = self.unpack(msg_list[3]) | |
|
744 | 744 | if content: |
|
745 |
message['content'] = self.unpack(msg_list[ |
|
|
745 | message['content'] = self.unpack(msg_list[4]) | |
|
746 | 746 | else: |
|
747 |
message['content'] = msg_list[ |
|
|
747 | message['content'] = msg_list[4] | |
|
748 | 748 | |
|
749 |
message['buffers'] = msg_list[ |
|
|
749 | message['buffers'] = msg_list[5:] | |
|
750 | 750 | return message |
|
751 | 751 | |
|
752 | 752 | def test_msg2obj(): |
@@ -47,10 +47,11 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 msg_type msg_id'.split()) | |
|
50 | thekeys = set('header parent_header metadata content msg_type msg_id'.split()) | |
|
51 | 51 | s = set(msg.keys()) |
|
52 | 52 | self.assertEqual(s, thekeys) |
|
53 | 53 | self.assertTrue(isinstance(msg['content'],dict)) |
|
54 | self.assertTrue(isinstance(msg['metadata'],dict)) | |
|
54 | 55 | self.assertTrue(isinstance(msg['header'],dict)) |
|
55 | 56 | self.assertTrue(isinstance(msg['parent_header'],dict)) |
|
56 | 57 | self.assertTrue(isinstance(msg['msg_id'],str)) |
@@ -69,6 +70,7 b' class TestSession(SessionTestCase):' | |||
|
69 | 70 | self.assertEqual(new_msg['header'],msg['header']) |
|
70 | 71 | self.assertEqual(new_msg['content'],msg['content']) |
|
71 | 72 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
73 | self.assertEqual(new_msg['metadata'],msg['metadata']) | |
|
72 | 74 | # ensure floats don't come out as Decimal: |
|
73 | 75 | self.assertEqual(type(new_msg['content']['b']),type(new_msg['content']['b'])) |
|
74 | 76 | |
@@ -85,6 +87,7 b' class TestSession(SessionTestCase):' | |||
|
85 | 87 | self.assertEqual(new_msg['header'],msg['header']) |
|
86 | 88 | self.assertEqual(new_msg['content'],msg['content']) |
|
87 | 89 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
90 | self.assertEqual(new_msg['metadata'],msg['metadata']) | |
|
88 | 91 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
89 | 92 | |
|
90 | 93 | socket.data = [] |
@@ -92,9 +95,10 b' class TestSession(SessionTestCase):' | |||
|
92 | 95 | content = msg['content'] |
|
93 | 96 | header = msg['header'] |
|
94 | 97 | parent = msg['parent_header'] |
|
98 | metadata = msg['metadata'] | |
|
95 | 99 | msg_type = header['msg_type'] |
|
96 | 100 | self.session.send(socket, None, content=content, parent=parent, |
|
97 | header=header, ident=b'foo', buffers=[b'bar']) | |
|
101 | header=header, metadata=metadata, ident=b'foo', buffers=[b'bar']) | |
|
98 | 102 | ident, msg_list = self.session.feed_identities(socket.data) |
|
99 | 103 | new_msg = self.session.unserialize(msg_list) |
|
100 | 104 | self.assertEqual(ident[0], b'foo') |
@@ -102,6 +106,7 b' class TestSession(SessionTestCase):' | |||
|
102 | 106 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
|
103 | 107 | self.assertEqual(new_msg['header'],msg['header']) |
|
104 | 108 | self.assertEqual(new_msg['content'],msg['content']) |
|
109 | self.assertEqual(new_msg['metadata'],msg['metadata']) | |
|
105 | 110 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
106 | 111 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
107 | 112 | |
@@ -114,6 +119,7 b' class TestSession(SessionTestCase):' | |||
|
114 | 119 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
|
115 | 120 | self.assertEqual(new_msg['header'],msg['header']) |
|
116 | 121 | self.assertEqual(new_msg['content'],msg['content']) |
|
122 | self.assertEqual(new_msg['metadata'],msg['metadata']) | |
|
117 | 123 | self.assertEqual(new_msg['parent_header'],msg['parent_header']) |
|
118 | 124 | self.assertEqual(new_msg['buffers'],[b'bar']) |
|
119 | 125 |
@@ -106,7 +106,7 b' A message is defined by the following four-dictionary structure::' | |||
|
106 | 106 | # depends on the message type. |
|
107 | 107 | 'content' : dict, |
|
108 | 108 | |
|
109 |
# Any metadata associated with the message |
|
|
109 | # Any metadata associated with the message. | |
|
110 | 110 | 'metadata' : dict, |
|
111 | 111 | } |
|
112 | 112 | |
@@ -130,7 +130,7 b' messages upon deserialization to the following form for convenience::' | |||
|
130 | 130 | 'msg_type' : str, |
|
131 | 131 | 'parent_header' : dict, |
|
132 | 132 | 'content' : dict, |
|
133 |
'metadata' : dict, |
|
|
133 | 'metadata' : dict, | |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | All messages sent to or received by any IPython process should have this |
General Comments 0
You need to be logged in to leave comments.
Login now