Show More
@@ -1,6 +1,13 b'' | |||||
1 | """A kernel manager for multiple kernels.""" |
|
1 | """A kernel manager for multiple kernels.""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | #----------------------------------------------------------------------------- | |
|
4 | # Copyright (C) 2011 The IPython Development Team | |||
|
5 | # | |||
|
6 | # Distributed under the terms of the BSD License. The full license is in | |||
|
7 | # the file COPYING.txt, distributed as part of this software. | |||
|
8 | #----------------------------------------------------------------------------- | |||
|
9 | ||||
|
10 | #----------------------------------------------------------------------------- | |||
4 | # Imports |
|
11 | # Imports | |
5 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
6 |
|
13 |
@@ -1,6 +1,13 b'' | |||||
1 | """A tornado based IPython notebook server.""" |
|
1 | """A tornado based IPython notebook server.""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | #----------------------------------------------------------------------------- | |
|
4 | # Copyright (C) 2011 The IPython Development Team | |||
|
5 | # | |||
|
6 | # Distributed under the terms of the BSD License. The full license is in | |||
|
7 | # the file COPYING.txt, distributed as part of this software. | |||
|
8 | #----------------------------------------------------------------------------- | |||
|
9 | ||||
|
10 | #----------------------------------------------------------------------------- | |||
4 | # Imports |
|
11 | # Imports | |
5 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
6 |
|
13 |
@@ -1,3 +1,16 b'' | |||||
|
1 | """Routers that connect WebSockets to ZMQ sockets.""" | |||
|
2 | ||||
|
3 | #----------------------------------------------------------------------------- | |||
|
4 | # Copyright (C) 2011 The IPython Development Team | |||
|
5 | # | |||
|
6 | # Distributed under the terms of the BSD License. The full license is in | |||
|
7 | # the file COPYING.txt, distributed as part of this software. | |||
|
8 | #----------------------------------------------------------------------------- | |||
|
9 | ||||
|
10 | #----------------------------------------------------------------------------- | |||
|
11 | # Imports | |||
|
12 | #----------------------------------------------------------------------------- | |||
|
13 | ||||
1 | import uuid |
|
14 | import uuid | |
2 | from Queue import Queue |
|
15 | from Queue import Queue | |
3 | import json |
|
16 | import json | |
@@ -5,6 +18,10 b' import json' | |||||
5 | from IPython.config.configurable import Configurable |
|
18 | from IPython.config.configurable import Configurable | |
6 | from IPython.utils.traitlets import Instance, Int, Dict |
|
19 | from IPython.utils.traitlets import Instance, Int, Dict | |
7 |
|
20 | |||
|
21 | #----------------------------------------------------------------------------- | |||
|
22 | # Classes | |||
|
23 | #----------------------------------------------------------------------------- | |||
|
24 | ||||
8 | class ZMQStreamRouter(Configurable): |
|
25 | class ZMQStreamRouter(Configurable): | |
9 |
|
26 | |||
10 | zmq_stream = Instance('zmq.eventloop.zmqstream.ZMQStream') |
|
27 | zmq_stream = Instance('zmq.eventloop.zmqstream.ZMQStream') | |
@@ -58,15 +75,26 b' class ZMQStreamRouter(Configurable):' | |||||
58 | """ |
|
75 | """ | |
59 | pass |
|
76 | pass | |
60 |
|
77 | |||
|
78 | def _reserialize_reply(self, msg_list): | |||
|
79 | """Reserialize a reply message using JSON. | |||
|
80 | ||||
|
81 | This takes the msg list from the ZMQ socket, unserializes it using | |||
|
82 | self.session and then serializes the result using JSON. This method | |||
|
83 | should be used by self._on_zmq_reply to build messages that can | |||
|
84 | be sent back to the browser. | |||
|
85 | """ | |||
|
86 | idents, msg_list = self.session.feed_identities(msg_list) | |||
|
87 | msg = self.session.unpack_message(msg_list) | |||
|
88 | msg['header'].pop('date') | |||
|
89 | return json.dumps(msg) | |||
|
90 | ||||
61 |
|
91 | |||
62 | class IOPubStreamRouter(ZMQStreamRouter): |
|
92 | class IOPubStreamRouter(ZMQStreamRouter): | |
63 |
|
93 | |||
64 | def _on_zmq_reply(self, msg_list): |
|
94 | def _on_zmq_reply(self, msg_list): | |
65 |
msg = self. |
|
95 | msg = self._reserialize_reply(msg_list) | |
66 | msg = json.dumps(msg) |
|
|||
67 | for client_id, client in self._clients.items(): |
|
96 | for client_id, client in self._clients.items(): | |
68 | for msg in msg_list: |
|
97 | client.write_message(msg) | |
69 | client.write_message(msg) |
|
|||
70 |
|
98 | |||
71 |
|
99 | |||
72 | class ShellStreamRouter(ZMQStreamRouter): |
|
100 | class ShellStreamRouter(ZMQStreamRouter): | |
@@ -74,21 +102,16 b' class ShellStreamRouter(ZMQStreamRouter):' | |||||
74 | _request_queue = Instance(Queue,(),{}) |
|
102 | _request_queue = Instance(Queue,(),{}) | |
75 |
|
103 | |||
76 | def _on_zmq_reply(self, msg_list): |
|
104 | def _on_zmq_reply(self, msg_list): | |
77 |
msg = self. |
|
105 | msg = self._reserialize_reply(msg_list) | |
78 | msg = json.dumps(msg) |
|
|||
79 | print "Reply: ", msg_list |
|
|||
80 | client_id = self._request_queue.get(block=False) |
|
106 | client_id = self._request_queue.get(block=False) | |
81 | client = self._clients.get(client_id) |
|
107 | client = self._clients.get(client_id) | |
82 | if client is not None: |
|
108 | if client is not None: | |
83 | for msg in msg_list: |
|
109 | client.write_message(msg) | |
84 | client.write_message(msg) |
|
|||
85 |
|
110 | |||
86 | def forward_msg(self, client_id, msg): |
|
111 | def forward_msg(self, client_id, msg): | |
87 | if len(msg) < self.max_msg_size: |
|
112 | if len(msg) < self.max_msg_size: | |
88 | msg = json.loads(msg) |
|
113 | msg = json.loads(msg) | |
89 | print "Raw msg: ", msg |
|
|||
90 | to_send = self.session.serialize(msg) |
|
114 | to_send = self.session.serialize(msg) | |
91 | print "to_send: ", to_send, to_send[-3:] |
|
|||
92 | self._request_queue.put(client_id) |
|
115 | self._request_queue.put(client_id) | |
93 |
self.session.send |
|
116 | self.session.send(self.zmq_stream, msg) | |
94 |
|
117 |
@@ -1,6 +1,13 b'' | |||||
1 | """A manager for session and channels for a single kernel.""" |
|
1 | """A manager for session and channels for a single kernel.""" | |
2 |
|
2 | |||
3 | #----------------------------------------------------------------------------- |
|
3 | #----------------------------------------------------------------------------- | |
|
4 | # Copyright (C) 2011 The IPython Development Team | |||
|
5 | # | |||
|
6 | # Distributed under the terms of the BSD License. The full license is in | |||
|
7 | # the file COPYING.txt, distributed as part of this software. | |||
|
8 | #----------------------------------------------------------------------------- | |||
|
9 | ||||
|
10 | #----------------------------------------------------------------------------- | |||
4 | # Imports |
|
11 | # Imports | |
5 | #----------------------------------------------------------------------------- |
|
12 | #----------------------------------------------------------------------------- | |
6 |
|
13 |
@@ -166,6 +166,8 b' div.output_latex {' | |||||
166 | font-size: 13pt; |
|
166 | font-size: 13pt; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
|
169 | div.output_png { | |||
|
170 | } | |||
169 |
|
171 | |||
170 | div.text_cell { |
|
172 | div.text_cell { | |
171 | background-color: white; |
|
173 | background-color: white; |
@@ -441,7 +441,7 b' Notebook.prototype._kernel_started = function () {' | |||||
441 | this.kernel.shell_channel.onmessage = function (e) { |
|
441 | this.kernel.shell_channel.onmessage = function (e) { | |
442 | reply = $.parseJSON(e.data); |
|
442 | reply = $.parseJSON(e.data); | |
443 | // console.log(reply); |
|
443 | // console.log(reply); | |
444 | var msg_type = reply.msg_type; |
|
444 | var msg_type = reply.header.msg_type; | |
445 | var cell = that.cell_for_msg(reply.parent_header.msg_id); |
|
445 | var cell = that.cell_for_msg(reply.parent_header.msg_id); | |
446 | if (msg_type === "execute_reply") { |
|
446 | if (msg_type === "execute_reply") { | |
447 | cell.set_input_prompt(reply.content.execution_count); |
|
447 | cell.set_input_prompt(reply.content.execution_count); | |
@@ -451,8 +451,8 b' Notebook.prototype._kernel_started = function () {' | |||||
451 | this.kernel.iopub_channel.onmessage = function (e) { |
|
451 | this.kernel.iopub_channel.onmessage = function (e) { | |
452 | reply = $.parseJSON(e.data); |
|
452 | reply = $.parseJSON(e.data); | |
453 | var content = reply.content; |
|
453 | var content = reply.content; | |
454 |
|
|
454 | console.log(reply); | |
455 | var msg_type = reply.msg_type; |
|
455 | var msg_type = reply.header.msg_type; | |
456 | var cell = that.cell_for_msg(reply.parent_header.msg_id); |
|
456 | var cell = that.cell_for_msg(reply.parent_header.msg_id); | |
457 | if (msg_type === "stream") { |
|
457 | if (msg_type === "stream") { | |
458 | cell.expand(); |
|
458 | cell.expand(); | |
@@ -709,6 +709,7 b' CodeCell.prototype.append_pyerr = function (ename, evalue, tb) {' | |||||
709 |
|
709 | |||
710 |
|
710 | |||
711 | CodeCell.prototype.append_display_data = function (data, element) { |
|
711 | CodeCell.prototype.append_display_data = function (data, element) { | |
|
712 | console.log(data); | |||
712 | if (data["text/latex"] !== undefined) { |
|
713 | if (data["text/latex"] !== undefined) { | |
713 | this.append_latex(data["text/latex"], element); |
|
714 | this.append_latex(data["text/latex"], element); | |
714 | // If it is undefined, then we just appended to div.output, which |
|
715 | // If it is undefined, then we just appended to div.output, which | |
@@ -719,6 +720,8 b' CodeCell.prototype.append_display_data = function (data, element) {' | |||||
719 | }; |
|
720 | }; | |
720 | } else if (data["image/svg+xml"] !== undefined) { |
|
721 | } else if (data["image/svg+xml"] !== undefined) { | |
721 | this.append_svg(data["image/svg+xml"], element); |
|
722 | this.append_svg(data["image/svg+xml"], element); | |
|
723 | } else if (data["image/png"] !== undefined) { | |||
|
724 | this.append_png(data["image/png"], element); | |||
722 | } else if (data["text/plain"] !== undefined) { |
|
725 | } else if (data["text/plain"] !== undefined) { | |
723 | this.append_stream(data["text/plain"], element); |
|
726 | this.append_stream(data["text/plain"], element); | |
724 | }; |
|
727 | }; | |
@@ -744,6 +747,15 b' CodeCell.prototype.append_svg = function (svg, element) {' | |||||
744 | }; |
|
747 | }; | |
745 |
|
748 | |||
746 |
|
749 | |||
|
750 | CodeCell.prototype.append_png = function (png, element) { | |||
|
751 | element = element || this.element.find("div.output"); | |||
|
752 | var toinsert = $("<div/>").addClass("output_area output_png"); | |||
|
753 | toinsert.append($("<img/>").attr('src','data:image/png;base64,'+png)); | |||
|
754 | element.append(toinsert); | |||
|
755 | return element; | |||
|
756 | }; | |||
|
757 | ||||
|
758 | ||||
747 | CodeCell.prototype.append_latex = function (latex, element) { |
|
759 | CodeCell.prototype.append_latex = function (latex, element) { | |
748 | // This method cannot do the typesetting because the latex first has to |
|
760 | // This method cannot do the typesetting because the latex first has to | |
749 | // be on the page. |
|
761 | // be on the page. | |
@@ -982,9 +994,9 b' Kernel.prototype.get_msg = function (msg_type, content) {' | |||||
982 | header : { |
|
994 | header : { | |
983 | msg_id : uuid(), |
|
995 | msg_id : uuid(), | |
984 | username : "bgranger", |
|
996 | username : "bgranger", | |
985 | session: this.session_id |
|
997 | session: this.session_id, | |
|
998 | msg_type : msg_type | |||
986 | }, |
|
999 | }, | |
987 | msg_type : msg_type, |
|
|||
988 | content : content, |
|
1000 | content : content, | |
989 | parent_header : {} |
|
1001 | parent_header : {} | |
990 | }; |
|
1002 | }; | |
@@ -1129,4 +1141,5 b' $(document).ready(function () {' | |||||
1129 | $("#collapse").click(function () {IPYTHON.notebook.collapse();}); |
|
1141 | $("#collapse").click(function () {IPYTHON.notebook.collapse();}); | |
1130 | $("#expand").click(function () {IPYTHON.notebook.expand();}); |
|
1142 | $("#expand").click(function () {IPYTHON.notebook.expand();}); | |
1131 |
|
1143 | |||
1132 | }); No newline at end of file |
|
1144 | }); | |
|
1145 |
General Comments 0
You need to be logged in to leave comments.
Login now