##// END OF EJS Templates
only use zmq.jsonapi when talking to zmq sockets...
MinRK -
Show More
@@ -3,6 +3,8 b''
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import json
7
6 try:
8 try:
7 from urllib.parse import urlparse # Py 3
9 from urllib.parse import urlparse # Py 3
8 except ImportError:
10 except ImportError:
@@ -16,8 +18,6 b' import logging'
16 from tornado import web
18 from tornado import web
17 from tornado import websocket
19 from tornado import websocket
18
20
19 from zmq.utils import jsonapi
20
21 from IPython.kernel.zmq.session import Session
21 from IPython.kernel.zmq.session import Session
22 from IPython.utils.jsonutil import date_default
22 from IPython.utils.jsonutil import date_default
23 from IPython.utils.py3compat import PY3, cast_unicode
23 from IPython.utils.py3compat import PY3, cast_unicode
@@ -73,7 +73,7 b' class ZMQStreamHandler(websocket.WebSocketHandler):'
73 except KeyError:
73 except KeyError:
74 pass
74 pass
75 msg.pop('buffers')
75 msg.pop('buffers')
76 return jsonapi.dumps(msg, default=date_default)
76 return json.dumps(msg, default=date_default)
77
77
78 def _on_zmq_reply(self, msg_list):
78 def _on_zmq_reply(self, msg_list):
79 # Sometimes this gets triggered when the on_close method is scheduled in the
79 # Sometimes this gets triggered when the on_close method is scheduled in the
@@ -1,25 +1,12 b''
1 """Tornado handlers for cluster web service.
1 """Tornado handlers for cluster web service."""
2
2
3 Authors:
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4
5
5 * Brian Granger
6 import json
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2011 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
7
19 from tornado import web
8 from tornado import web
20
9
21 from zmq.utils import jsonapi
22
23 from ...base.handlers import IPythonHandler
10 from ...base.handlers import IPythonHandler
24
11
25 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
@@ -31,14 +18,14 b' class MainClusterHandler(IPythonHandler):'
31
18
32 @web.authenticated
19 @web.authenticated
33 def get(self):
20 def get(self):
34 self.finish(jsonapi.dumps(self.cluster_manager.list_profiles()))
21 self.finish(json.dumps(self.cluster_manager.list_profiles()))
35
22
36
23
37 class ClusterProfileHandler(IPythonHandler):
24 class ClusterProfileHandler(IPythonHandler):
38
25
39 @web.authenticated
26 @web.authenticated
40 def get(self, profile):
27 def get(self, profile):
41 self.finish(jsonapi.dumps(self.cluster_manager.profile_info(profile)))
28 self.finish(json.dumps(self.cluster_manager.profile_info(profile)))
42
29
43
30
44 class ClusterActionHandler(IPythonHandler):
31 class ClusterActionHandler(IPythonHandler):
@@ -54,7 +41,7 b' class ClusterActionHandler(IPythonHandler):'
54 data = cm.start_cluster(profile, int(n))
41 data = cm.start_cluster(profile, int(n))
55 if action == 'stop':
42 if action == 'stop':
56 data = cm.stop_cluster(profile)
43 data = cm.stop_cluster(profile)
57 self.finish(jsonapi.dumps(data))
44 self.finish(json.dumps(data))
58
45
59
46
60 #-----------------------------------------------------------------------------
47 #-----------------------------------------------------------------------------
@@ -3,11 +3,10 b''
3 # Copyright (c) IPython Development Team.
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
4 # Distributed under the terms of the Modified BSD License.
5
5
6 import json
6 import logging
7 import logging
7 from tornado import web
8 from tornado import web
8
9
9 from zmq.utils import jsonapi
10
11 from IPython.utils.jsonutil import date_default
10 from IPython.utils.jsonutil import date_default
12 from IPython.utils.py3compat import string_types
11 from IPython.utils.py3compat import string_types
13 from IPython.html.utils import url_path_join, url_escape
12 from IPython.html.utils import url_path_join, url_escape
@@ -23,7 +22,7 b' class MainKernelHandler(IPythonHandler):'
23 @json_errors
22 @json_errors
24 def get(self):
23 def get(self):
25 km = self.kernel_manager
24 km = self.kernel_manager
26 self.finish(jsonapi.dumps(km.list_kernels()))
25 self.finish(json.dumps(km.list_kernels()))
27
26
28 @web.authenticated
27 @web.authenticated
29 @json_errors
28 @json_errors
@@ -34,7 +33,7 b' class MainKernelHandler(IPythonHandler):'
34 location = url_path_join(self.base_url, 'api', 'kernels', kernel_id)
33 location = url_path_join(self.base_url, 'api', 'kernels', kernel_id)
35 self.set_header('Location', url_escape(location))
34 self.set_header('Location', url_escape(location))
36 self.set_status(201)
35 self.set_status(201)
37 self.finish(jsonapi.dumps(model))
36 self.finish(json.dumps(model))
38
37
39
38
40 class KernelHandler(IPythonHandler):
39 class KernelHandler(IPythonHandler):
@@ -47,7 +46,7 b' class KernelHandler(IPythonHandler):'
47 km = self.kernel_manager
46 km = self.kernel_manager
48 km._check_kernel_id(kernel_id)
47 km._check_kernel_id(kernel_id)
49 model = km.kernel_model(kernel_id)
48 model = km.kernel_model(kernel_id)
50 self.finish(jsonapi.dumps(model))
49 self.finish(json.dumps(model))
51
50
52 @web.authenticated
51 @web.authenticated
53 @json_errors
52 @json_errors
@@ -71,7 +70,7 b' class KernelActionHandler(IPythonHandler):'
71 km.restart_kernel(kernel_id)
70 km.restart_kernel(kernel_id)
72 model = km.kernel_model(kernel_id)
71 model = km.kernel_model(kernel_id)
73 self.set_header('Location', '{0}api/kernels/{1}'.format(self.base_url, kernel_id))
72 self.set_header('Location', '{0}api/kernels/{1}'.format(self.base_url, kernel_id))
74 self.write(jsonapi.dumps(model))
73 self.write(json.dumps(model))
75 self.finish()
74 self.finish()
76
75
77
76
@@ -138,7 +137,7 b' class ZMQChannelHandler(AuthenticatedZMQStreamHandler):'
138 self.zmq_stream.on_recv(self._on_zmq_reply)
137 self.zmq_stream.on_recv(self._on_zmq_reply)
139
138
140 def on_message(self, msg):
139 def on_message(self, msg):
141 msg = jsonapi.loads(msg)
140 msg = json.loads(msg)
142 self.session.send(self.zmq_stream, msg)
141 self.session.send(self.zmq_stream, msg)
143
142
144 def on_close(self):
143 def on_close(self):
@@ -177,7 +176,7 b' class IOPubHandler(ZMQChannelHandler):'
177 msg = self.session.msg("status",
176 msg = self.session.msg("status",
178 {'execution_state': status}
177 {'execution_state': status}
179 )
178 )
180 self.write_message(jsonapi.dumps(msg, default=date_default))
179 self.write_message(json.dumps(msg, default=date_default))
181
180
182 def on_kernel_restarted(self):
181 def on_kernel_restarted(self):
183 logging.warn("kernel %s restarted", self.kernel_id)
182 logging.warn("kernel %s restarted", self.kernel_id)
General Comments 0
You need to be logged in to leave comments. Login now