Show More
@@ -1,8 +1,9 b'' | |||||
|
1 | import json | |||
1 | import os |
|
2 | import os | |
2 |
|
3 | |||
3 | from tornado import web |
|
4 | from tornado import web | |
4 |
|
5 | |||
5 | from ..base.handlers import IPythonHandler |
|
6 | from ..base.handlers import IPythonHandler, json_errors | |
6 | from IPython.nbformat.current import to_notebook_json |
|
7 | from IPython.nbformat.current import to_notebook_json | |
7 | from IPython.nbconvert.exporters.export import exporter_map |
|
8 | from IPython.nbconvert.exporters.export import exporter_map | |
8 | from IPython.utils import tz |
|
9 | from IPython.utils import tz | |
@@ -69,6 +70,19 b' class NbconvertPostHandler(IPythonHandler):' | |||||
69 |
|
70 | |||
70 | self.finish(output) |
|
71 | self.finish(output) | |
71 |
|
72 | |||
|
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 | ||||
72 | #----------------------------------------------------------------------------- |
|
86 | #----------------------------------------------------------------------------- | |
73 | # URL to handler mappings |
|
87 | # URL to handler mappings | |
74 | #----------------------------------------------------------------------------- |
|
88 | #----------------------------------------------------------------------------- | |
@@ -82,4 +96,5 b' default_handlers = [' | |||||
82 | (r"/nbconvert/%s%s" % (_format_regex, _notebook_path_regex), |
|
96 | (r"/nbconvert/%s%s" % (_format_regex, _notebook_path_regex), | |
83 | NbconvertFileHandler), |
|
97 | NbconvertFileHandler), | |
84 | (r"/nbconvert/%s" % _format_regex, NbconvertPostHandler), |
|
98 | (r"/nbconvert/%s" % _format_regex, NbconvertPostHandler), | |
|
99 | (r"/nbconvert", NbconvertRootHandler), | |||
85 | ] No newline at end of file |
|
100 | ] |
@@ -32,6 +32,9 b' class NbconvertAPI(object):' | |||||
32 | body = json.dumps(nbmodel) |
|
32 | body = json.dumps(nbmodel) | |
33 | return self._req('POST', format, body) |
|
33 | return self._req('POST', format, body) | |
34 |
|
34 | |||
|
35 | def list_formats(self): | |||
|
36 | return self._req('GET', '') | |||
|
37 | ||||
35 | class APITest(NotebookTestBase): |
|
38 | class APITest(NotebookTestBase): | |
36 | def setUp(self): |
|
39 | def setUp(self): | |
37 | nbdir = self.notebook_dir.name |
|
40 | nbdir = self.notebook_dir.name | |
@@ -92,3 +95,10 b' class APITest(NotebookTestBase):' | |||||
92 | r = self.nbconvert_api.from_post(format='python', nbmodel=nbmodel) |
|
95 | r = self.nbconvert_api.from_post(format='python', nbmodel=nbmodel) | |
93 | self.assertIn(u'text/x-python', r.headers['Content-Type']) |
|
96 | self.assertIn(u'text/x-python', r.headers['Content-Type']) | |
94 | self.assertIn(u'print(2*6)', r.text) |
|
97 | 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 |
General Comments 0
You need to be logged in to leave comments.
Login now