##// END OF EJS Templates
allow metadata in Kernel-side Comm messages.
MinRK -
Show More
@@ -63,11 +63,13 b' class Comm(LoggingConfigurable):'
63 # I am primary, open my peer.
63 # I am primary, open my peer.
64 self.open(data)
64 self.open(data)
65
65
66 def _publish_msg(self, msg_type, data=None, **keys):
66 def _publish_msg(self, msg_type, data=None, metadata=None, **keys):
67 """Helper for sending a comm message on IOPub"""
67 """Helper for sending a comm message on IOPub"""
68 data = {} if data is None else data
68 data = {} if data is None else data
69 metadata = {} if metadata is None else metadata
69 self.session.send(self.iopub_socket, msg_type,
70 self.session.send(self.iopub_socket, msg_type,
70 dict(data=data, comm_id=self.comm_id, **keys),
71 dict(data=data, comm_id=self.comm_id, **keys),
72 metadata=metadata,
71 parent=self.shell.get_parent(),
73 parent=self.shell.get_parent(),
72 ident=self.topic,
74 ident=self.topic,
73 )
75 )
@@ -78,25 +80,25 b' class Comm(LoggingConfigurable):'
78
80
79 # publishing messages
81 # publishing messages
80
82
81 def open(self, data=None):
83 def open(self, data=None, metadata=None):
82 """Open the frontend-side version of this comm"""
84 """Open the frontend-side version of this comm"""
83 if data is None:
85 if data is None:
84 data = self._open_data
86 data = self._open_data
85 self._publish_msg('comm_open', data, target_name=self.target_name)
87 self._publish_msg('comm_open', data, metadata, target_name=self.target_name)
86
88
87 def close(self, data=None):
89 def close(self, data=None, metadata=None):
88 """Close the frontend-side version of this comm"""
90 """Close the frontend-side version of this comm"""
89 if self._closed:
91 if self._closed:
90 # only close once
92 # only close once
91 return
93 return
92 if data is None:
94 if data is None:
93 data = self._close_data
95 data = self._close_data
94 self._publish_msg('comm_close', data)
96 self._publish_msg('comm_close', data, metadata)
95 self._closed = True
97 self._closed = True
96
98
97 def send(self, data=None):
99 def send(self, data=None, metadata=None):
98 """Send a message to the frontend-side version of this comm"""
100 """Send a message to the frontend-side version of this comm"""
99 self._publish_msg('comm_msg', data)
101 self._publish_msg('comm_msg', data, metadata)
100
102
101 # registering callbacks
103 # registering callbacks
102
104
General Comments 0
You need to be logged in to leave comments. Login now