Show More
@@ -27,7 +27,7 b' except ImportError:' | |||
|
27 | 27 | from IPython.config import Application |
|
28 | 28 | from IPython.utils.path import filefind |
|
29 | 29 | from IPython.utils.py3compat import string_types |
|
30 | from IPython.html.utils import is_hidden | |
|
30 | from IPython.html.utils import is_hidden, url_path_join, url_escape | |
|
31 | 31 | |
|
32 | 32 | #----------------------------------------------------------------------------- |
|
33 | 33 | # Top-level handlers |
@@ -409,6 +409,37 b' class TrailingSlashHandler(web.RequestHandler):' | |||
|
409 | 409 | def get(self): |
|
410 | 410 | self.redirect(self.request.uri.rstrip('/')) |
|
411 | 411 | |
|
412 | ||
|
413 | class FilesRedirectHandler(IPythonHandler): | |
|
414 | """Handler for redirecting relative URLs to the /files/ handler""" | |
|
415 | def get(self, path=''): | |
|
416 | cm = self.contents_manager | |
|
417 | if cm.path_exists(path): | |
|
418 | # it's a *directory*, redirect to /tree | |
|
419 | url = url_path_join(self.base_url, 'tree', path) | |
|
420 | else: | |
|
421 | orig_path = path | |
|
422 | # otherwise, redirect to /files | |
|
423 | parts = path.split('/') | |
|
424 | path = '/'.join(parts[:-1]) | |
|
425 | name = parts[-1] | |
|
426 | ||
|
427 | if not cm.file_exists(name=name, path=path) and 'files' in parts: | |
|
428 | # redirect without files/ iff it would 404 | |
|
429 | # this preserves pre-2.0-style 'files/' links | |
|
430 | self.log.warn("Deprecated files/ URL: %s", orig_path) | |
|
431 | parts.remove('files') | |
|
432 | path = '/'.join(parts[:-1]) | |
|
433 | ||
|
434 | if not cm.file_exists(name=name, path=path): | |
|
435 | raise web.HTTPError(404) | |
|
436 | ||
|
437 | url = url_path_join(self.base_url, 'files', path, name) | |
|
438 | url = url_escape(url) | |
|
439 | self.log.debug("Redirecting %s to %s", self.request.path, url) | |
|
440 | self.redirect(url) | |
|
441 | ||
|
442 | ||
|
412 | 443 | #----------------------------------------------------------------------------- |
|
413 | 444 | # URL pattern fragments for re-use |
|
414 | 445 | #----------------------------------------------------------------------------- |
@@ -9,7 +9,10 b' import zipfile' | |||
|
9 | 9 | |
|
10 | 10 | from tornado import web |
|
11 | 11 | |
|
12 |
from ..base.handlers import |
|
|
12 | from ..base.handlers import ( | |
|
13 | IPythonHandler, FilesRedirectHandler, | |
|
14 | notebook_path_regex, path_regex, | |
|
15 | ) | |
|
13 | 16 | from IPython.nbformat.current import to_notebook_json |
|
14 | 17 | |
|
15 | 18 | from IPython.utils.py3compat import cast_bytes |
@@ -128,6 +131,7 b' class NbconvertPostHandler(IPythonHandler):' | |||
|
128 | 131 | |
|
129 | 132 | self.finish(output) |
|
130 | 133 | |
|
134 | ||
|
131 | 135 | #----------------------------------------------------------------------------- |
|
132 | 136 | # URL to handler mappings |
|
133 | 137 | #----------------------------------------------------------------------------- |
@@ -139,4 +143,5 b' default_handlers = [' | |||
|
139 | 143 | (r"/nbconvert/%s%s" % (_format_regex, notebook_path_regex), |
|
140 | 144 | NbconvertFileHandler), |
|
141 | 145 | (r"/nbconvert/%s" % _format_regex, NbconvertPostHandler), |
|
146 | (r"/nbconvert/html%s" % path_regex, FilesRedirectHandler), | |
|
142 | 147 | ] |
@@ -1,31 +1,17 b'' | |||
|
1 | """Tornado handlers for the live notebook view. | |
|
1 | """Tornado handlers for the live notebook view.""" | |
|
2 | 2 | |
|
3 | Authors: | |
|
4 | ||
|
5 | * Brian Granger | |
|
6 | """ | |
|
7 | ||
|
8 | #----------------------------------------------------------------------------- | |
|
9 | # Copyright (C) 2011 The IPython Development Team | |
|
10 | # | |
|
11 | # Distributed under the terms of the BSD License. The full license is in | |
|
12 | # the file COPYING, distributed as part of this software. | |
|
13 | #----------------------------------------------------------------------------- | |
|
14 | ||
|
15 | #----------------------------------------------------------------------------- | |
|
16 | # Imports | |
|
17 | #----------------------------------------------------------------------------- | |
|
3 | # Copyright (c) IPython Development Team. | |
|
4 | # Distributed under the terms of the Modified BSD License. | |
|
18 | 5 | |
|
19 | 6 | import os |
|
20 | 7 | from tornado import web |
|
21 | 8 | HTTPError = web.HTTPError |
|
22 | 9 | |
|
23 | from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex | |
|
24 | from ..utils import url_path_join, url_escape | |
|
25 | ||
|
26 | #----------------------------------------------------------------------------- | |
|
27 | # Handlers | |
|
28 | #----------------------------------------------------------------------------- | |
|
10 | from ..base.handlers import ( | |
|
11 | IPythonHandler, FilesRedirectHandler, | |
|
12 | notebook_path_regex, path_regex, | |
|
13 | ) | |
|
14 | from ..utils import url_escape | |
|
29 | 15 | |
|
30 | 16 | |
|
31 | 17 | class NotebookHandler(IPythonHandler): |
@@ -53,33 +39,6 b' class NotebookHandler(IPythonHandler):' | |||
|
53 | 39 | ) |
|
54 | 40 | ) |
|
55 | 41 | |
|
56 | class NotebookRedirectHandler(IPythonHandler): | |
|
57 | def get(self, path=''): | |
|
58 | cm = self.contents_manager | |
|
59 | if cm.path_exists(path): | |
|
60 | # it's a *directory*, redirect to /tree | |
|
61 | url = url_path_join(self.base_url, 'tree', path) | |
|
62 | else: | |
|
63 | orig_path = path | |
|
64 | # otherwise, redirect to /files | |
|
65 | parts = path.split('/') | |
|
66 | path = '/'.join(parts[:-1]) | |
|
67 | name = parts[-1] | |
|
68 | ||
|
69 | if not cm.file_exists(name=name, path=path) and 'files' in parts: | |
|
70 | # redirect without files/ iff it would 404 | |
|
71 | # this preserves pre-2.0-style 'files/' links | |
|
72 | self.log.warn("Deprecated files/ URL: %s", orig_path) | |
|
73 | parts.remove('files') | |
|
74 | path = '/'.join(parts[:-1]) | |
|
75 | ||
|
76 | if not cm.file_exists(name=name, path=path): | |
|
77 | raise web.HTTPError(404) | |
|
78 | ||
|
79 | url = url_path_join(self.base_url, 'files', path, name) | |
|
80 | url = url_escape(url) | |
|
81 | self.log.debug("Redirecting %s to %s", self.request.path, url) | |
|
82 | self.redirect(url) | |
|
83 | 42 | |
|
84 | 43 | #----------------------------------------------------------------------------- |
|
85 | 44 | # URL to handler mappings |
@@ -88,6 +47,6 b' class NotebookRedirectHandler(IPythonHandler):' | |||
|
88 | 47 | |
|
89 | 48 | default_handlers = [ |
|
90 | 49 | (r"/notebooks%s" % notebook_path_regex, NotebookHandler), |
|
91 |
(r"/notebooks%s" % path_regex, |
|
|
50 | (r"/notebooks%s" % path_regex, FilesRedirectHandler), | |
|
92 | 51 | ] |
|
93 | 52 |
General Comments 0
You need to be logged in to leave comments.
Login now