Show More
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,25 b'' | |||||
|
1 | from tornado import web | |||
|
2 | from ..base.handlers import IPythonHandler | |||
|
3 | from ..services.kernelspecs.handlers import kernel_name_regex | |||
|
4 | ||||
|
5 | class KernelSpecResourceHandler(web.StaticFileHandler, IPythonHandler): | |||
|
6 | SUPPORTED_METHODS = ('GET', 'HEAD') | |||
|
7 | ||||
|
8 | def initialize(self): | |||
|
9 | web.StaticFileHandler.initialize(self, path='') | |||
|
10 | ||||
|
11 | def get(self, kernel_name, path, include_body=True): | |||
|
12 | ksm = self.kernel_spec_manager | |||
|
13 | try: | |||
|
14 | self.root = ksm.get_kernel_spec(kernel_name).resource_dir | |||
|
15 | except KeyError: | |||
|
16 | raise web.HTTPError(404, u'Kernel spec %s not found' % kernel_name) | |||
|
17 | self.log.debug("Serving kernel resource from: %s", self.root) | |||
|
18 | return web.StaticFileHandler.get(self, path, include_body=include_body) | |||
|
19 | ||||
|
20 | def head(self, kernel_name, path): | |||
|
21 | self.get(kernel_name, path, include_body=False) | |||
|
22 | ||||
|
23 | default_handlers = [ | |||
|
24 | (r"/kernelspecs/%s/(?P<path>.*)" % kernel_name_regex, KernelSpecResourceHandler), | |||
|
25 | ] No newline at end of file |
@@ -187,6 +187,7 b' class NotebookWebApplication(web.Application):' | |||||
187 | handlers.extend(load_handlers('auth.logout')) |
|
187 | handlers.extend(load_handlers('auth.logout')) | |
188 | handlers.extend(load_handlers('notebook.handlers')) |
|
188 | handlers.extend(load_handlers('notebook.handlers')) | |
189 | handlers.extend(load_handlers('nbconvert.handlers')) |
|
189 | handlers.extend(load_handlers('nbconvert.handlers')) | |
|
190 | handlers.extend(load_handlers('kernelspecs.handlers')) | |||
190 | handlers.extend(load_handlers('services.kernels.handlers')) |
|
191 | handlers.extend(load_handlers('services.kernels.handlers')) | |
191 | handlers.extend(load_handlers('services.notebooks.handlers')) |
|
192 | handlers.extend(load_handlers('services.notebooks.handlers')) | |
192 | handlers.extend(load_handlers('services.clusters.handlers')) |
|
193 | handlers.extend(load_handlers('services.clusters.handlers')) |
@@ -41,31 +41,11 b' class KernelSpecHandler(IPythonHandler):' | |||||
41 | self.finish(kernelspec.to_json()) |
|
41 | self.finish(kernelspec.to_json()) | |
42 |
|
42 | |||
43 |
|
43 | |||
44 | class KernelSpecResourceHandler(web.StaticFileHandler, IPythonHandler): |
|
|||
45 | SUPPORTED_METHODS = ('GET', 'HEAD') |
|
|||
46 |
|
||||
47 | def initialize(self): |
|
|||
48 | web.StaticFileHandler.initialize(self, path='') |
|
|||
49 |
|
||||
50 | def get(self, kernel_name, path, include_body=True): |
|
|||
51 | ksm = self.kernel_spec_manager |
|
|||
52 | try: |
|
|||
53 | self.root = ksm.get_kernel_spec(kernel_name).resource_dir |
|
|||
54 | except KeyError: |
|
|||
55 | raise web.HTTPError(404, u'Kernel spec %s not found' % kernel_name) |
|
|||
56 | self.log.debug("Serving kernel resource from: %s", self.root) |
|
|||
57 | return web.StaticFileHandler.get(self, path, include_body=include_body) |
|
|||
58 |
|
||||
59 | def head(self, kernel_name, path): |
|
|||
60 | self.get(kernel_name, path, include_body=False) |
|
|||
61 |
|
||||
62 |
|
||||
63 | # URL to handler mappings |
|
44 | # URL to handler mappings | |
64 |
|
45 | |||
65 |
|
|
46 | kernel_name_regex = r"(?P<kernel_name>\w+)" | |
66 |
|
47 | |||
67 | default_handlers = [ |
|
48 | default_handlers = [ | |
68 | (r"/api/kernelspecs", MainKernelSpecHandler), |
|
49 | (r"/api/kernelspecs", MainKernelSpecHandler), | |
69 |
(r"/api/kernelspecs/%s" % |
|
50 | (r"/api/kernelspecs/%s" % kernel_name_regex, KernelSpecHandler), | |
70 | (r"/api/kernelspecs/%s/(?P<path>.*)" % _kernel_name_regex, KernelSpecResourceHandler), |
|
|||
71 | ] |
|
51 | ] |
@@ -30,20 +30,20 b' class KernelSpecAPI(object):' | |||||
30 |
|
30 | |||
31 | def _req(self, verb, path, body=None): |
|
31 | def _req(self, verb, path, body=None): | |
32 | response = requests.request(verb, |
|
32 | response = requests.request(verb, | |
33 |
url_path_join(self.base_url, |
|
33 | url_path_join(self.base_url, path), | |
34 | data=body, |
|
34 | data=body, | |
35 | ) |
|
35 | ) | |
36 | response.raise_for_status() |
|
36 | response.raise_for_status() | |
37 | return response |
|
37 | return response | |
38 |
|
38 | |||
39 | def list(self): |
|
39 | def list(self): | |
40 | return self._req('GET', '') |
|
40 | return self._req('GET', 'api/kernelspecs') | |
41 |
|
41 | |||
42 | def kernel_spec_info(self, name): |
|
42 | def kernel_spec_info(self, name): | |
43 | return self._req('GET', name) |
|
43 | return self._req('GET', url_path_join('api/kernelspecs', name)) | |
44 |
|
44 | |||
45 | def kernel_resource(self, name, path): |
|
45 | def kernel_resource(self, name, path): | |
46 | return self._req('GET', url_path_join(name, path)) |
|
46 | return self._req('GET', url_path_join('kernelspecs', name, path)) | |
47 |
|
47 | |||
48 | class APITest(NotebookTestBase): |
|
48 | class APITest(NotebookTestBase): | |
49 | """Test the kernelspec web service API""" |
|
49 | """Test the kernelspec web service API""" |
General Comments 0
You need to be logged in to leave comments.
Login now