handlers.py 878 B

1234567891011121314151617181920212223242526272829
  1. #encoding: utf-8
  2. """Tornado handlers for the terminal emulator."""
  3. # Copyright (c) Jupyter Development Team.
  4. # Distributed under the terms of the Modified BSD License.
  5. from tornado import web
  6. from ..base.handlers import IPythonHandler, path_regex
  7. from ..utils import url_escape
  8. class EditorHandler(IPythonHandler):
  9. """Render the text editor interface."""
  10. @web.authenticated
  11. def get(self, path):
  12. path = path.strip('/')
  13. if not self.contents_manager.file_exists(path):
  14. raise web.HTTPError(404, u'File does not exist: %s' % path)
  15. basename = path.rsplit('/', 1)[-1]
  16. self.write(self.render_template('edit.html',
  17. file_path=url_escape(path),
  18. basename=basename,
  19. page_title=basename + " (editing)",
  20. )
  21. )
  22. default_handlers = [
  23. (r"/edit%s" % path_regex, EditorHandler),
  24. ]