##// END OF EJS Templates
Correct %edit docstring for ZMQ shell
Correct %edit docstring for ZMQ shell

File last commit:

r13563:0be1a702
r13599:e7823f0c
Show More
handlers.py
91 lines | 3.3 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
#-----------------------------------------------------------------------------
MinRK
support 1.0-style `files/` relative URLs...
r13563 import os
Brian E. Granger
Adding new files.
r10641 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
MinRK
adjust definition of 'path' in notebooks...
r13067 from ..services.notebooks.handlers import _notebook_path_regex, _path_regex
Thomas Kluyver
Remove unused imports in IPython.html.notebook.handlers
r13398 from ..utils import url_path_join, url_escape
Brian E. Granger
Adding new files.
r10641
#-----------------------------------------------------------------------------
Brian E. Granger
Splitting handlers into different files....
r10642 # Handlers
Brian E. Granger
Adding new files.
r10641 #-----------------------------------------------------------------------------
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016 class NotebookHandler(IPythonHandler):
Brian E. Granger
Adding new files.
r10641
@web.authenticated
MinRK
adjust definition of 'path' in notebooks...
r13067 def get(self, path='', name=None):
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 """get renders the notebook template if a name is given, or
redirects to the '/files/' handler if the name is not given."""
MinRK
strip '/' from paths in template-render handlers
r13117 path = path.strip('/')
Brian E. Granger
Adding new files.
r10641 nbm = self.notebook_manager
MinRK
adjust definition of 'path' in notebooks...
r13067 if name is None:
MinRK
cleanup old, unused `/notebooks/foo` API methods...
r13073 raise web.HTTPError(500, "This shouldn't be accessible: %s" % self.request.uri)
MinRK
adjust definition of 'path' in notebooks...
r13067 # a .ipynb filename was given
if not nbm.notebook_exists(name, path):
raise web.HTTPError(404, u'Notebook does not exist: %s/%s' % (path, name))
MinRK
move url_[un]escape to utils from nbm
r13068 name = url_escape(name)
path = url_escape(path)
MinRK
adjust definition of 'path' in notebooks...
r13067 self.write(self.render_template('notebook.html',
project=self.project_dir,
notebook_path=path,
notebook_name=name,
kill_kernel=False,
mathjax_url=self.mathjax_url,
)
)
Zachary Sailer
removed '/new' URL and added POST notebook request
r13016
MinRK
cleanup old, unused `/notebooks/foo` API methods...
r13073 class NotebookRedirectHandler(IPythonHandler):
def get(self, path=''):
Zachary Sailer
Change new/copy URLS to POST requests
r13017 nbm = self.notebook_manager
MinRK
cleanup old, unused `/notebooks/foo` API methods...
r13073 if nbm.path_exists(path):
# it's a *directory*, redirect to /tree
url = url_path_join(self.base_project_url, 'tree', path)
Paul Ivanov
named_notebook_path: consistent usage convention
r13029 else:
MinRK
cleanup old, unused `/notebooks/foo` API methods...
r13073 # otherwise, redirect to /files
MinRK
support 1.0-style `files/` relative URLs...
r13563 if '/files/' in path:
# redirect without files/ iff it would 404
# this preserves pre-2.0-style 'files/' links
# FIXME: this is hardcoded based on notebook_path,
# but so is the files handler itself,
# so it should work until both are cleaned up.
parts = path.split('/')
files_path = os.path.join(nbm.notebook_dir, *parts)
self.log.warn("filespath: %s", files_path)
if not os.path.exists(files_path):
path = path.replace('/files/', '/', 1)
MinRK
cleanup old, unused `/notebooks/foo` API methods...
r13073 url = url_path_join(self.base_project_url, 'files', path)
MinRK
url_escape redirects
r13135 url = url_escape(url)
self.log.debug("Redirecting %s to %s", self.request.path, url)
MinRK
cleanup old, unused `/notebooks/foo` API methods...
r13073 self.redirect(url)
Brian E. Granger
Adding new files.
r10641
Brian E. Granger
More work on the handlers
r10647 #-----------------------------------------------------------------------------
# URL to handler mappings
#-----------------------------------------------------------------------------
default_handlers = [
MinRK
simplify handler patterns...
r13079 (r"/notebooks%s" % _notebook_path_regex, NotebookHandler),
(r"/notebooks%s" % _path_regex, NotebookRedirectHandler),
Zachary Sailer
fixing broken links from recent changes....
r13033 ]