Show More
@@ -58,8 +58,8 b' def serialize_binary_message(msg):' | |||||
58 | return b''.join(buffers) |
|
58 | return b''.join(buffers) | |
59 |
|
59 | |||
60 |
|
60 | |||
61 |
def |
|
61 | def deserialize_binary_message(bmsg): | |
62 |
""" |
|
62 | """deserialize a message from a binary blog | |
63 |
|
63 | |||
64 | Header: |
|
64 | Header: | |
65 |
|
65 | |||
@@ -133,13 +133,13 b' class ZMQStreamHandler(websocket.WebSocketHandler):' | |||||
133 | def _reserialize_reply(self, msg_list): |
|
133 | def _reserialize_reply(self, msg_list): | |
134 | """Reserialize a reply message using JSON. |
|
134 | """Reserialize a reply message using JSON. | |
135 |
|
135 | |||
136 |
This takes the msg list from the ZMQ socket, |
|
136 | This takes the msg list from the ZMQ socket, deserializes it using | |
137 | self.session and then serializes the result using JSON. This method |
|
137 | self.session and then serializes the result using JSON. This method | |
138 | should be used by self._on_zmq_reply to build messages that can |
|
138 | should be used by self._on_zmq_reply to build messages that can | |
139 | be sent back to the browser. |
|
139 | be sent back to the browser. | |
140 | """ |
|
140 | """ | |
141 | idents, msg_list = self.session.feed_identities(msg_list) |
|
141 | idents, msg_list = self.session.feed_identities(msg_list) | |
142 |
msg = self.session. |
|
142 | msg = self.session.deserialize(msg_list) | |
143 | try: |
|
143 | try: | |
144 | msg['header'].pop('date') |
|
144 | msg['header'].pop('date') | |
145 | except KeyError: |
|
145 | except KeyError: |
@@ -110,7 +110,7 b' class ZMQChannelHandler(AuthenticatedZMQStreamHandler):' | |||||
110 | """ |
|
110 | """ | |
111 | idents,msg = self.session.feed_identities(msg) |
|
111 | idents,msg = self.session.feed_identities(msg) | |
112 | try: |
|
112 | try: | |
113 |
msg = self.session. |
|
113 | msg = self.session.deserialize(msg) | |
114 | except: |
|
114 | except: | |
115 | self.log.error("Bad kernel_info reply", exc_info=True) |
|
115 | self.log.error("Bad kernel_info reply", exc_info=True) | |
116 | self._request_kernel_info() |
|
116 | self._request_kernel_info() |
@@ -846,8 +846,9 b' define([' | |||||
846 | } |
|
846 | } | |
847 | }; |
|
847 | }; | |
848 |
|
848 | |||
849 | Kernel.prototype._unserialize_binary_message = function(blob, callback) { |
|
849 | ||
850 | // unserialize the binary message format |
|
850 | Kernel.prototype._deserialize_binary_message = function(blob, callback) { | |
|
851 | // deserialize the binary message format | |||
851 | // callback will be called with a message whose buffers attribute |
|
852 | // callback will be called with a message whose buffers attribute | |
852 | // will be an array of DataViews. |
|
853 | // will be an array of DataViews. | |
853 | var reader = new FileReader(); |
|
854 | var reader = new FileReader(); | |
@@ -880,14 +881,14 b' define([' | |||||
880 | }; |
|
881 | }; | |
881 |
|
882 | |||
882 |
|
883 | |||
883 |
Kernel.prototype._ |
|
884 | Kernel.prototype._deserialize_msg = function (e, callback) { | |
884 |
// |
|
885 | // deserialze a message and pass the unpacked message object to callback | |
885 | if (typeof e.data === "string") { |
|
886 | if (typeof e.data === "string") { | |
886 | // text JSON message |
|
887 | // text JSON message | |
887 | callback($.parseJSON(e.data)); |
|
888 | callback($.parseJSON(e.data)); | |
888 | } else { |
|
889 | } else { | |
889 | // binary message |
|
890 | // binary message | |
890 |
this._ |
|
891 | this._deserialize_binary_message(e.data, callback); | |
891 | } |
|
892 | } | |
892 | }; |
|
893 | }; | |
893 |
|
894 | |||
@@ -895,7 +896,7 b' define([' | |||||
895 | * @function _handle_shell_reply |
|
896 | * @function _handle_shell_reply | |
896 | */ |
|
897 | */ | |
897 | Kernel.prototype._handle_shell_reply = function (e) { |
|
898 | Kernel.prototype._handle_shell_reply = function (e) { | |
898 |
this._ |
|
899 | this._deserialize_msg(e, $.proxy(this._finish_shell_reply, this)); | |
899 | }; |
|
900 | }; | |
900 |
|
901 | |||
901 | Kernel.prototype._finish_shell_reply = function (reply) { |
|
902 | Kernel.prototype._finish_shell_reply = function (reply) { | |
@@ -1026,7 +1027,7 b' define([' | |||||
1026 | * @function _handle_iopub_message |
|
1027 | * @function _handle_iopub_message | |
1027 | */ |
|
1028 | */ | |
1028 | Kernel.prototype._handle_iopub_message = function (e) { |
|
1029 | Kernel.prototype._handle_iopub_message = function (e) { | |
1029 |
this._ |
|
1030 | this._deserialize_msg(e, $.proxy(this._finish_iopub_message, this)); | |
1030 | }; |
|
1031 | }; | |
1031 |
|
1032 | |||
1032 |
|
1033 | |||
@@ -1041,7 +1042,7 b' define([' | |||||
1041 | * @function _handle_input_request |
|
1042 | * @function _handle_input_request | |
1042 | */ |
|
1043 | */ | |
1043 | Kernel.prototype._handle_input_request = function (e) { |
|
1044 | Kernel.prototype._handle_input_request = function (e) { | |
1044 |
this._ |
|
1045 | this._deserialize_msg(e, $.proxy(this._finish_input_request, this)); | |
1045 | }; |
|
1046 | }; | |
1046 |
|
1047 | |||
1047 |
|
1048 |
@@ -176,7 +176,7 b' class ZMQSocketChannel(Thread):' | |||||
176 | Unpacks message, and calls handlers with it. |
|
176 | Unpacks message, and calls handlers with it. | |
177 | """ |
|
177 | """ | |
178 | ident,smsg = self.session.feed_identities(msg) |
|
178 | ident,smsg = self.session.feed_identities(msg) | |
179 |
msg = self.session. |
|
179 | msg = self.session.deserialize(smsg) | |
180 | self.call_handlers(msg) |
|
180 | self.call_handlers(msg) | |
181 |
|
181 | |||
182 |
|
182 |
@@ -130,7 +130,7 b' class Kernel(SingletonConfigurable):' | |||||
130 | """dispatch control requests""" |
|
130 | """dispatch control requests""" | |
131 | idents,msg = self.session.feed_identities(msg, copy=False) |
|
131 | idents,msg = self.session.feed_identities(msg, copy=False) | |
132 | try: |
|
132 | try: | |
133 |
msg = self.session. |
|
133 | msg = self.session.deserialize(msg, content=True, copy=False) | |
134 | except: |
|
134 | except: | |
135 | self.log.error("Invalid Control Message", exc_info=True) |
|
135 | self.log.error("Invalid Control Message", exc_info=True) | |
136 | return |
|
136 | return | |
@@ -165,7 +165,7 b' class Kernel(SingletonConfigurable):' | |||||
165 |
|
165 | |||
166 | idents,msg = self.session.feed_identities(msg, copy=False) |
|
166 | idents,msg = self.session.feed_identities(msg, copy=False) | |
167 | try: |
|
167 | try: | |
168 |
msg = self.session. |
|
168 | msg = self.session.deserialize(msg, content=True, copy=False) | |
169 | except: |
|
169 | except: | |
170 | self.log.error("Invalid Message", exc_info=True) |
|
170 | self.log.error("Invalid Message", exc_info=True) | |
171 | return |
|
171 | return |
@@ -89,7 +89,7 b' def serialize_object(obj, buffer_threshold=MAX_BYTES, item_threshold=MAX_ITEMS):' | |||||
89 | buffers.insert(0, pickle.dumps(cobj, PICKLE_PROTOCOL)) |
|
89 | buffers.insert(0, pickle.dumps(cobj, PICKLE_PROTOCOL)) | |
90 | return buffers |
|
90 | return buffers | |
91 |
|
91 | |||
92 |
def |
|
92 | def deserialize_object(buffers, g=None): | |
93 | """reconstruct an object serialized by serialize_object from data buffers. |
|
93 | """reconstruct an object serialized by serialize_object from data buffers. | |
94 |
|
94 | |||
95 | Parameters |
|
95 | Parameters | |
@@ -170,14 +170,14 b' def unpack_apply_message(bufs, g=None, copy=True):' | |||||
170 |
|
170 | |||
171 | args = [] |
|
171 | args = [] | |
172 | for i in range(info['nargs']): |
|
172 | for i in range(info['nargs']): | |
173 |
arg, arg_bufs = |
|
173 | arg, arg_bufs = deserialize_object(arg_bufs, g) | |
174 | args.append(arg) |
|
174 | args.append(arg) | |
175 | args = tuple(args) |
|
175 | args = tuple(args) | |
176 | assert not arg_bufs, "Shouldn't be any arg bufs left over" |
|
176 | assert not arg_bufs, "Shouldn't be any arg bufs left over" | |
177 |
|
177 | |||
178 | kwargs = {} |
|
178 | kwargs = {} | |
179 | for key in info['kw_keys']: |
|
179 | for key in info['kw_keys']: | |
180 |
kwarg, kwarg_bufs = |
|
180 | kwarg, kwarg_bufs = deserialize_object(kwarg_bufs, g) | |
181 | kwargs[key] = kwarg |
|
181 | kwargs[key] = kwarg | |
182 | assert not kwarg_bufs, "Shouldn't be any kwarg bufs left over" |
|
182 | assert not kwarg_bufs, "Shouldn't be any kwarg bufs left over" | |
183 |
|
183 |
@@ -18,6 +18,7 b' import os' | |||||
18 | import pprint |
|
18 | import pprint | |
19 | import random |
|
19 | import random | |
20 | import uuid |
|
20 | import uuid | |
|
21 | import warnings | |||
21 | from datetime import datetime |
|
22 | from datetime import datetime | |
22 |
|
23 | |||
23 | try: |
|
24 | try: | |
@@ -492,7 +493,7 b' class Session(Configurable):' | |||||
492 | """Return the nested message dict. |
|
493 | """Return the nested message dict. | |
493 |
|
494 | |||
494 | This format is different from what is sent over the wire. The |
|
495 | This format is different from what is sent over the wire. The | |
495 |
serialize/ |
|
496 | serialize/deserialize methods converts this nested message dict to the wire | |
496 | format, which is a list of message parts. |
|
497 | format, which is a list of message parts. | |
497 | """ |
|
498 | """ | |
498 | msg = {} |
|
499 | msg = {} | |
@@ -525,7 +526,7 b' class Session(Configurable):' | |||||
525 | def serialize(self, msg, ident=None): |
|
526 | def serialize(self, msg, ident=None): | |
526 | """Serialize the message components to bytes. |
|
527 | """Serialize the message components to bytes. | |
527 |
|
528 | |||
528 |
This is roughly the inverse of |
|
529 | This is roughly the inverse of deserialize. The serialize/deserialize | |
529 | methods work with full message lists, whereas pack/unpack work with |
|
530 | methods work with full message lists, whereas pack/unpack work with | |
530 | the individual message parts in the message list. |
|
531 | the individual message parts in the message list. | |
531 |
|
532 | |||
@@ -590,7 +591,7 b' class Session(Configurable):' | |||||
590 | [ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_content, |
|
591 | [ident1,ident2,...,DELIM,HMAC,p_header,p_parent,p_content, | |
591 | buffer1,buffer2,...] |
|
592 | buffer1,buffer2,...] | |
592 |
|
593 | |||
593 |
The serialize/ |
|
594 | The serialize/deserialize methods convert the nested message dict into this | |
594 | format. |
|
595 | format. | |
595 |
|
596 | |||
596 | Parameters |
|
597 | Parameters | |
@@ -722,7 +723,7 b' class Session(Configurable):' | |||||
722 | # invalid large messages can cause very expensive string comparisons |
|
723 | # invalid large messages can cause very expensive string comparisons | |
723 | idents, msg_list = self.feed_identities(msg_list, copy) |
|
724 | idents, msg_list = self.feed_identities(msg_list, copy) | |
724 | try: |
|
725 | try: | |
725 |
return idents, self. |
|
726 | return idents, self.deserialize(msg_list, content=content, copy=copy) | |
726 | except Exception as e: |
|
727 | except Exception as e: | |
727 | # TODO: handle it |
|
728 | # TODO: handle it | |
728 | raise e |
|
729 | raise e | |
@@ -747,7 +748,7 b' class Session(Configurable):' | |||||
747 | idents will always be a list of bytes, each of which is a ZMQ |
|
748 | idents will always be a list of bytes, each of which is a ZMQ | |
748 | identity. msg_list will be a list of bytes or zmq.Messages of the |
|
749 | identity. msg_list will be a list of bytes or zmq.Messages of the | |
749 | form [HMAC,p_header,p_parent,p_content,buffer1,buffer2,...] and |
|
750 | form [HMAC,p_header,p_parent,p_content,buffer1,buffer2,...] and | |
750 |
should be unpackable/unserializable via self. |
|
751 | should be unpackable/unserializable via self.deserialize at this | |
751 | point. |
|
752 | point. | |
752 | """ |
|
753 | """ | |
753 | if copy: |
|
754 | if copy: | |
@@ -788,10 +789,10 b' class Session(Configurable):' | |||||
788 | to_cull = random.sample(self.digest_history, n_to_cull) |
|
789 | to_cull = random.sample(self.digest_history, n_to_cull) | |
789 | self.digest_history.difference_update(to_cull) |
|
790 | self.digest_history.difference_update(to_cull) | |
790 |
|
791 | |||
791 |
def |
|
792 | def deserialize(self, msg_list, content=True, copy=True): | |
792 | """Unserialize a msg_list to a nested message dict. |
|
793 | """Unserialize a msg_list to a nested message dict. | |
793 |
|
794 | |||
794 |
This is roughly the inverse of serialize. The serialize/ |
|
795 | This is roughly the inverse of serialize. The serialize/deserialize | |
795 | methods work with full message lists, whereas pack/unpack work with |
|
796 | methods work with full message lists, whereas pack/unpack work with | |
796 | the individual message parts in the message list. |
|
797 | the individual message parts in the message list. | |
797 |
|
798 | |||
@@ -842,10 +843,16 b' class Session(Configurable):' | |||||
842 | message['content'] = msg_list[4] |
|
843 | message['content'] = msg_list[4] | |
843 |
|
844 | |||
844 | message['buffers'] = msg_list[5:] |
|
845 | message['buffers'] = msg_list[5:] | |
845 | # print("received: %s: %s\n %s" % (message['msg_type'], message['header'], message['content'])) |
|
|||
846 | # adapt to the current version |
|
846 | # adapt to the current version | |
847 | return adapt(message) |
|
847 | return adapt(message) | |
848 | # print("adapted: %s: %s\n %s" % (adapted['msg_type'], adapted['header'], adapted['content'])) |
|
848 | ||
|
849 | def unserialize(self, *args, **kwargs): | |||
|
850 | warnings.warn( | |||
|
851 | "Session.unserialize is deprecated. Use Session.deserialize.", | |||
|
852 | DeprecationWarning, | |||
|
853 | ) | |||
|
854 | return self.deserialize(*args, **kwargs) | |||
|
855 | ||||
849 |
|
856 | |||
850 | def test_msg2obj(): |
|
857 | def test_msg2obj(): | |
851 | am = dict(x=1) |
|
858 | am = dict(x=1) |
@@ -9,7 +9,7 b' from collections import namedtuple' | |||||
9 | import nose.tools as nt |
|
9 | import nose.tools as nt | |
10 |
|
10 | |||
11 | # from unittest import TestCaes |
|
11 | # from unittest import TestCaes | |
12 |
from IPython.kernel.zmq.serialize import serialize_object, |
|
12 | from IPython.kernel.zmq.serialize import serialize_object, deserialize_object | |
13 | from IPython.testing import decorators as dec |
|
13 | from IPython.testing import decorators as dec | |
14 | from IPython.utils.pickleutil import CannedArray, CannedClass |
|
14 | from IPython.utils.pickleutil import CannedArray, CannedClass | |
15 | from IPython.utils.py3compat import iteritems |
|
15 | from IPython.utils.py3compat import iteritems | |
@@ -22,7 +22,7 b' from IPython.parallel import interactive' | |||||
22 | def roundtrip(obj): |
|
22 | def roundtrip(obj): | |
23 | """roundtrip an object through serialization""" |
|
23 | """roundtrip an object through serialization""" | |
24 | bufs = serialize_object(obj) |
|
24 | bufs = serialize_object(obj) | |
25 |
obj2, remainder = |
|
25 | obj2, remainder = deserialize_object(bufs) | |
26 | nt.assert_equals(remainder, []) |
|
26 | nt.assert_equals(remainder, []) | |
27 | return obj2 |
|
27 | return obj2 | |
28 |
|
28 | |||
@@ -70,7 +70,7 b' def test_roundtrip_buffered():' | |||||
70 | ]: |
|
70 | ]: | |
71 | bufs = serialize_object(obj) |
|
71 | bufs = serialize_object(obj) | |
72 | nt.assert_equal(len(bufs), 2) |
|
72 | nt.assert_equal(len(bufs), 2) | |
73 |
obj2, remainder = |
|
73 | obj2, remainder = deserialize_object(bufs) | |
74 | nt.assert_equal(remainder, []) |
|
74 | nt.assert_equal(remainder, []) | |
75 | nt.assert_equal(obj, obj2) |
|
75 | nt.assert_equal(obj, obj2) | |
76 |
|
76 | |||
@@ -82,7 +82,7 b' def test_numpy():' | |||||
82 | for dtype in DTYPES: |
|
82 | for dtype in DTYPES: | |
83 | A = new_array(shape, dtype=dtype) |
|
83 | A = new_array(shape, dtype=dtype) | |
84 | bufs = serialize_object(A) |
|
84 | bufs = serialize_object(A) | |
85 |
B, r = |
|
85 | B, r = deserialize_object(bufs) | |
86 | nt.assert_equal(r, []) |
|
86 | nt.assert_equal(r, []) | |
87 | nt.assert_equal(A.shape, B.shape) |
|
87 | nt.assert_equal(A.shape, B.shape) | |
88 | nt.assert_equal(A.dtype, B.dtype) |
|
88 | nt.assert_equal(A.dtype, B.dtype) | |
@@ -100,7 +100,7 b' def test_recarray():' | |||||
100 | A = new_array(shape, dtype=dtype) |
|
100 | A = new_array(shape, dtype=dtype) | |
101 |
|
101 | |||
102 | bufs = serialize_object(A) |
|
102 | bufs = serialize_object(A) | |
103 |
B, r = |
|
103 | B, r = deserialize_object(bufs) | |
104 | nt.assert_equal(r, []) |
|
104 | nt.assert_equal(r, []) | |
105 | nt.assert_equal(A.shape, B.shape) |
|
105 | nt.assert_equal(A.shape, B.shape) | |
106 | nt.assert_equal(A.dtype, B.dtype) |
|
106 | nt.assert_equal(A.dtype, B.dtype) | |
@@ -116,7 +116,7 b' def test_numpy_in_seq():' | |||||
116 | bufs = serialize_object((A,1,2,b'hello')) |
|
116 | bufs = serialize_object((A,1,2,b'hello')) | |
117 | canned = pickle.loads(bufs[0]) |
|
117 | canned = pickle.loads(bufs[0]) | |
118 | nt.assert_is_instance(canned[0], CannedArray) |
|
118 | nt.assert_is_instance(canned[0], CannedArray) | |
119 |
tup, r = |
|
119 | tup, r = deserialize_object(bufs) | |
120 | B = tup[0] |
|
120 | B = tup[0] | |
121 | nt.assert_equal(r, []) |
|
121 | nt.assert_equal(r, []) | |
122 | nt.assert_equal(A.shape, B.shape) |
|
122 | nt.assert_equal(A.shape, B.shape) | |
@@ -133,7 +133,7 b' def test_numpy_in_dict():' | |||||
133 | bufs = serialize_object(dict(a=A,b=1,c=range(20))) |
|
133 | bufs = serialize_object(dict(a=A,b=1,c=range(20))) | |
134 | canned = pickle.loads(bufs[0]) |
|
134 | canned = pickle.loads(bufs[0]) | |
135 | nt.assert_is_instance(canned['a'], CannedArray) |
|
135 | nt.assert_is_instance(canned['a'], CannedArray) | |
136 |
d, r = |
|
136 | d, r = deserialize_object(bufs) | |
137 | B = d['a'] |
|
137 | B = d['a'] | |
138 | nt.assert_equal(r, []) |
|
138 | nt.assert_equal(r, []) | |
139 | nt.assert_equal(A.shape, B.shape) |
|
139 | nt.assert_equal(A.shape, B.shape) | |
@@ -147,7 +147,7 b' def test_class():' | |||||
147 | bufs = serialize_object(dict(C=C)) |
|
147 | bufs = serialize_object(dict(C=C)) | |
148 | canned = pickle.loads(bufs[0]) |
|
148 | canned = pickle.loads(bufs[0]) | |
149 | nt.assert_is_instance(canned['C'], CannedClass) |
|
149 | nt.assert_is_instance(canned['C'], CannedClass) | |
150 |
d, r = |
|
150 | d, r = deserialize_object(bufs) | |
151 | C2 = d['C'] |
|
151 | C2 = d['C'] | |
152 | nt.assert_equal(C2.a, C.a) |
|
152 | nt.assert_equal(C2.a, C.a) | |
153 |
|
153 | |||
@@ -159,7 +159,7 b' def test_class_oldstyle():' | |||||
159 | bufs = serialize_object(dict(C=C)) |
|
159 | bufs = serialize_object(dict(C=C)) | |
160 | canned = pickle.loads(bufs[0]) |
|
160 | canned = pickle.loads(bufs[0]) | |
161 | nt.assert_is_instance(canned['C'], CannedClass) |
|
161 | nt.assert_is_instance(canned['C'], CannedClass) | |
162 |
d, r = |
|
162 | d, r = deserialize_object(bufs) | |
163 | C2 = d['C'] |
|
163 | C2 = d['C'] | |
164 | nt.assert_equal(C2.a, C.a) |
|
164 | nt.assert_equal(C2.a, C.a) | |
165 |
|
165 | |||
@@ -168,7 +168,7 b' def test_tuple():' | |||||
168 | bufs = serialize_object(tup) |
|
168 | bufs = serialize_object(tup) | |
169 | canned = pickle.loads(bufs[0]) |
|
169 | canned = pickle.loads(bufs[0]) | |
170 | nt.assert_is_instance(canned, tuple) |
|
170 | nt.assert_is_instance(canned, tuple) | |
171 |
t2, r = |
|
171 | t2, r = deserialize_object(bufs) | |
172 | nt.assert_equal(t2[0](t2[1]), tup[0](tup[1])) |
|
172 | nt.assert_equal(t2[0](t2[1]), tup[0](tup[1])) | |
173 |
|
173 | |||
174 | point = namedtuple('point', 'x y') |
|
174 | point = namedtuple('point', 'x y') | |
@@ -178,7 +178,7 b' def test_namedtuple():' | |||||
178 | bufs = serialize_object(p) |
|
178 | bufs = serialize_object(p) | |
179 | canned = pickle.loads(bufs[0]) |
|
179 | canned = pickle.loads(bufs[0]) | |
180 | nt.assert_is_instance(canned, point) |
|
180 | nt.assert_is_instance(canned, point) | |
181 |
p2, r = |
|
181 | p2, r = deserialize_object(bufs, globals()) | |
182 | nt.assert_equal(p2.x, p.x) |
|
182 | nt.assert_equal(p2.x, p.x) | |
183 | nt.assert_equal(p2.y, p.y) |
|
183 | nt.assert_equal(p2.y, p.y) | |
184 |
|
184 | |||
@@ -187,7 +187,7 b' def test_list():' | |||||
187 | bufs = serialize_object(lis) |
|
187 | bufs = serialize_object(lis) | |
188 | canned = pickle.loads(bufs[0]) |
|
188 | canned = pickle.loads(bufs[0]) | |
189 | nt.assert_is_instance(canned, list) |
|
189 | nt.assert_is_instance(canned, list) | |
190 |
l2, r = |
|
190 | l2, r = deserialize_object(bufs) | |
191 | nt.assert_equal(l2[0](l2[1]), lis[0](lis[1])) |
|
191 | nt.assert_equal(l2[0](l2[1]), lis[0](lis[1])) | |
192 |
|
192 | |||
193 | def test_class_inheritance(): |
|
193 | def test_class_inheritance(): | |
@@ -202,7 +202,7 b' def test_class_inheritance():' | |||||
202 | bufs = serialize_object(dict(D=D)) |
|
202 | bufs = serialize_object(dict(D=D)) | |
203 | canned = pickle.loads(bufs[0]) |
|
203 | canned = pickle.loads(bufs[0]) | |
204 | nt.assert_is_instance(canned['D'], CannedClass) |
|
204 | nt.assert_is_instance(canned['D'], CannedClass) | |
205 |
d, r = |
|
205 | d, r = deserialize_object(bufs) | |
206 | D2 = d['D'] |
|
206 | D2 = d['D'] | |
207 | nt.assert_equal(D2.a, D.a) |
|
207 | nt.assert_equal(D2.a, D.a) | |
208 | nt.assert_equal(D2.b, D.b) |
|
208 | nt.assert_equal(D2.b, D.b) |
@@ -60,7 +60,7 b' class TestSession(SessionTestCase):' | |||||
60 | msg = self.session.msg('execute', content=dict(a=10, b=1.1)) |
|
60 | msg = self.session.msg('execute', content=dict(a=10, b=1.1)) | |
61 | msg_list = self.session.serialize(msg, ident=b'foo') |
|
61 | msg_list = self.session.serialize(msg, ident=b'foo') | |
62 | ident, msg_list = self.session.feed_identities(msg_list) |
|
62 | ident, msg_list = self.session.feed_identities(msg_list) | |
63 |
new_msg = self.session. |
|
63 | new_msg = self.session.deserialize(msg_list) | |
64 | self.assertEqual(ident[0], b'foo') |
|
64 | self.assertEqual(ident[0], b'foo') | |
65 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
|
65 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) | |
66 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
|
66 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) | |
@@ -82,7 +82,7 b' class TestSession(SessionTestCase):' | |||||
82 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) |
|
82 | self.session.send(A, msg, ident=b'foo', buffers=[b'bar']) | |
83 |
|
83 | |||
84 | ident, msg_list = self.session.feed_identities(B.recv_multipart()) |
|
84 | ident, msg_list = self.session.feed_identities(B.recv_multipart()) | |
85 |
new_msg = self.session. |
|
85 | new_msg = self.session.deserialize(msg_list) | |
86 | self.assertEqual(ident[0], b'foo') |
|
86 | self.assertEqual(ident[0], b'foo') | |
87 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
|
87 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) | |
88 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
|
88 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) | |
@@ -100,7 +100,7 b' class TestSession(SessionTestCase):' | |||||
100 | self.session.send(A, None, content=content, parent=parent, |
|
100 | self.session.send(A, None, content=content, parent=parent, | |
101 | header=header, metadata=metadata, ident=b'foo', buffers=[b'bar']) |
|
101 | header=header, metadata=metadata, ident=b'foo', buffers=[b'bar']) | |
102 | ident, msg_list = self.session.feed_identities(B.recv_multipart()) |
|
102 | ident, msg_list = self.session.feed_identities(B.recv_multipart()) | |
103 |
new_msg = self.session. |
|
103 | new_msg = self.session.deserialize(msg_list) | |
104 | self.assertEqual(ident[0], b'foo') |
|
104 | self.assertEqual(ident[0], b'foo') | |
105 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) |
|
105 | self.assertEqual(new_msg['msg_id'],msg['msg_id']) | |
106 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
|
106 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) | |
@@ -263,7 +263,7 b' class TestSession(SessionTestCase):' | |||||
263 | p = session.msg('msg') |
|
263 | p = session.msg('msg') | |
264 | msg = session.msg('msg', content=content, metadata=metadata, parent=p['header']) |
|
264 | msg = session.msg('msg', content=content, metadata=metadata, parent=p['header']) | |
265 | smsg = session.serialize(msg) |
|
265 | smsg = session.serialize(msg) | |
266 |
msg2 = session. |
|
266 | msg2 = session.deserialize(session.feed_identities(smsg)[1]) | |
267 | assert isinstance(msg2['header']['date'], datetime) |
|
267 | assert isinstance(msg2['header']['date'], datetime) | |
268 | self.assertEqual(msg['header'], msg2['header']) |
|
268 | self.assertEqual(msg['header'], msg2['header']) | |
269 | self.assertEqual(msg['parent_header'], msg2['parent_header']) |
|
269 | self.assertEqual(msg['parent_header'], msg2['parent_header']) | |
@@ -305,7 +305,7 b' class TestSession(SessionTestCase):' | |||||
305 | self.session.send_raw(A, msg_list, ident=b'foo') |
|
305 | self.session.send_raw(A, msg_list, ident=b'foo') | |
306 |
|
306 | |||
307 | ident, new_msg_list = self.session.feed_identities(B.recv_multipart()) |
|
307 | ident, new_msg_list = self.session.feed_identities(B.recv_multipart()) | |
308 |
new_msg = self.session. |
|
308 | new_msg = self.session.deserialize(new_msg_list) | |
309 | self.assertEqual(ident[0], b'foo') |
|
309 | self.assertEqual(ident[0], b'foo') | |
310 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) |
|
310 | self.assertEqual(new_msg['msg_type'],msg['msg_type']) | |
311 | self.assertEqual(new_msg['header'],msg['header']) |
|
311 | self.assertEqual(new_msg['header'],msg['header']) |
@@ -782,7 +782,7 b' class Client(HasTraits):' | |||||
782 |
|
782 | |||
783 | # construct result: |
|
783 | # construct result: | |
784 | if content['status'] == 'ok': |
|
784 | if content['status'] == 'ok': | |
785 |
self.results[msg_id] = serialize. |
|
785 | self.results[msg_id] = serialize.deserialize_object(msg['buffers'])[0] | |
786 | elif content['status'] == 'aborted': |
|
786 | elif content['status'] == 'aborted': | |
787 | self.results[msg_id] = error.TaskAborted(msg_id) |
|
787 | self.results[msg_id] = error.TaskAborted(msg_id) | |
788 | elif content['status'] == 'resubmitted': |
|
788 | elif content['status'] == 'resubmitted': | |
@@ -884,7 +884,7 b' class Client(HasTraits):' | |||||
884 | elif msg_type == 'execute_result': |
|
884 | elif msg_type == 'execute_result': | |
885 | md['execute_result'] = content |
|
885 | md['execute_result'] = content | |
886 | elif msg_type == 'data_message': |
|
886 | elif msg_type == 'data_message': | |
887 |
data, remainder = serialize. |
|
887 | data, remainder = serialize.deserialize_object(msg['buffers']) | |
888 | md['data'].update(data) |
|
888 | md['data'].update(data) | |
889 | elif msg_type == 'status': |
|
889 | elif msg_type == 'status': | |
890 | # idle message comes after all outputs |
|
890 | # idle message comes after all outputs | |
@@ -1593,7 +1593,7 b' class Client(HasTraits):' | |||||
1593 |
|
1593 | |||
1594 | if rcontent['status'] == 'ok': |
|
1594 | if rcontent['status'] == 'ok': | |
1595 | if header['msg_type'] == 'apply_reply': |
|
1595 | if header['msg_type'] == 'apply_reply': | |
1596 |
res,buffers = serialize. |
|
1596 | res,buffers = serialize.deserialize_object(buffers) | |
1597 | elif header['msg_type'] == 'execute_reply': |
|
1597 | elif header['msg_type'] == 'execute_reply': | |
1598 | res = ExecuteReply(msg_id, rcontent, md) |
|
1598 | res = ExecuteReply(msg_id, rcontent, md) | |
1599 | else: |
|
1599 | else: |
@@ -523,7 +523,7 b' class Hub(SessionFactory):' | |||||
523 | return |
|
523 | return | |
524 | client_id = idents[0] |
|
524 | client_id = idents[0] | |
525 | try: |
|
525 | try: | |
526 |
msg = self.session. |
|
526 | msg = self.session.deserialize(msg, content=True) | |
527 | except Exception: |
|
527 | except Exception: | |
528 | content = error.wrap_exception() |
|
528 | content = error.wrap_exception() | |
529 | self.log.error("Bad Query Message: %r", msg, exc_info=True) |
|
529 | self.log.error("Bad Query Message: %r", msg, exc_info=True) | |
@@ -588,7 +588,7 b' class Hub(SessionFactory):' | |||||
588 | return |
|
588 | return | |
589 | queue_id, client_id = idents[:2] |
|
589 | queue_id, client_id = idents[:2] | |
590 | try: |
|
590 | try: | |
591 |
msg = self.session. |
|
591 | msg = self.session.deserialize(msg) | |
592 | except Exception: |
|
592 | except Exception: | |
593 | self.log.error("queue::client %r sent invalid message to %r: %r", client_id, queue_id, msg, exc_info=True) |
|
593 | self.log.error("queue::client %r sent invalid message to %r: %r", client_id, queue_id, msg, exc_info=True) | |
594 | return |
|
594 | return | |
@@ -636,7 +636,7 b' class Hub(SessionFactory):' | |||||
636 |
|
636 | |||
637 | client_id, queue_id = idents[:2] |
|
637 | client_id, queue_id = idents[:2] | |
638 | try: |
|
638 | try: | |
639 |
msg = self.session. |
|
639 | msg = self.session.deserialize(msg) | |
640 | except Exception: |
|
640 | except Exception: | |
641 | self.log.error("queue::engine %r sent invalid message to %r: %r", |
|
641 | self.log.error("queue::engine %r sent invalid message to %r: %r", | |
642 | queue_id, client_id, msg, exc_info=True) |
|
642 | queue_id, client_id, msg, exc_info=True) | |
@@ -690,7 +690,7 b' class Hub(SessionFactory):' | |||||
690 | client_id = idents[0] |
|
690 | client_id = idents[0] | |
691 |
|
691 | |||
692 | try: |
|
692 | try: | |
693 |
msg = self.session. |
|
693 | msg = self.session.deserialize(msg) | |
694 | except Exception: |
|
694 | except Exception: | |
695 | self.log.error("task::client %r sent invalid task message: %r", |
|
695 | self.log.error("task::client %r sent invalid task message: %r", | |
696 | client_id, msg, exc_info=True) |
|
696 | client_id, msg, exc_info=True) | |
@@ -740,7 +740,7 b' class Hub(SessionFactory):' | |||||
740 | """save the result of a completed task.""" |
|
740 | """save the result of a completed task.""" | |
741 | client_id = idents[0] |
|
741 | client_id = idents[0] | |
742 | try: |
|
742 | try: | |
743 |
msg = self.session. |
|
743 | msg = self.session.deserialize(msg) | |
744 | except Exception: |
|
744 | except Exception: | |
745 | self.log.error("task::invalid task result message send to %r: %r", |
|
745 | self.log.error("task::invalid task result message send to %r: %r", | |
746 | client_id, msg, exc_info=True) |
|
746 | client_id, msg, exc_info=True) | |
@@ -794,7 +794,7 b' class Hub(SessionFactory):' | |||||
794 |
|
794 | |||
795 | def save_task_destination(self, idents, msg): |
|
795 | def save_task_destination(self, idents, msg): | |
796 | try: |
|
796 | try: | |
797 |
msg = self.session. |
|
797 | msg = self.session.deserialize(msg, content=True) | |
798 | except Exception: |
|
798 | except Exception: | |
799 | self.log.error("task::invalid task tracking message", exc_info=True) |
|
799 | self.log.error("task::invalid task tracking message", exc_info=True) | |
800 | return |
|
800 | return | |
@@ -831,7 +831,7 b' class Hub(SessionFactory):' | |||||
831 | """save an iopub message into the db""" |
|
831 | """save an iopub message into the db""" | |
832 | # print (topics) |
|
832 | # print (topics) | |
833 | try: |
|
833 | try: | |
834 |
msg = self.session. |
|
834 | msg = self.session.deserialize(msg, content=True) | |
835 | except Exception: |
|
835 | except Exception: | |
836 | self.log.error("iopub::invalid IOPub message", exc_info=True) |
|
836 | self.log.error("iopub::invalid IOPub message", exc_info=True) | |
837 | return |
|
837 | return |
@@ -251,7 +251,7 b' class TaskScheduler(SessionFactory):' | |||||
251 | self.log.warn("task::Invalid Message: %r",msg) |
|
251 | self.log.warn("task::Invalid Message: %r",msg) | |
252 | return |
|
252 | return | |
253 | try: |
|
253 | try: | |
254 |
msg = self.session. |
|
254 | msg = self.session.deserialize(msg) | |
255 | except ValueError: |
|
255 | except ValueError: | |
256 | self.log.warn("task::Unauthorized message from: %r"%idents) |
|
256 | self.log.warn("task::Unauthorized message from: %r"%idents) | |
257 | return |
|
257 | return | |
@@ -270,7 +270,7 b' class TaskScheduler(SessionFactory):' | |||||
270 | self.log.warn("task::Invalid Message: %r",msg) |
|
270 | self.log.warn("task::Invalid Message: %r",msg) | |
271 | return |
|
271 | return | |
272 | try: |
|
272 | try: | |
273 |
msg = self.session. |
|
273 | msg = self.session.deserialize(msg) | |
274 | except ValueError: |
|
274 | except ValueError: | |
275 | self.log.warn("task::Unauthorized message from: %r"%idents) |
|
275 | self.log.warn("task::Unauthorized message from: %r"%idents) | |
276 | return |
|
276 | return | |
@@ -375,7 +375,7 b' class TaskScheduler(SessionFactory):' | |||||
375 | self.notifier_stream.flush() |
|
375 | self.notifier_stream.flush() | |
376 | try: |
|
376 | try: | |
377 | idents, msg = self.session.feed_identities(raw_msg, copy=False) |
|
377 | idents, msg = self.session.feed_identities(raw_msg, copy=False) | |
378 |
msg = self.session. |
|
378 | msg = self.session.deserialize(msg, content=False, copy=False) | |
379 | except Exception: |
|
379 | except Exception: | |
380 | self.log.error("task::Invaid task msg: %r"%raw_msg, exc_info=True) |
|
380 | self.log.error("task::Invaid task msg: %r"%raw_msg, exc_info=True) | |
381 | return |
|
381 | return | |
@@ -621,7 +621,7 b' class TaskScheduler(SessionFactory):' | |||||
621 | """dispatch method for result replies""" |
|
621 | """dispatch method for result replies""" | |
622 | try: |
|
622 | try: | |
623 | idents,msg = self.session.feed_identities(raw_msg, copy=False) |
|
623 | idents,msg = self.session.feed_identities(raw_msg, copy=False) | |
624 |
msg = self.session. |
|
624 | msg = self.session.deserialize(msg, content=False, copy=False) | |
625 | engine = idents[0] |
|
625 | engine = idents[0] | |
626 | try: |
|
626 | try: | |
627 | idx = self.targets.index(engine) |
|
627 | idx = self.targets.index(engine) |
@@ -159,7 +159,7 b' class EngineFactory(RegistrationFactory):' | |||||
159 | loop = self.loop |
|
159 | loop = self.loop | |
160 | identity = self.bident |
|
160 | identity = self.bident | |
161 | idents,msg = self.session.feed_identities(msg) |
|
161 | idents,msg = self.session.feed_identities(msg) | |
162 |
msg = self.session. |
|
162 | msg = self.session.deserialize(msg) | |
163 | content = msg['content'] |
|
163 | content = msg['content'] | |
164 | info = self.connection_info |
|
164 | info = self.connection_info | |
165 |
|
165 |
General Comments 0
You need to be logged in to leave comments.
Login now