##// END OF EJS Templates
Move notebook URL fragment regexen into IPython.html.base.handlers
Thomas Kluyver -
Show More
@@ -355,6 +355,14 b' class TrailingSlashHandler(web.RequestHandler):'
355 self.redirect(self.request.uri.rstrip('/'))
355 self.redirect(self.request.uri.rstrip('/'))
356
356
357 #-----------------------------------------------------------------------------
357 #-----------------------------------------------------------------------------
358 # URL pattern fragments for re-use
359 #-----------------------------------------------------------------------------
360
361 path_regex = r"(?P<path>(?:/.*)*)"
362 notebook_name_regex = r"(?P<name>[^/]+\.ipynb)"
363 notebook_path_regex = "%s/%s" % (path_regex, notebook_name_regex)
364
365 #-----------------------------------------------------------------------------
358 # URL to handler mappings
366 # URL to handler mappings
359 #-----------------------------------------------------------------------------
367 #-----------------------------------------------------------------------------
360
368
@@ -2,7 +2,7 b' import os'
2
2
3 from tornado import web
3 from tornado import web
4
4
5 from ..base.handlers import IPythonHandler
5 from ..base.handlers import IPythonHandler, notebook_path_regex
6 from IPython.nbformat.current import to_notebook_json
6 from IPython.nbformat.current import to_notebook_json
7 from IPython.nbconvert.exporters.export import exporter_map
7 from IPython.nbconvert.exporters.export import exporter_map
8 from IPython.utils import tz
8 from IPython.utils import tz
@@ -74,12 +74,10 b' class NbconvertPostHandler(IPythonHandler):'
74 #-----------------------------------------------------------------------------
74 #-----------------------------------------------------------------------------
75
75
76 _format_regex = r"(?P<format>\w+)"
76 _format_regex = r"(?P<format>\w+)"
77 _path_regex = r"(?P<path>(?:/.*)*)"
77
78 _notebook_name_regex = r"(?P<name>[^/]+\.ipynb)"
79 _notebook_path_regex = "%s/%s" % (_path_regex, _notebook_name_regex)
80
78
81 default_handlers = [
79 default_handlers = [
82 (r"/nbconvert/%s%s" % (_format_regex, _notebook_path_regex),
80 (r"/nbconvert/%s%s" % (_format_regex, notebook_path_regex),
83 NbconvertFileHandler),
81 NbconvertFileHandler),
84 (r"/nbconvert/%s" % _format_regex, NbconvertPostHandler),
82 (r"/nbconvert/%s" % _format_regex, NbconvertPostHandler),
85 ] No newline at end of file
83 ]
@@ -20,8 +20,7 b' import os'
20 from tornado import web
20 from tornado import web
21 HTTPError = web.HTTPError
21 HTTPError = web.HTTPError
22
22
23 from ..base.handlers import IPythonHandler
23 from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
24 from ..services.notebooks.handlers import _notebook_path_regex, _path_regex
25 from ..utils import url_path_join, url_escape
24 from ..utils import url_path_join, url_escape
26
25
27 #-----------------------------------------------------------------------------
26 #-----------------------------------------------------------------------------
@@ -85,7 +84,7 b' class NotebookRedirectHandler(IPythonHandler):'
85
84
86
85
87 default_handlers = [
86 default_handlers = [
88 (r"/notebooks%s" % _notebook_path_regex, NotebookHandler),
87 (r"/notebooks%s" % notebook_path_regex, NotebookHandler),
89 (r"/notebooks%s" % _path_regex, NotebookRedirectHandler),
88 (r"/notebooks%s" % path_regex, NotebookRedirectHandler),
90 ]
89 ]
91
90
@@ -23,7 +23,9 b' from tornado import web'
23 from IPython.html.utils import url_path_join, url_escape
23 from IPython.html.utils import url_path_join, url_escape
24 from IPython.utils.jsonutil import date_default
24 from IPython.utils.jsonutil import date_default
25
25
26 from IPython.html.base.handlers import IPythonHandler, json_errors
26 from IPython.html.base.handlers import (IPythonHandler, json_errors,
27 notebook_path_regex, path_regex,
28 notebook_name_regex)
27
29
28 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
29 # Notebook web service handlers
31 # Notebook web service handlers
@@ -264,17 +266,14 b' class ModifyNotebookCheckpointsHandler(IPythonHandler):'
264 #-----------------------------------------------------------------------------
266 #-----------------------------------------------------------------------------
265
267
266
268
267 _path_regex = r"(?P<path>(?:/.*)*)"
268 _checkpoint_id_regex = r"(?P<checkpoint_id>[\w-]+)"
269 _checkpoint_id_regex = r"(?P<checkpoint_id>[\w-]+)"
269 _notebook_name_regex = r"(?P<name>[^/]+\.ipynb)"
270 _notebook_path_regex = "%s/%s" % (_path_regex, _notebook_name_regex)
271
270
272 default_handlers = [
271 default_handlers = [
273 (r"/api/notebooks%s/checkpoints" % _notebook_path_regex, NotebookCheckpointsHandler),
272 (r"/api/notebooks%s/checkpoints" % notebook_path_regex, NotebookCheckpointsHandler),
274 (r"/api/notebooks%s/checkpoints/%s" % (_notebook_path_regex, _checkpoint_id_regex),
273 (r"/api/notebooks%s/checkpoints/%s" % (notebook_path_regex, _checkpoint_id_regex),
275 ModifyNotebookCheckpointsHandler),
274 ModifyNotebookCheckpointsHandler),
276 (r"/api/notebooks%s" % _notebook_path_regex, NotebookHandler),
275 (r"/api/notebooks%s" % notebook_path_regex, NotebookHandler),
277 (r"/api/notebooks%s" % _path_regex, NotebookHandler),
276 (r"/api/notebooks%s" % path_regex, NotebookHandler),
278 ]
277 ]
279
278
280
279
@@ -18,9 +18,8 b' Authors:'
18 import os
18 import os
19
19
20 from tornado import web
20 from tornado import web
21 from ..base.handlers import IPythonHandler
21 from ..base.handlers import IPythonHandler, notebook_path_regex, path_regex
22 from ..utils import url_path_join, path2url, url2path, url_escape
22 from ..utils import url_path_join, path2url, url2path, url_escape
23 from ..services.notebooks.handlers import _notebook_path_regex, _path_regex
24
23
25 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
26 # Handlers
25 # Handlers
@@ -70,8 +69,8 b' class TreeRedirectHandler(IPythonHandler):'
70
69
71
70
72 default_handlers = [
71 default_handlers = [
73 (r"/tree%s" % _notebook_path_regex, TreeHandler),
72 (r"/tree%s" % notebook_path_regex, TreeHandler),
74 (r"/tree%s" % _path_regex, TreeHandler),
73 (r"/tree%s" % path_regex, TreeHandler),
75 (r"/tree", TreeHandler),
74 (r"/tree", TreeHandler),
76 (r"/", TreeRedirectHandler),
75 (r"/", TreeRedirectHandler),
77 ]
76 ]
General Comments 0
You need to be logged in to leave comments. Login now