handlers.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import json
  2. from tornado import web
  3. from ...base.handlers import APIHandler
  4. class NbconvertRootHandler(APIHandler):
  5. @web.authenticated
  6. def get(self):
  7. self.check_xsrf_cookie()
  8. try:
  9. from nbconvert.exporters import base
  10. except ImportError as e:
  11. raise web.HTTPError(500, "Could not import nbconvert: %s" % e)
  12. res = {}
  13. exporters = base.get_export_names()
  14. for exporter_name in exporters:
  15. try:
  16. exporter_class = base.get_exporter(exporter_name)
  17. except ValueError:
  18. # I think the only way this will happen is if the entrypoint
  19. # is uninstalled while this method is running
  20. continue
  21. # XXX: According to the docs, it looks like this should be set to None
  22. # if the exporter shouldn't be exposed to the front-end and a friendly
  23. # name if it should. However, none of the built-in exports have it defined.
  24. # if not exporter_class.export_from_notebook:
  25. # continue
  26. res[exporter_name] = {
  27. "output_mimetype": exporter_class.output_mimetype,
  28. }
  29. self.finish(json.dumps(res))
  30. default_handlers = [
  31. (r"/api/nbconvert", NbconvertRootHandler),
  32. ]