##// END OF EJS Templates
emit valid html:...
emit valid html: Not closed div, <a> don't have alt but title, chrome frame has been closed for at least a year, IE shoudl use edge mode. div cannot embed span.

File last commit:

r19263:ac2ff1be
r19477:da58c6f3
Show More
handlers.py
57 lines | 1.7 KiB | text/x-python | PythonLexer
Thomas Kluyver
Create REST API for kernel specs
r16684 """Tornado handlers for kernel specifications."""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Thomas Kluyver
Use stdlib json, not zmq jsonapi
r17020 import json
Thomas Kluyver
Create REST API for kernel specs
r16684 from tornado import web
Thomas Kluyver
Test kernel specs REST API...
r16689 from ...base.handlers import IPythonHandler, json_errors
Thomas Kluyver
Create REST API for kernel specs
r16684
class MainKernelSpecHandler(IPythonHandler):
SUPPORTED_METHODS = ('GET',)
@web.authenticated
@json_errors
def get(self):
ksm = self.kernel_spec_manager
Min RK
kernelspecs is a dict...
r19263 km = self.kernel_manager
model = {}
model['default'] = km.default_kernel_name
model['kernelspecs'] = specs = {}
for kernel_name in ksm.find_kernel_specs():
Min RK
log kernel specs that fail to load
r18552 try:
d = ksm.get_kernel_spec(kernel_name).to_dict()
except Exception:
self.log.error("Failed to load kernel spec: '%s'", kernel_name, exc_info=True)
continue
Thomas Kluyver
Put full kernel info in REST API response for all kernels
r16714 d['name'] = kernel_name
Min RK
kernelspecs is a dict...
r19263 specs[kernel_name] = d
Thomas Kluyver
Create REST API for kernel specs
r16684
self.set_header("Content-Type", 'application/json')
Min RK
kernelspecs is a dict...
r19263 self.finish(json.dumps(model))
Thomas Kluyver
Create REST API for kernel specs
r16684
class KernelSpecHandler(IPythonHandler):
SUPPORTED_METHODS = ('GET',)
@web.authenticated
@json_errors
def get(self, kernel_name):
ksm = self.kernel_spec_manager
Thomas Kluyver
Test kernel specs REST API...
r16689 try:
kernelspec = ksm.get_kernel_spec(kernel_name)
except KeyError:
raise web.HTTPError(404, u'Kernel spec %s not found' % kernel_name)
Thomas Kluyver
Create REST API for kernel specs
r16684 self.set_header("Content-Type", 'application/json')
self.finish(kernelspec.to_json())
# URL to handler mappings
Thomas Kluyver
Refactor kernelspec resource handler to separate URL prefix
r16706 kernel_name_regex = r"(?P<kernel_name>\w+)"
Thomas Kluyver
Create REST API for kernel specs
r16684
default_handlers = [
(r"/api/kernelspecs", MainKernelSpecHandler),
Thomas Kluyver
Refactor kernelspec resource handler to separate URL prefix
r16706 (r"/api/kernelspecs/%s" % kernel_name_regex, KernelSpecHandler),
Thomas Kluyver
Create REST API for kernel specs
r16684 ]