##// END OF EJS Templates
fix missing trailing comma in kernel.js
MinRK -
Show More
@@ -1,167 +1,167 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2008-2011 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // Kernel
10 10 //============================================================================
11 11
12 12 var IPython = (function (IPython) {
13 13
14 14 var utils = IPython.utils;
15 15
16 16 var Kernel = function () {
17 17 this.kernel_id = null;
18 18 this.base_url = "/kernels";
19 19 this.kernel_url = null;
20 20 this.shell_channel = null;
21 21 this.iopub_channel = null;
22 22 this.running = false;
23 23
24 24 this.username = "username";
25 25 this.session_id = utils.uuid();
26 26
27 27 if (typeof(WebSocket) !== 'undefined') {
28 28 this.WebSocket = WebSocket
29 29 } else if (typeof(MozWebSocket) !== 'undefined') {
30 30 this.WebSocket = MozWebSocket
31 31 } else {
32 32 alert('Your browser does not have WebSocket support, please try Chrome, Safari or Firefox 6. Firefox 4 and 5 are also supported by you have to enable WebSockets in about:config.');
33 33 };
34 34 };
35 35
36 36
37 37 Kernel.prototype.get_msg = function (msg_type, content) {
38 38 var msg = {
39 39 header : {
40 40 msg_id : utils.uuid(),
41 41 username : this.username,
42 42 session : this.session_id,
43 43 msg_type : msg_type
44 44 },
45 45 content : content,
46 46 parent_header : {}
47 47 };
48 48 return msg;
49 49 }
50 50
51 51 Kernel.prototype.start = function (notebook_id, callback) {
52 52 var that = this;
53 53 if (!this.running) {
54 54 var qs = $.param({notebook:notebook_id});
55 55 $.post(this.base_url + '?' + qs,
56 56 function (kernel_id) {
57 57 that._handle_start_kernel(kernel_id, callback);
58 58 },
59 59 'json'
60 60 );
61 61 };
62 62 };
63 63
64 64
65 65 Kernel.prototype.restart = function (callback) {
66 66 IPython.kernel_status_widget.status_restarting();
67 67 var url = this.kernel_url + "/restart";
68 68 var that = this;
69 69 if (this.running) {
70 70 this.stop_channels();
71 71 $.post(url,
72 72 function (kernel_id) {
73 73 that._handle_start_kernel(kernel_id, callback);
74 74 },
75 75 'json'
76 76 );
77 77 };
78 78 };
79 79
80 80
81 81 Kernel.prototype._handle_start_kernel = function (json, callback) {
82 82 this.running = true;
83 83 this.kernel_id = json.kernel_id;
84 84 this.ws_url = json.ws_url;
85 85 this.kernel_url = this.base_url + "/" + this.kernel_id;
86 86 this.start_channels();
87 87 callback();
88 88 IPython.kernel_status_widget.status_idle();
89 89 };
90 90
91 91
92 92 Kernel.prototype.start_channels = function () {
93 93 this.stop_channels();
94 94 var ws_url = this.ws_url + this.kernel_url;
95 95 console.log("Starting WS:", ws_url);
96 96 this.shell_channel = new this.WebSocket(ws_url + "/shell");
97 97 this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
98 98 send_cookie = function(){
99 99 this.send(document.cookie);
100 100 console.log(this);
101 101 }
102 102 this.shell_channel.onopen = send_cookie;
103 103 this.iopub_channel.onopen = send_cookie;
104 104 };
105 105
106 106
107 107 Kernel.prototype.stop_channels = function () {
108 108 if (this.shell_channel !== null) {
109 109 this.shell_channel.close();
110 110 this.shell_channel = null;
111 111 };
112 112 if (this.iopub_channel !== null) {
113 113 this.iopub_channel.close();
114 114 this.iopub_channel = null;
115 115 };
116 116 };
117 117
118 118 Kernel.prototype.execute = function (code) {
119 119 var content = {
120 120 code : code,
121 121 silent : false,
122 122 user_variables : [],
123 user_expressions : {}
123 user_expressions : {},
124 124 allow_stdin : false,
125 125 };
126 126 var msg = this.get_msg("execute_request", content);
127 127 this.shell_channel.send(JSON.stringify(msg));
128 128 return msg.header.msg_id;
129 129 }
130 130
131 131
132 132 Kernel.prototype.complete = function (line, cursor_pos) {
133 133 var content = {
134 134 text : '',
135 135 line : line,
136 136 cursor_pos : cursor_pos
137 137 };
138 138 var msg = this.get_msg("complete_request", content);
139 139 this.shell_channel.send(JSON.stringify(msg));
140 140 return msg.header.msg_id;
141 141 }
142 142
143 143
144 144 Kernel.prototype.interrupt = function () {
145 145 if (this.running) {
146 146 $.post(this.kernel_url + "/interrupt");
147 147 };
148 148 };
149 149
150 150
151 151 Kernel.prototype.kill = function () {
152 152 if (this.running) {
153 153 this.running = false;
154 154 var settings = {
155 155 cache : false,
156 156 type : "DELETE",
157 157 };
158 158 $.ajax(this.kernel_url, settings);
159 159 };
160 160 };
161 161
162 162 IPython.Kernel = Kernel;
163 163
164 164 return IPython;
165 165
166 166 }(IPython));
167 167
General Comments 0
You need to be logged in to leave comments. Login now