##// END OF EJS Templates
change default dir permissions to 755...
change default dir permissions to 755 777 is a weird default

File last commit:

r15903:e656f069
r16488:d0d1e34f
Show More
handlers.py
90 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
Thomas Kluyver
Move notebook URL fragment regexen into IPython.html.base.handlers
r13916 from ..base.handlers import IPythonHandler, 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
MinRK
s/base_project_url/base_url/...
r15238 url = url_path_join(self.base_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)
if not os.path.exists(files_path):
MinRK
better log message in deprecated files/ redirect
r15903 self.log.warn("Deprecated files/ URL: %s", path)
MinRK
support 1.0-style `files/` relative URLs...
r13563 path = path.replace('/files/', '/', 1)
MinRK
s/base_project_url/base_url/...
r15238 url = url_path_join(self.base_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 = [
Thomas Kluyver
Move notebook URL fragment regexen into IPython.html.base.handlers
r13916 (r"/notebooks%s" % notebook_path_regex, NotebookHandler),
(r"/notebooks%s" % path_regex, NotebookRedirectHandler),
Zachary Sailer
fixing broken links from recent changes....
r13033 ]