Show More
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,23 b'' | |||||
|
1 | import json | |||
|
2 | ||||
|
3 | from tornado import web | |||
|
4 | ||||
|
5 | from ...base.handlers import IPythonHandler, json_errors | |||
|
6 | from IPython.nbconvert.exporters.export import exporter_map | |||
|
7 | ||||
|
8 | class NbconvertRootHandler(IPythonHandler): | |||
|
9 | SUPPORTED_METHODS = ('GET',) | |||
|
10 | ||||
|
11 | @web.authenticated | |||
|
12 | @json_errors | |||
|
13 | def get(self): | |||
|
14 | res = {} | |||
|
15 | for format, exporter in exporter_map.items(): | |||
|
16 | res[format] = info = {} | |||
|
17 | info['output_mimetype'] = exporter.output_mimetype | |||
|
18 | ||||
|
19 | self.finish(json.dumps(res)) | |||
|
20 | ||||
|
21 | default_handlers = [ | |||
|
22 | (r"/api/nbconvert", NbconvertRootHandler), | |||
|
23 | ] No newline at end of file |
1 | NO CONTENT: new file 100644 |
|
NO CONTENT: new file 100644 |
@@ -0,0 +1,31 b'' | |||||
|
1 | import requests | |||
|
2 | ||||
|
3 | from IPython.html.utils import url_path_join | |||
|
4 | from IPython.html.tests.launchnotebook import NotebookTestBase | |||
|
5 | ||||
|
6 | class NbconvertAPI(object): | |||
|
7 | """Wrapper for nbconvert API calls.""" | |||
|
8 | def __init__(self, base_url): | |||
|
9 | self.base_url = base_url | |||
|
10 | ||||
|
11 | def _req(self, verb, path, body=None, params=None): | |||
|
12 | response = requests.request(verb, | |||
|
13 | url_path_join(self.base_url, 'api/nbconvert', path), | |||
|
14 | data=body, params=params, | |||
|
15 | ) | |||
|
16 | response.raise_for_status() | |||
|
17 | return response | |||
|
18 | ||||
|
19 | def list_formats(self): | |||
|
20 | return self._req('GET', '') | |||
|
21 | ||||
|
22 | class APITest(NotebookTestBase): | |||
|
23 | def setUp(self): | |||
|
24 | self.nbconvert_api = NbconvertAPI(self.base_url()) | |||
|
25 | ||||
|
26 | def test_list_formats(self): | |||
|
27 | formats = self.nbconvert_api.list_formats().json() | |||
|
28 | self.assertIsInstance(formats, dict) | |||
|
29 | self.assertIn('python', formats) | |||
|
30 | self.assertIn('html', formats) | |||
|
31 | self.assertEqual(formats['python']['output_mimetype'], 'text/x-python') No newline at end of file |
@@ -1,9 +1,8 b'' | |||||
1 | import json |
|
|||
2 |
|
|
1 | import os | |
3 |
|
2 | |||
4 | from tornado import web |
|
3 | from tornado import web | |
5 |
|
4 | |||
6 |
from ..base.handlers import IPythonHandler |
|
5 | from ..base.handlers import IPythonHandler | |
7 | from IPython.nbformat.current import to_notebook_json |
|
6 | from IPython.nbformat.current import to_notebook_json | |
8 | from IPython.nbconvert.exporters.export import exporter_map |
|
7 | from IPython.nbconvert.exporters.export import exporter_map | |
9 | from IPython.utils import tz |
|
8 | from IPython.utils import tz | |
@@ -70,19 +69,6 b' class NbconvertPostHandler(IPythonHandler):' | |||||
70 |
|
69 | |||
71 | self.finish(output) |
|
70 | self.finish(output) | |
72 |
|
71 | |||
73 | class NbconvertRootHandler(IPythonHandler): |
|
|||
74 | SUPPORTED_METHODS = ('GET',) |
|
|||
75 |
|
||||
76 | @web.authenticated |
|
|||
77 | @json_errors |
|
|||
78 | def get(self): |
|
|||
79 | res = {} |
|
|||
80 | for format, exporter in exporter_map.items(): |
|
|||
81 | res[format] = info = {} |
|
|||
82 | info['output_mimetype'] = exporter.output_mimetype |
|
|||
83 |
|
||||
84 | self.finish(json.dumps(res)) |
|
|||
85 |
|
||||
86 | #----------------------------------------------------------------------------- |
|
72 | #----------------------------------------------------------------------------- | |
87 | # URL to handler mappings |
|
73 | # URL to handler mappings | |
88 | #----------------------------------------------------------------------------- |
|
74 | #----------------------------------------------------------------------------- | |
@@ -96,5 +82,4 b' default_handlers = [' | |||||
96 | (r"/nbconvert/%s%s" % (_format_regex, _notebook_path_regex), |
|
82 | (r"/nbconvert/%s%s" % (_format_regex, _notebook_path_regex), | |
97 | NbconvertFileHandler), |
|
83 | NbconvertFileHandler), | |
98 | (r"/nbconvert/%s" % _format_regex, NbconvertPostHandler), |
|
84 | (r"/nbconvert/%s" % _format_regex, NbconvertPostHandler), | |
99 | (r"/nbconvert", NbconvertRootHandler), |
|
|||
100 | ] No newline at end of file |
|
85 | ] |
@@ -1,3 +1,4 b'' | |||||
|
1 | # coding: utf-8 | |||
1 | import io |
|
2 | import io | |
2 | import json |
|
3 | import json | |
3 | import os |
|
4 | import os | |
@@ -95,10 +96,3 b' class APITest(NotebookTestBase):' | |||||
95 | r = self.nbconvert_api.from_post(format='python', nbmodel=nbmodel) |
|
96 | r = self.nbconvert_api.from_post(format='python', nbmodel=nbmodel) | |
96 | self.assertIn(u'text/x-python', r.headers['Content-Type']) |
|
97 | self.assertIn(u'text/x-python', r.headers['Content-Type']) | |
97 | self.assertIn(u'print(2*6)', r.text) |
|
98 | self.assertIn(u'print(2*6)', r.text) | |
98 |
|
||||
99 | def test_list_formats(self): |
|
|||
100 | formats = self.nbconvert_api.list_formats().json() |
|
|||
101 | self.assertIsInstance(formats, dict) |
|
|||
102 | self.assertIn('python', formats) |
|
|||
103 | self.assertIn('html', formats) |
|
|||
104 | self.assertEqual(formats['python']['output_mimetype'], 'text/x-python') No newline at end of file |
|
@@ -197,6 +197,7 b' class NotebookWebApplication(web.Application):' | |||||
197 | handlers.extend(load_handlers('services.notebooks.handlers')) |
|
197 | handlers.extend(load_handlers('services.notebooks.handlers')) | |
198 | handlers.extend(load_handlers('services.clusters.handlers')) |
|
198 | handlers.extend(load_handlers('services.clusters.handlers')) | |
199 | handlers.extend(load_handlers('services.sessions.handlers')) |
|
199 | handlers.extend(load_handlers('services.sessions.handlers')) | |
|
200 | handlers.extend(load_handlers('services.nbconvert.handlers')) | |||
200 | handlers.extend([ |
|
201 | handlers.extend([ | |
201 | (r"/files/(.*)", AuthenticatedFileHandler, {'path' : settings['notebook_manager'].notebook_dir}), |
|
202 | (r"/files/(.*)", AuthenticatedFileHandler, {'path' : settings['notebook_manager'].notebook_dir}), | |
202 | (r"/nbextensions/(.*)", FileFindHandler, {'path' : settings['nbextensions_path']}), |
|
203 | (r"/nbextensions/(.*)", FileFindHandler, {'path' : settings['nbextensions_path']}), |
General Comments 0
You need to be logged in to leave comments.
Login now