##// END OF EJS Templates
Fix clashes between debugger tests and coverage.py...
Fix clashes between debugger tests and coverage.py coverage.py works by setting the trace function. But so does the debugger, so we need to re-set it afterwards to get accurate coverage results.

File last commit:

r11644:961067ee
r12286:fab155c9
Show More
handlers.py
91 lines | 2.8 KiB | text/x-python | PythonLexer
Brian E. Granger
Splitting handlers into different files....
r10642 """Tornado handlers for the live notebook view.
Brian E. Granger
Adding new files.
r10641
Authors:
* Brian Granger
"""
#-----------------------------------------------------------------------------
Brian E. Granger
Splitting handlers into different files....
r10642 # Copyright (C) 2011 The IPython Development Team
Brian E. Granger
Adding new files.
r10641 #
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
import os
from tornado import web
Brian E. Granger
Splitting handlers into different files....
r10642 HTTPError = web.HTTPError
Brian E. Granger
Adding new files.
r10641
MinRK
remove notebook read-only view...
r11644 from ..base.handlers import IPythonHandler
Brian E. Granger
Splitting handlers into different files....
r10642 from ..utils import url_path_join
Brian E. Granger
Adding new files.
r10641
#-----------------------------------------------------------------------------
Brian E. Granger
Splitting handlers into different files....
r10642 # Handlers
Brian E. Granger
Adding new files.
r10641 #-----------------------------------------------------------------------------
class NewHandler(IPythonHandler):
@web.authenticated
def get(self):
notebook_id = self.notebook_manager.new_notebook()
Brian E. Granger
Fixing url join problems.
r10644 self.redirect(url_path_join(self.base_project_url, notebook_id))
Brian E. Granger
Splitting handlers into different files....
r10642
Brian E. Granger
Adding new files.
r10641
class NamedNotebookHandler(IPythonHandler):
MinRK
remove notebook read-only view...
r11644 @web.authenticated
Brian E. Granger
Adding new files.
r10641 def get(self, notebook_id):
nbm = self.notebook_manager
if not nbm.notebook_exists(notebook_id):
raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
Brian E. Granger
Creating override.css for each page....
r10723 self.write(self.render_template('notebook.html',
Brian E. Granger
Adding new files.
r10641 project=self.project,
notebook_id=notebook_id,
kill_kernel=False,
mathjax_url=self.mathjax_url,
)
)
class NotebookRedirectHandler(IPythonHandler):
MinRK
remove notebook read-only view...
r11644 @web.authenticated
Brian E. Granger
Adding new files.
r10641 def get(self, notebook_name):
# strip trailing .ipynb:
notebook_name = os.path.splitext(notebook_name)[0]
notebook_id = self.notebook_manager.rev_mapping.get(notebook_name, '')
if notebook_id:
Brian E. Granger
Fixing url join problems.
r10644 url = url_path_join(self.settings.get('base_project_url', '/'), notebook_id)
Brian E. Granger
Adding new files.
r10641 return self.redirect(url)
else:
raise HTTPError(404)
class NotebookCopyHandler(IPythonHandler):
@web.authenticated
def get(self, notebook_id):
notebook_id = self.notebook_manager.copy_notebook(notebook_id)
Brian E. Granger
Fixing url join problems.
r10644 self.redirect(url_path_join(self.base_project_url, notebook_id))
Brian E. Granger
Adding new files.
r10641
Brian E. Granger
More work on the handlers
r10647
#-----------------------------------------------------------------------------
# URL to handler mappings
#-----------------------------------------------------------------------------
_notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
_notebook_name_regex = r"(?P<notebook_name>.+\.ipynb)"
default_handlers = [
(r"/new", NewHandler),
(r"/%s" % _notebook_id_regex, NamedNotebookHandler),
(r"/%s" % _notebook_name_regex, NotebookRedirectHandler),
(r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
]