Show More
@@ -24,7 +24,7 b' var IPython = (function (IPython) {' | |||||
24 |
|
24 | |||
25 | var CommManager = function (kernel) { |
|
25 | var CommManager = function (kernel) { | |
26 | this.comms = {}; |
|
26 | this.comms = {}; | |
27 |
this.targets = { |
|
27 | this.targets = {}; | |
28 | if (kernel !== undefined) { |
|
28 | if (kernel !== undefined) { | |
29 | this.init_kernel(kernel); |
|
29 | this.init_kernel(kernel); | |
30 | } |
|
30 | } | |
@@ -40,9 +40,9 b' var IPython = (function (IPython) {' | |||||
40 | } |
|
40 | } | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 |
CommManager.prototype.register_target = function (target, |
|
43 | CommManager.prototype.register_target = function (target_name, f) { | |
44 |
// Register a |
|
44 | // Register a target function for a given target name | |
45 |
this.targets[target] = |
|
45 | this.targets[target_name] = f; | |
46 | }; |
|
46 | }; | |
47 |
|
47 | |||
48 | CommManager.prototype.register_comm = function (comm) { |
|
48 | CommManager.prototype.register_comm = function (comm) { | |
@@ -61,9 +61,9 b' var IPython = (function (IPython) {' | |||||
61 |
|
61 | |||
62 | CommManager.prototype.comm_open = function (msg) { |
|
62 | CommManager.prototype.comm_open = function (msg) { | |
63 | var content = msg.content; |
|
63 | var content = msg.content; | |
64 | var callback = this.targets[content.target]; |
|
64 | var callback = this.targets[content.target_name]; | |
65 | if (callback === undefined) { |
|
65 | if (callback === undefined) { | |
66 | console.log("No such target registered: ", content.target); |
|
66 | console.log("No such target registered: ", content.target_name); | |
67 | console.log("Available targets are: ", this.targets); |
|
67 | console.log("Available targets are: ", this.targets); | |
68 | return; |
|
68 | return; | |
69 | } |
|
69 | } | |
@@ -96,9 +96,9 b' var IPython = (function (IPython) {' | |||||
96 | // Comm base class |
|
96 | // Comm base class | |
97 | //----------------------------------------------------------------------- |
|
97 | //----------------------------------------------------------------------- | |
98 |
|
98 | |||
99 | var Comm = function (comm_id, target) { |
|
99 | var Comm = function (comm_id, target_name) { | |
100 | this.comm_id = comm_id || new IPython.utils.uuid(); |
|
100 | this.comm_id = comm_id || new IPython.utils.uuid(); | |
101 |
this.target = target |
|
101 | this.target_name = target_name; | |
102 | this._msg_callback = this._open_callback = this._close_callback = null; |
|
102 | this._msg_callback = this._open_callback = this._close_callback = null; | |
103 | }; |
|
103 | }; | |
104 |
|
104 | |||
@@ -106,7 +106,7 b' var IPython = (function (IPython) {' | |||||
106 | Comm.prototype.open = function (data, callbacks) { |
|
106 | Comm.prototype.open = function (data, callbacks) { | |
107 | var content = { |
|
107 | var content = { | |
108 | comm_id : this.comm_id, |
|
108 | comm_id : this.comm_id, | |
109 | target : this.target, |
|
109 | target_name : this.target_name, | |
110 | data : data || {}, |
|
110 | data : data || {}, | |
111 | }; |
|
111 | }; | |
112 | return this.kernel.send_shell_message("comm_open", content, callbacks); |
|
112 | return this.kernel.send_shell_message("comm_open", content, callbacks); |
@@ -37,7 +37,7 b' class Comm(LoggingConfigurable):' | |||||
37 | return |
|
37 | return | |
38 | return self.shell.kernel.session |
|
38 | return self.shell.kernel.session | |
39 |
|
39 | |||
40 | target = Unicode('comm') |
|
40 | target_name = Unicode('comm') | |
41 |
|
41 | |||
42 | topic = Bytes() |
|
42 | topic = Bytes() | |
43 | def _topic_default(self): |
|
43 | def _topic_default(self): | |
@@ -82,7 +82,7 b' class Comm(LoggingConfigurable):' | |||||
82 | """Open the frontend-side version of this comm""" |
|
82 | """Open the frontend-side version of this comm""" | |
83 | if data is None: |
|
83 | if data is None: | |
84 | data = self._open_data |
|
84 | data = self._open_data | |
85 | self._publish_msg('comm_open', data, target=self.target) |
|
85 | self._publish_msg('comm_open', data, target_name=self.target_name) | |
86 |
|
86 | |||
87 | def close(self, data=None): |
|
87 | def close(self, data=None): | |
88 | """Close the frontend-side version of this comm""" |
|
88 | """Close the frontend-side version of this comm""" |
@@ -76,8 +76,8 b' class CommManager(LoggingConfigurable):' | |||||
76 |
|
76 | |||
77 | # Public APIs |
|
77 | # Public APIs | |
78 |
|
78 | |||
79 | def register_target(self, target, f): |
|
79 | def register_target(self, target_name, f): | |
80 | """Register a callable f for a given target |
|
80 | """Register a callable f for a given target name | |
81 |
|
81 | |||
82 | f will be called with a Comm object as its only argument |
|
82 | f will be called with a Comm object as its only argument | |
83 | when a comm_open message is received with `target`. |
|
83 | when a comm_open message is received with `target`. | |
@@ -87,7 +87,7 b' class CommManager(LoggingConfigurable):' | |||||
87 | if isinstance(f, basestring): |
|
87 | if isinstance(f, basestring): | |
88 | f = import_item(f) |
|
88 | f = import_item(f) | |
89 |
|
89 | |||
90 | self.targets[target] = f |
|
90 | self.targets[target_name] = f | |
91 |
|
91 | |||
92 | def register_comm(self, comm): |
|
92 | def register_comm(self, comm): | |
93 | """Register a new comm""" |
|
93 | """Register a new comm""" | |
@@ -125,18 +125,18 b' class CommManager(LoggingConfigurable):' | |||||
125 | """Handler for comm_open messages""" |
|
125 | """Handler for comm_open messages""" | |
126 | content = msg['content'] |
|
126 | content = msg['content'] | |
127 | comm_id = content['comm_id'] |
|
127 | comm_id = content['comm_id'] | |
128 | target = content['target'] |
|
128 | target_name = content['target_name'] | |
129 |
|
|
129 | f = self.targets.get(target_name, None) | |
130 | comm = Comm(comm_id=comm_id, |
|
130 | comm = Comm(comm_id=comm_id, | |
131 | shell=self.shell, |
|
131 | shell=self.shell, | |
132 | iopub_socket=self.iopub_socket, |
|
132 | iopub_socket=self.iopub_socket, | |
133 | primary=False, |
|
133 | primary=False, | |
134 | ) |
|
134 | ) | |
135 |
if |
|
135 | if f is None: | |
136 | self.log.error("No such comm target registered: %s", target) |
|
136 | self.log.error("No such comm target registered: %s", target_name) | |
137 | comm.close() |
|
137 | comm.close() | |
138 | return |
|
138 | return | |
139 |
|
|
139 | f(comm) | |
140 | comm.handle_open(msg) |
|
140 | comm.handle_open(msg) | |
141 | self.register_comm(comm) |
|
141 | self.register_comm(comm) | |
142 |
|
142 |
General Comments 0
You need to be logged in to leave comments.
Login now