##// END OF EJS Templates
More work on the handlers
Brian E. Granger -
Show More
@@ -274,3 +274,11 class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
274 274 @authenticate_unless_readonly
275 275 def get(self, path):
276 276 return web.StaticFileHandler.get(self, path)
277
278
279 #-----------------------------------------------------------------------------
280 # URL to handler mappings
281 #-----------------------------------------------------------------------------
282
283
284 default_handlers = []
@@ -55,3 +55,18 class ClusterActionHandler(IPythonHandler):
55 55 if action == 'stop':
56 56 data = cm.stop_cluster(profile)
57 57 self.finish(jsonapi.dumps(data))
58
59
60 #-----------------------------------------------------------------------------
61 # URL to handler mappings
62 #-----------------------------------------------------------------------------
63
64
65 _cluster_action_regex = r"(?P<action>start|stop)"
66 _profile_regex = r"(?P<profile>[^\/]+)" # there is almost no text that is invalid
67
68 default_handlers = [
69 (r"/clusters", MainClusterHandler),
70 (r"/clusters/%s/%s" % (_profile_regex, _cluster_action_regex), ClusterActionHandler),
71 (r"/clusters/%s" % _profile_regex, ClusterProfileHandler),
72 ]
@@ -244,8 +244,28 class IOPubHandler(ZMQChannelHandler):
244 244 """IOPub messages make no sense"""
245 245 pass
246 246
247
247 248 class ShellHandler(ZMQChannelHandler):
248 249 channel = 'shell'
249 250
251
250 252 class StdinHandler(ZMQChannelHandler):
251 253 channel = 'stdin'
254
255
256 #-----------------------------------------------------------------------------
257 # URL to handler mappings
258 #-----------------------------------------------------------------------------
259
260
261 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
262 _kernel_action_regex = r"(?P<action>restart|interrupt)"
263
264 default_handlers = [
265 (r"/kernels", MainKernelHandler),
266 (r"/kernels/%s" % _kernel_id_regex, KernelHandler),
267 (r"/kernels/%s/%s" % (_kernel_id_regex, _kernel_action_regex), KernelActionHandler),
268 (r"/kernels/%s/iopub" % _kernel_id_regex, IOPubHandler),
269 (r"/kernels/%s/shell" % _kernel_id_regex, ShellHandler),
270 (r"/kernels/%s/stdin" % _kernel_id_regex, StdinHandler)
271 ]
@@ -28,7 +28,6 from .base import IPythonHandler
28 28 # Handler
29 29 #-----------------------------------------------------------------------------
30 30
31
32 31 class LoginHandler(IPythonHandler):
33 32
34 33 def _render(self, message=None):
@@ -55,3 +54,9 class LoginHandler(IPythonHandler):
55 54 self.redirect(self.get_argument('next', default=self.base_project_url))
56 55
57 56
57 #-----------------------------------------------------------------------------
58 # URL to handler mappings
59 #-----------------------------------------------------------------------------
60
61
62 default_handlers = [(r"/login", LoginHandler)]
@@ -34,3 +34,11 class LogoutHandler(IPythonHandler):
34 34 'is disabled.'}
35 35 self.write(self.render_template('logout.html',
36 36 message=message))
37
38
39 #-----------------------------------------------------------------------------
40 # URL to handler mappings
41 #-----------------------------------------------------------------------------
42
43
44 default_handlers = [(r"/logout", LogoutHandler)] No newline at end of file
@@ -73,3 +73,19 class NotebookCopyHandler(IPythonHandler):
73 73 notebook_id = self.notebook_manager.copy_notebook(notebook_id)
74 74 self.redirect(url_path_join(self.base_project_url, notebook_id))
75 75
76
77 #-----------------------------------------------------------------------------
78 # URL to handler mappings
79 #-----------------------------------------------------------------------------
80
81
82 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
83 _notebook_name_regex = r"(?P<notebook_name>.+\.ipynb)"
84
85 default_handlers = [
86 (r"/new", NewHandler),
87 (r"/%s" % _notebook_id_regex, NamedNotebookHandler),
88 (r"/%s" % _notebook_name_regex, NotebookRedirectHandler),
89 (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
90
91 ]
@@ -134,5 +134,23 class ModifyNotebookCheckpointsHandler(IPythonHandler):
134 134 self.finish()
135 135
136 136
137 #-----------------------------------------------------------------------------
138 # URL to handler mappings
139 #-----------------------------------------------------------------------------
140
141
142 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
143 _checkpoint_id_regex = r"(?P<checkpoint_id>[\w-]+)"
144
145 default_handlers = [
146 (r"/notebooks", NotebookRootHandler),
147 (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler),
148 (r"/notebooks/%s/checkpoints" % _notebook_id_regex, NotebookCheckpointsHandler),
149 (r"/notebooks/%s/checkpoints/%s" % (_notebook_id_regex, _checkpoint_id_regex),
150 ModifyNotebookCheckpointsHandler
151 ),
152 ]
153
154
137 155
138 156
@@ -31,3 +31,11 class ProjectDashboardHandler(IPythonHandler):
31 31 project=self.project,
32 32 project_component=self.project.split('/'),
33 33 ))
34
35
36 #-----------------------------------------------------------------------------
37 # URL to handler mappings
38 #-----------------------------------------------------------------------------
39
40
41 default_handlers = [(r"/", ProjectDashboardHandler)] No newline at end of file
@@ -115,14 +115,6 from .utils import url_path_join
115 115 # Module globals
116 116 #-----------------------------------------------------------------------------
117 117
118 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
119 _kernel_action_regex = r"(?P<action>restart|interrupt)"
120 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
121 _notebook_name_regex = r"(?P<notebook_name>.+\.ipynb)"
122 _checkpoint_id_regex = r"(?P<checkpoint_id>[\w-]+)"
123 _profile_regex = r"(?P<profile>[^\/]+)" # there is almost no text that is invalid
124 _cluster_action_regex = r"(?P<action>start|stop)"
125
126 118 _examples = """
127 119 ipython notebook # start the notebook
128 120 ipython notebook --profile=sympy # use the sympy profile
@@ -146,6 +138,12 def random_ports(port, n):
146 138 for i in range(n-5):
147 139 yield port + random.randint(-2*n, 2*n)
148 140
141 def load_handlers(name):
142 """Load the (URL pattern, handler) tuples for each component."""
143 name = 'IPython.frontend.html.notebook.handlers.' + name
144 mod = __import__(name, fromlist=['default_handlers'])
145 return mod.default_handlers
146
149 147 #-----------------------------------------------------------------------------
150 148 # The Tornado web application
151 149 #-----------------------------------------------------------------------------
@@ -155,31 +153,20 class NotebookWebApplication(web.Application):
155 153 def __init__(self, ipython_app, kernel_manager, notebook_manager,
156 154 cluster_manager, log,
157 155 base_project_url, settings_overrides):
158 handlers = [
159 (r"/", ProjectDashboardHandler),
160 (r"/login", LoginHandler),
161 (r"/logout", LogoutHandler),
162 (r"/new", NewHandler),
163 (r"/%s" % _notebook_id_regex, NamedNotebookHandler),
164 (r"/%s" % _notebook_name_regex, NotebookRedirectHandler),
165 (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
166 (r"/kernels", MainKernelHandler),
167 (r"/kernels/%s" % _kernel_id_regex, KernelHandler),
168 (r"/kernels/%s/%s" % (_kernel_id_regex, _kernel_action_regex), KernelActionHandler),
169 (r"/kernels/%s/iopub" % _kernel_id_regex, IOPubHandler),
170 (r"/kernels/%s/shell" % _kernel_id_regex, ShellHandler),
171 (r"/kernels/%s/stdin" % _kernel_id_regex, StdinHandler),
172 (r"/notebooks", NotebookRootHandler),
173 (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler),
174 (r"/notebooks/%s/checkpoints" % _notebook_id_regex, NotebookCheckpointsHandler),
175 (r"/notebooks/%s/checkpoints/%s" % (_notebook_id_regex, _checkpoint_id_regex),
176 ModifyNotebookCheckpointsHandler
177 ),
156
157 # Load the (URL pattern, handler) tuples for each component.
158 handlers = []
159 handlers.extend(load_handlers('base'))
160 handlers.extend(load_handlers('tree'))
161 handlers.extend(load_handlers('login'))
162 handlers.extend(load_handlers('logout'))
163 handlers.extend(load_handlers('notebooks'))
164 handlers.extend(load_handlers('kernelsapi'))
165 handlers.extend(load_handlers('notebooksapi'))
166 handlers.extend(load_handlers('clustersapi'))
167 handlers.extend([
178 168 (r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}),
179 (r"/clusters", MainClusterHandler),
180 (r"/clusters/%s/%s" % (_profile_regex, _cluster_action_regex), ClusterActionHandler),
181 (r"/clusters/%s" % _profile_regex, ClusterProfileHandler),
182 ]
169 ])
183 170
184 171 # Python < 2.6.5 doesn't accept unicode keys in f(**kwargs), and
185 172 # base_project_url will always be unicode, which will in turn
General Comments 0
You need to be logged in to leave comments. Login now