##// END OF EJS Templates
Use stdlib json, not zmq jsonapi
Thomas Kluyver -
Show More
@@ -1,52 +1,50 b''
1 1 """Tornado handlers for kernel specifications."""
2 2
3 3 # Copyright (c) IPython Development Team.
4 4 # Distributed under the terms of the Modified BSD License.
5
5 import json
6 6 from tornado import web
7 7
8 from zmq.utils import jsonapi
9
10 8 from ...base.handlers import IPythonHandler, json_errors
11 9
12 10
13 11 class MainKernelSpecHandler(IPythonHandler):
14 12 SUPPORTED_METHODS = ('GET',)
15 13
16 14 @web.authenticated
17 15 @json_errors
18 16 def get(self):
19 17 ksm = self.kernel_spec_manager
20 18 results = []
21 19 for kernel_name in ksm.find_kernel_specs():
22 20 d = ksm.get_kernel_spec(kernel_name).to_dict()
23 21 d['name'] = kernel_name
24 22 results.append(d)
25 23
26 24 self.set_header("Content-Type", 'application/json')
27 self.finish(jsonapi.dumps(results))
25 self.finish(json.dumps(results))
28 26
29 27
30 28 class KernelSpecHandler(IPythonHandler):
31 29 SUPPORTED_METHODS = ('GET',)
32 30
33 31 @web.authenticated
34 32 @json_errors
35 33 def get(self, kernel_name):
36 34 ksm = self.kernel_spec_manager
37 35 try:
38 36 kernelspec = ksm.get_kernel_spec(kernel_name)
39 37 except KeyError:
40 38 raise web.HTTPError(404, u'Kernel spec %s not found' % kernel_name)
41 39 self.set_header("Content-Type", 'application/json')
42 40 self.finish(kernelspec.to_json())
43 41
44 42
45 43 # URL to handler mappings
46 44
47 45 kernel_name_regex = r"(?P<kernel_name>\w+)"
48 46
49 47 default_handlers = [
50 48 (r"/api/kernelspecs", MainKernelSpecHandler),
51 49 (r"/api/kernelspecs/%s" % kernel_name_regex, KernelSpecHandler),
52 50 ]
General Comments 0
You need to be logged in to leave comments. Login now