##// END OF EJS Templates
Merge pull request #1332 from astraw/alternate-url-prefix...
Fernando Perez -
r6012:69c627ca merge
parent child Browse files
Show More
@@ -1,678 +1,686 b''
1 """Tornado handlers for the notebook.
1 """Tornado handlers for the notebook.
2
2
3 Authors:
3 Authors:
4
4
5 * Brian Granger
5 * Brian Granger
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 import logging
19 import logging
20 import Cookie
20 import Cookie
21 import time
21 import time
22 import uuid
22 import uuid
23
23
24 from tornado import web
24 from tornado import web
25 from tornado import websocket
25 from tornado import websocket
26
26
27 from zmq.eventloop import ioloop
27 from zmq.eventloop import ioloop
28 from zmq.utils import jsonapi
28 from zmq.utils import jsonapi
29
29
30 from IPython.external.decorator import decorator
30 from IPython.external.decorator import decorator
31 from IPython.zmq.session import Session
31 from IPython.zmq.session import Session
32 from IPython.lib.security import passwd_check
32 from IPython.lib.security import passwd_check
33
33
34 try:
34 try:
35 from docutils.core import publish_string
35 from docutils.core import publish_string
36 except ImportError:
36 except ImportError:
37 publish_string = None
37 publish_string = None
38
38
39 #-----------------------------------------------------------------------------
39 #-----------------------------------------------------------------------------
40 # Monkeypatch for Tornado <= 2.1.1 - Remove when no longer necessary!
40 # Monkeypatch for Tornado <= 2.1.1 - Remove when no longer necessary!
41 #-----------------------------------------------------------------------------
41 #-----------------------------------------------------------------------------
42
42
43 # Google Chrome, as of release 16, changed its websocket protocol number. The
43 # Google Chrome, as of release 16, changed its websocket protocol number. The
44 # parts tornado cares about haven't really changed, so it's OK to continue
44 # parts tornado cares about haven't really changed, so it's OK to continue
45 # accepting Chrome connections, but as of Tornado 2.1.1 (the currently released
45 # accepting Chrome connections, but as of Tornado 2.1.1 (the currently released
46 # version as of Oct 30/2011) the version check fails, see the issue report:
46 # version as of Oct 30/2011) the version check fails, see the issue report:
47
47
48 # https://github.com/facebook/tornado/issues/385
48 # https://github.com/facebook/tornado/issues/385
49
49
50 # This issue has been fixed in Tornado post 2.1.1:
50 # This issue has been fixed in Tornado post 2.1.1:
51
51
52 # https://github.com/facebook/tornado/commit/84d7b458f956727c3b0d6710
52 # https://github.com/facebook/tornado/commit/84d7b458f956727c3b0d6710
53
53
54 # Here we manually apply the same patch as above so that users of IPython can
54 # Here we manually apply the same patch as above so that users of IPython can
55 # continue to work with an officially released Tornado. We make the
55 # continue to work with an officially released Tornado. We make the
56 # monkeypatch version check as narrow as possible to limit its effects; once
56 # monkeypatch version check as narrow as possible to limit its effects; once
57 # Tornado 2.1.1 is no longer found in the wild we'll delete this code.
57 # Tornado 2.1.1 is no longer found in the wild we'll delete this code.
58
58
59 import tornado
59 import tornado
60
60
61 if tornado.version_info <= (2,1,1):
61 if tornado.version_info <= (2,1,1):
62
62
63 def _execute(self, transforms, *args, **kwargs):
63 def _execute(self, transforms, *args, **kwargs):
64 from tornado.websocket import WebSocketProtocol8, WebSocketProtocol76
64 from tornado.websocket import WebSocketProtocol8, WebSocketProtocol76
65
65
66 self.open_args = args
66 self.open_args = args
67 self.open_kwargs = kwargs
67 self.open_kwargs = kwargs
68
68
69 # The difference between version 8 and 13 is that in 8 the
69 # The difference between version 8 and 13 is that in 8 the
70 # client sends a "Sec-Websocket-Origin" header and in 13 it's
70 # client sends a "Sec-Websocket-Origin" header and in 13 it's
71 # simply "Origin".
71 # simply "Origin".
72 if self.request.headers.get("Sec-WebSocket-Version") in ("7", "8", "13"):
72 if self.request.headers.get("Sec-WebSocket-Version") in ("7", "8", "13"):
73 self.ws_connection = WebSocketProtocol8(self)
73 self.ws_connection = WebSocketProtocol8(self)
74 self.ws_connection.accept_connection()
74 self.ws_connection.accept_connection()
75
75
76 elif self.request.headers.get("Sec-WebSocket-Version"):
76 elif self.request.headers.get("Sec-WebSocket-Version"):
77 self.stream.write(tornado.escape.utf8(
77 self.stream.write(tornado.escape.utf8(
78 "HTTP/1.1 426 Upgrade Required\r\n"
78 "HTTP/1.1 426 Upgrade Required\r\n"
79 "Sec-WebSocket-Version: 8\r\n\r\n"))
79 "Sec-WebSocket-Version: 8\r\n\r\n"))
80 self.stream.close()
80 self.stream.close()
81
81
82 else:
82 else:
83 self.ws_connection = WebSocketProtocol76(self)
83 self.ws_connection = WebSocketProtocol76(self)
84 self.ws_connection.accept_connection()
84 self.ws_connection.accept_connection()
85
85
86 websocket.WebSocketHandler._execute = _execute
86 websocket.WebSocketHandler._execute = _execute
87 del _execute
87 del _execute
88
88
89 #-----------------------------------------------------------------------------
89 #-----------------------------------------------------------------------------
90 # Decorator for disabling read-only handlers
90 # Decorator for disabling read-only handlers
91 #-----------------------------------------------------------------------------
91 #-----------------------------------------------------------------------------
92
92
93 @decorator
93 @decorator
94 def not_if_readonly(f, self, *args, **kwargs):
94 def not_if_readonly(f, self, *args, **kwargs):
95 if self.application.read_only:
95 if self.application.read_only:
96 raise web.HTTPError(403, "Notebook server is read-only")
96 raise web.HTTPError(403, "Notebook server is read-only")
97 else:
97 else:
98 return f(self, *args, **kwargs)
98 return f(self, *args, **kwargs)
99
99
100 @decorator
100 @decorator
101 def authenticate_unless_readonly(f, self, *args, **kwargs):
101 def authenticate_unless_readonly(f, self, *args, **kwargs):
102 """authenticate this page *unless* readonly view is active.
102 """authenticate this page *unless* readonly view is active.
103
103
104 In read-only mode, the notebook list and print view should
104 In read-only mode, the notebook list and print view should
105 be accessible without authentication.
105 be accessible without authentication.
106 """
106 """
107
107
108 @web.authenticated
108 @web.authenticated
109 def auth_f(self, *args, **kwargs):
109 def auth_f(self, *args, **kwargs):
110 return f(self, *args, **kwargs)
110 return f(self, *args, **kwargs)
111
111
112 if self.application.read_only:
112 if self.application.read_only:
113 return f(self, *args, **kwargs)
113 return f(self, *args, **kwargs)
114 else:
114 else:
115 return auth_f(self, *args, **kwargs)
115 return auth_f(self, *args, **kwargs)
116
116
117 #-----------------------------------------------------------------------------
117 #-----------------------------------------------------------------------------
118 # Top-level handlers
118 # Top-level handlers
119 #-----------------------------------------------------------------------------
119 #-----------------------------------------------------------------------------
120
120
121 class RequestHandler(web.RequestHandler):
121 class RequestHandler(web.RequestHandler):
122 """RequestHandler with default variable setting."""
122 """RequestHandler with default variable setting."""
123
123
124 def render(*args, **kwargs):
124 def render(*args, **kwargs):
125 kwargs.setdefault('message', '')
125 kwargs.setdefault('message', '')
126 return web.RequestHandler.render(*args, **kwargs)
126 return web.RequestHandler.render(*args, **kwargs)
127
127
128 class AuthenticatedHandler(RequestHandler):
128 class AuthenticatedHandler(RequestHandler):
129 """A RequestHandler with an authenticated user."""
129 """A RequestHandler with an authenticated user."""
130
130
131 def get_current_user(self):
131 def get_current_user(self):
132 user_id = self.get_secure_cookie("username")
132 user_id = self.get_secure_cookie("username")
133 # For now the user_id should not return empty, but it could eventually
133 # For now the user_id should not return empty, but it could eventually
134 if user_id == '':
134 if user_id == '':
135 user_id = 'anonymous'
135 user_id = 'anonymous'
136 if user_id is None:
136 if user_id is None:
137 # prevent extra Invalid cookie sig warnings:
137 # prevent extra Invalid cookie sig warnings:
138 self.clear_cookie('username')
138 self.clear_cookie('username')
139 if not self.application.password and not self.application.read_only:
139 if not self.application.password and not self.application.read_only:
140 user_id = 'anonymous'
140 user_id = 'anonymous'
141 return user_id
141 return user_id
142
142
143 @property
143 @property
144 def logged_in(self):
144 def logged_in(self):
145 """Is a user currently logged in?
145 """Is a user currently logged in?
146
146
147 """
147 """
148 user = self.get_current_user()
148 user = self.get_current_user()
149 return (user and not user == 'anonymous')
149 return (user and not user == 'anonymous')
150
150
151 @property
151 @property
152 def login_available(self):
152 def login_available(self):
153 """May a user proceed to log in?
153 """May a user proceed to log in?
154
154
155 This returns True if login capability is available, irrespective of
155 This returns True if login capability is available, irrespective of
156 whether the user is already logged in or not.
156 whether the user is already logged in or not.
157
157
158 """
158 """
159 return bool(self.application.password)
159 return bool(self.application.password)
160
160
161 @property
161 @property
162 def read_only(self):
162 def read_only(self):
163 """Is the notebook read-only?
163 """Is the notebook read-only?
164
164
165 """
165 """
166 return self.application.read_only
166 return self.application.read_only
167
167
168 @property
168 @property
169 def ws_url(self):
169 def ws_url(self):
170 """websocket url matching the current request
170 """websocket url matching the current request
171
171
172 turns http[s]://host[:port] into
172 turns http[s]://host[:port] into
173 ws[s]://host[:port]
173 ws[s]://host[:port]
174 """
174 """
175 proto = self.request.protocol.replace('http', 'ws')
175 proto = self.request.protocol.replace('http', 'ws')
176 return "%s://%s" % (proto, self.request.host)
176 host = self.application.ipython_app.websocket_host # default to config value
177 if host == '':
178 host = self.request.host # get from request
179 return "%s://%s" % (proto, host)
177
180
178
181
179 class AuthenticatedFileHandler(AuthenticatedHandler, web.StaticFileHandler):
182 class AuthenticatedFileHandler(AuthenticatedHandler, web.StaticFileHandler):
180 """static files should only be accessible when logged in"""
183 """static files should only be accessible when logged in"""
181
184
182 @authenticate_unless_readonly
185 @authenticate_unless_readonly
183 def get(self, path):
186 def get(self, path):
184 return web.StaticFileHandler.get(self, path)
187 return web.StaticFileHandler.get(self, path)
185
188
186
189
187 class ProjectDashboardHandler(AuthenticatedHandler):
190 class ProjectDashboardHandler(AuthenticatedHandler):
188
191
189 @authenticate_unless_readonly
192 @authenticate_unless_readonly
190 def get(self):
193 def get(self):
191 nbm = self.application.notebook_manager
194 nbm = self.application.notebook_manager
192 project = nbm.notebook_dir
195 project = nbm.notebook_dir
193 self.render(
196 self.render(
194 'projectdashboard.html', project=project,
197 'projectdashboard.html', project=project,
195 base_project_url=u'/', base_kernel_url=u'/',
198 base_project_url=self.application.ipython_app.base_project_url,
199 base_kernel_url=self.application.ipython_app.base_kernel_url,
196 read_only=self.read_only,
200 read_only=self.read_only,
197 logged_in=self.logged_in,
201 logged_in=self.logged_in,
198 login_available=self.login_available
202 login_available=self.login_available
199 )
203 )
200
204
201
205
202 class LoginHandler(AuthenticatedHandler):
206 class LoginHandler(AuthenticatedHandler):
203
207
204 def _render(self, message=None):
208 def _render(self, message=None):
205 self.render('login.html',
209 self.render('login.html',
206 next=self.get_argument('next', default='/'),
210 next=self.get_argument('next', default='/'),
207 read_only=self.read_only,
211 read_only=self.read_only,
208 logged_in=self.logged_in,
212 logged_in=self.logged_in,
209 login_available=self.login_available,
213 login_available=self.login_available,
210 message=message
214 message=message
211 )
215 )
212
216
213 def get(self):
217 def get(self):
214 if self.current_user:
218 if self.current_user:
215 self.redirect(self.get_argument('next', default='/'))
219 self.redirect(self.get_argument('next', default='/'))
216 else:
220 else:
217 self._render()
221 self._render()
218
222
219 def post(self):
223 def post(self):
220 pwd = self.get_argument('password', default=u'')
224 pwd = self.get_argument('password', default=u'')
221 if self.application.password:
225 if self.application.password:
222 if passwd_check(self.application.password, pwd):
226 if passwd_check(self.application.password, pwd):
223 self.set_secure_cookie('username', str(uuid.uuid4()))
227 self.set_secure_cookie('username', str(uuid.uuid4()))
224 else:
228 else:
225 self._render(message={'error': 'Invalid password'})
229 self._render(message={'error': 'Invalid password'})
226 return
230 return
227
231
228 self.redirect(self.get_argument('next', default='/'))
232 self.redirect(self.get_argument('next', default='/'))
229
233
230
234
231 class LogoutHandler(AuthenticatedHandler):
235 class LogoutHandler(AuthenticatedHandler):
232
236
233 def get(self):
237 def get(self):
234 self.clear_cookie('username')
238 self.clear_cookie('username')
235 if self.login_available:
239 if self.login_available:
236 message = {'info': 'Successfully logged out.'}
240 message = {'info': 'Successfully logged out.'}
237 else:
241 else:
238 message = {'warning': 'Cannot log out. Notebook authentication '
242 message = {'warning': 'Cannot log out. Notebook authentication '
239 'is disabled.'}
243 'is disabled.'}
240
244
241 self.render('logout.html',
245 self.render('logout.html',
242 read_only=self.read_only,
246 read_only=self.read_only,
243 logged_in=self.logged_in,
247 logged_in=self.logged_in,
244 login_available=self.login_available,
248 login_available=self.login_available,
245 message=message)
249 message=message)
246
250
247
251
248 class NewHandler(AuthenticatedHandler):
252 class NewHandler(AuthenticatedHandler):
249
253
250 @web.authenticated
254 @web.authenticated
251 def get(self):
255 def get(self):
252 nbm = self.application.notebook_manager
256 nbm = self.application.notebook_manager
253 project = nbm.notebook_dir
257 project = nbm.notebook_dir
254 notebook_id = nbm.new_notebook()
258 notebook_id = nbm.new_notebook()
255 self.render(
259 self.render(
256 'notebook.html', project=project,
260 'notebook.html', project=project,
257 notebook_id=notebook_id,
261 notebook_id=notebook_id,
258 base_project_url=u'/', base_kernel_url=u'/',
262 base_project_url=self.application.ipython_app.base_project_url,
263 base_kernel_url=self.application.ipython_app.base_kernel_url,
259 kill_kernel=False,
264 kill_kernel=False,
260 read_only=False,
265 read_only=False,
261 logged_in=self.logged_in,
266 logged_in=self.logged_in,
262 login_available=self.login_available,
267 login_available=self.login_available,
263 mathjax_url=self.application.ipython_app.mathjax_url,
268 mathjax_url=self.application.ipython_app.mathjax_url,
264 )
269 )
265
270
266
271
267 class NamedNotebookHandler(AuthenticatedHandler):
272 class NamedNotebookHandler(AuthenticatedHandler):
268
273
269 @authenticate_unless_readonly
274 @authenticate_unless_readonly
270 def get(self, notebook_id):
275 def get(self, notebook_id):
271 nbm = self.application.notebook_manager
276 nbm = self.application.notebook_manager
272 project = nbm.notebook_dir
277 project = nbm.notebook_dir
273 if not nbm.notebook_exists(notebook_id):
278 if not nbm.notebook_exists(notebook_id):
274 raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
279 raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
275
280
276 self.render(
281 self.render(
277 'notebook.html', project=project,
282 'notebook.html', project=project,
278 notebook_id=notebook_id,
283 notebook_id=notebook_id,
279 base_project_url=u'/', base_kernel_url=u'/',
284 base_project_url=self.application.ipython_app.base_project_url,
285 base_kernel_url=self.application.ipython_app.base_kernel_url,
280 kill_kernel=False,
286 kill_kernel=False,
281 read_only=self.read_only,
287 read_only=self.read_only,
282 logged_in=self.logged_in,
288 logged_in=self.logged_in,
283 login_available=self.login_available,
289 login_available=self.login_available,
284 mathjax_url=self.application.ipython_app.mathjax_url,
290 mathjax_url=self.application.ipython_app.mathjax_url,
285 )
291 )
286
292
287
293
288 class PrintNotebookHandler(AuthenticatedHandler):
294 class PrintNotebookHandler(AuthenticatedHandler):
289
295
290 @authenticate_unless_readonly
296 @authenticate_unless_readonly
291 def get(self, notebook_id):
297 def get(self, notebook_id):
292 nbm = self.application.notebook_manager
298 nbm = self.application.notebook_manager
293 project = nbm.notebook_dir
299 project = nbm.notebook_dir
294 if not nbm.notebook_exists(notebook_id):
300 if not nbm.notebook_exists(notebook_id):
295 raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
301 raise web.HTTPError(404, u'Notebook does not exist: %s' % notebook_id)
296
302
297 self.render(
303 self.render(
298 'printnotebook.html', project=project,
304 'printnotebook.html', project=project,
299 notebook_id=notebook_id,
305 notebook_id=notebook_id,
300 base_project_url=u'/', base_kernel_url=u'/',
306 base_project_url=self.application.ipython_app.base_project_url,
307 base_kernel_url=self.application.ipython_app.base_kernel_url,
301 kill_kernel=False,
308 kill_kernel=False,
302 read_only=self.read_only,
309 read_only=self.read_only,
303 logged_in=self.logged_in,
310 logged_in=self.logged_in,
304 login_available=self.login_available,
311 login_available=self.login_available,
305 mathjax_url=self.application.ipython_app.mathjax_url,
312 mathjax_url=self.application.ipython_app.mathjax_url,
306 )
313 )
307
314
308 #-----------------------------------------------------------------------------
315 #-----------------------------------------------------------------------------
309 # Kernel handlers
316 # Kernel handlers
310 #-----------------------------------------------------------------------------
317 #-----------------------------------------------------------------------------
311
318
312
319
313 class MainKernelHandler(AuthenticatedHandler):
320 class MainKernelHandler(AuthenticatedHandler):
314
321
315 @web.authenticated
322 @web.authenticated
316 def get(self):
323 def get(self):
317 km = self.application.kernel_manager
324 km = self.application.kernel_manager
318 self.finish(jsonapi.dumps(km.kernel_ids))
325 self.finish(jsonapi.dumps(km.kernel_ids))
319
326
320 @web.authenticated
327 @web.authenticated
321 def post(self):
328 def post(self):
322 km = self.application.kernel_manager
329 km = self.application.kernel_manager
323 notebook_id = self.get_argument('notebook', default=None)
330 notebook_id = self.get_argument('notebook', default=None)
324 kernel_id = km.start_kernel(notebook_id)
331 kernel_id = km.start_kernel(notebook_id)
325 data = {'ws_url':self.ws_url,'kernel_id':kernel_id}
332 data = {'ws_url':self.ws_url,'kernel_id':kernel_id}
326 self.set_header('Location', '/'+kernel_id)
333 self.set_header('Location', '/'+kernel_id)
327 self.finish(jsonapi.dumps(data))
334 self.finish(jsonapi.dumps(data))
328
335
329
336
330 class KernelHandler(AuthenticatedHandler):
337 class KernelHandler(AuthenticatedHandler):
331
338
332 SUPPORTED_METHODS = ('DELETE')
339 SUPPORTED_METHODS = ('DELETE')
333
340
334 @web.authenticated
341 @web.authenticated
335 def delete(self, kernel_id):
342 def delete(self, kernel_id):
336 km = self.application.kernel_manager
343 km = self.application.kernel_manager
337 km.kill_kernel(kernel_id)
344 km.kill_kernel(kernel_id)
338 self.set_status(204)
345 self.set_status(204)
339 self.finish()
346 self.finish()
340
347
341
348
342 class KernelActionHandler(AuthenticatedHandler):
349 class KernelActionHandler(AuthenticatedHandler):
343
350
344 @web.authenticated
351 @web.authenticated
345 def post(self, kernel_id, action):
352 def post(self, kernel_id, action):
346 km = self.application.kernel_manager
353 km = self.application.kernel_manager
347 if action == 'interrupt':
354 if action == 'interrupt':
348 km.interrupt_kernel(kernel_id)
355 km.interrupt_kernel(kernel_id)
349 self.set_status(204)
356 self.set_status(204)
350 if action == 'restart':
357 if action == 'restart':
351 new_kernel_id = km.restart_kernel(kernel_id)
358 new_kernel_id = km.restart_kernel(kernel_id)
352 data = {'ws_url':self.ws_url,'kernel_id':new_kernel_id}
359 data = {'ws_url':self.ws_url,'kernel_id':new_kernel_id}
353 self.set_header('Location', '/'+new_kernel_id)
360 self.set_header('Location', '/'+new_kernel_id)
354 self.write(jsonapi.dumps(data))
361 self.write(jsonapi.dumps(data))
355 self.finish()
362 self.finish()
356
363
357
364
358 class ZMQStreamHandler(websocket.WebSocketHandler):
365 class ZMQStreamHandler(websocket.WebSocketHandler):
359
366
360 def _reserialize_reply(self, msg_list):
367 def _reserialize_reply(self, msg_list):
361 """Reserialize a reply message using JSON.
368 """Reserialize a reply message using JSON.
362
369
363 This takes the msg list from the ZMQ socket, unserializes it using
370 This takes the msg list from the ZMQ socket, unserializes it using
364 self.session and then serializes the result using JSON. This method
371 self.session and then serializes the result using JSON. This method
365 should be used by self._on_zmq_reply to build messages that can
372 should be used by self._on_zmq_reply to build messages that can
366 be sent back to the browser.
373 be sent back to the browser.
367 """
374 """
368 idents, msg_list = self.session.feed_identities(msg_list)
375 idents, msg_list = self.session.feed_identities(msg_list)
369 msg = self.session.unserialize(msg_list)
376 msg = self.session.unserialize(msg_list)
370 try:
377 try:
371 msg['header'].pop('date')
378 msg['header'].pop('date')
372 except KeyError:
379 except KeyError:
373 pass
380 pass
374 try:
381 try:
375 msg['parent_header'].pop('date')
382 msg['parent_header'].pop('date')
376 except KeyError:
383 except KeyError:
377 pass
384 pass
378 msg.pop('buffers')
385 msg.pop('buffers')
379 return jsonapi.dumps(msg)
386 return jsonapi.dumps(msg)
380
387
381 def _on_zmq_reply(self, msg_list):
388 def _on_zmq_reply(self, msg_list):
382 try:
389 try:
383 msg = self._reserialize_reply(msg_list)
390 msg = self._reserialize_reply(msg_list)
384 except:
391 except:
385 self.application.log.critical("Malformed message: %r" % msg_list)
392 self.application.log.critical("Malformed message: %r" % msg_list)
386 else:
393 else:
387 self.write_message(msg)
394 self.write_message(msg)
388
395
389
396
390 class AuthenticatedZMQStreamHandler(ZMQStreamHandler):
397 class AuthenticatedZMQStreamHandler(ZMQStreamHandler):
391
398
392 def open(self, kernel_id):
399 def open(self, kernel_id):
393 self.kernel_id = kernel_id.decode('ascii')
400 self.kernel_id = kernel_id.decode('ascii')
394 try:
401 try:
395 cfg = self.application.ipython_app.config
402 cfg = self.application.ipython_app.config
396 except AttributeError:
403 except AttributeError:
397 # protect from the case where this is run from something other than
404 # protect from the case where this is run from something other than
398 # the notebook app:
405 # the notebook app:
399 cfg = None
406 cfg = None
400 self.session = Session(config=cfg)
407 self.session = Session(config=cfg)
401 self.save_on_message = self.on_message
408 self.save_on_message = self.on_message
402 self.on_message = self.on_first_message
409 self.on_message = self.on_first_message
403
410
404 def get_current_user(self):
411 def get_current_user(self):
405 user_id = self.get_secure_cookie("username")
412 user_id = self.get_secure_cookie("username")
406 if user_id == '' or (user_id is None and not self.application.password):
413 if user_id == '' or (user_id is None and not self.application.password):
407 user_id = 'anonymous'
414 user_id = 'anonymous'
408 return user_id
415 return user_id
409
416
410 def _inject_cookie_message(self, msg):
417 def _inject_cookie_message(self, msg):
411 """Inject the first message, which is the document cookie,
418 """Inject the first message, which is the document cookie,
412 for authentication."""
419 for authentication."""
413 if isinstance(msg, unicode):
420 if isinstance(msg, unicode):
414 # Cookie can't constructor doesn't accept unicode strings for some reason
421 # Cookie can't constructor doesn't accept unicode strings for some reason
415 msg = msg.encode('utf8', 'replace')
422 msg = msg.encode('utf8', 'replace')
416 try:
423 try:
417 self.request._cookies = Cookie.SimpleCookie(msg)
424 self.request._cookies = Cookie.SimpleCookie(msg)
418 except:
425 except:
419 logging.warn("couldn't parse cookie string: %s",msg, exc_info=True)
426 logging.warn("couldn't parse cookie string: %s",msg, exc_info=True)
420
427
421 def on_first_message(self, msg):
428 def on_first_message(self, msg):
422 self._inject_cookie_message(msg)
429 self._inject_cookie_message(msg)
423 if self.get_current_user() is None:
430 if self.get_current_user() is None:
424 logging.warn("Couldn't authenticate WebSocket connection")
431 logging.warn("Couldn't authenticate WebSocket connection")
425 raise web.HTTPError(403)
432 raise web.HTTPError(403)
426 self.on_message = self.save_on_message
433 self.on_message = self.save_on_message
427
434
428
435
429 class IOPubHandler(AuthenticatedZMQStreamHandler):
436 class IOPubHandler(AuthenticatedZMQStreamHandler):
430
437
431 def initialize(self, *args, **kwargs):
438 def initialize(self, *args, **kwargs):
432 self._kernel_alive = True
439 self._kernel_alive = True
433 self._beating = False
440 self._beating = False
434 self.iopub_stream = None
441 self.iopub_stream = None
435 self.hb_stream = None
442 self.hb_stream = None
436
443
437 def on_first_message(self, msg):
444 def on_first_message(self, msg):
438 try:
445 try:
439 super(IOPubHandler, self).on_first_message(msg)
446 super(IOPubHandler, self).on_first_message(msg)
440 except web.HTTPError:
447 except web.HTTPError:
441 self.close()
448 self.close()
442 return
449 return
443 km = self.application.kernel_manager
450 km = self.application.kernel_manager
444 self.time_to_dead = km.time_to_dead
451 self.time_to_dead = km.time_to_dead
445 self.first_beat = km.first_beat
452 self.first_beat = km.first_beat
446 kernel_id = self.kernel_id
453 kernel_id = self.kernel_id
447 try:
454 try:
448 self.iopub_stream = km.create_iopub_stream(kernel_id)
455 self.iopub_stream = km.create_iopub_stream(kernel_id)
449 self.hb_stream = km.create_hb_stream(kernel_id)
456 self.hb_stream = km.create_hb_stream(kernel_id)
450 except web.HTTPError:
457 except web.HTTPError:
451 # WebSockets don't response to traditional error codes so we
458 # WebSockets don't response to traditional error codes so we
452 # close the connection.
459 # close the connection.
453 if not self.stream.closed():
460 if not self.stream.closed():
454 self.stream.close()
461 self.stream.close()
455 self.close()
462 self.close()
456 else:
463 else:
457 self.iopub_stream.on_recv(self._on_zmq_reply)
464 self.iopub_stream.on_recv(self._on_zmq_reply)
458 self.start_hb(self.kernel_died)
465 self.start_hb(self.kernel_died)
459
466
460 def on_message(self, msg):
467 def on_message(self, msg):
461 pass
468 pass
462
469
463 def on_close(self):
470 def on_close(self):
464 # This method can be called twice, once by self.kernel_died and once
471 # This method can be called twice, once by self.kernel_died and once
465 # from the WebSocket close event. If the WebSocket connection is
472 # from the WebSocket close event. If the WebSocket connection is
466 # closed before the ZMQ streams are setup, they could be None.
473 # closed before the ZMQ streams are setup, they could be None.
467 self.stop_hb()
474 self.stop_hb()
468 if self.iopub_stream is not None and not self.iopub_stream.closed():
475 if self.iopub_stream is not None and not self.iopub_stream.closed():
469 self.iopub_stream.on_recv(None)
476 self.iopub_stream.on_recv(None)
470 self.iopub_stream.close()
477 self.iopub_stream.close()
471 if self.hb_stream is not None and not self.hb_stream.closed():
478 if self.hb_stream is not None and not self.hb_stream.closed():
472 self.hb_stream.close()
479 self.hb_stream.close()
473
480
474 def start_hb(self, callback):
481 def start_hb(self, callback):
475 """Start the heartbeating and call the callback if the kernel dies."""
482 """Start the heartbeating and call the callback if the kernel dies."""
476 if not self._beating:
483 if not self._beating:
477 self._kernel_alive = True
484 self._kernel_alive = True
478
485
479 def ping_or_dead():
486 def ping_or_dead():
480 self.hb_stream.flush()
487 self.hb_stream.flush()
481 if self._kernel_alive:
488 if self._kernel_alive:
482 self._kernel_alive = False
489 self._kernel_alive = False
483 self.hb_stream.send(b'ping')
490 self.hb_stream.send(b'ping')
484 # flush stream to force immediate socket send
491 # flush stream to force immediate socket send
485 self.hb_stream.flush()
492 self.hb_stream.flush()
486 else:
493 else:
487 try:
494 try:
488 callback()
495 callback()
489 except:
496 except:
490 pass
497 pass
491 finally:
498 finally:
492 self.stop_hb()
499 self.stop_hb()
493
500
494 def beat_received(msg):
501 def beat_received(msg):
495 self._kernel_alive = True
502 self._kernel_alive = True
496
503
497 self.hb_stream.on_recv(beat_received)
504 self.hb_stream.on_recv(beat_received)
498 loop = ioloop.IOLoop.instance()
505 loop = ioloop.IOLoop.instance()
499 self._hb_periodic_callback = ioloop.PeriodicCallback(ping_or_dead, self.time_to_dead*1000, loop)
506 self._hb_periodic_callback = ioloop.PeriodicCallback(ping_or_dead, self.time_to_dead*1000, loop)
500 loop.add_timeout(time.time()+self.first_beat, self._really_start_hb)
507 loop.add_timeout(time.time()+self.first_beat, self._really_start_hb)
501 self._beating= True
508 self._beating= True
502
509
503 def _really_start_hb(self):
510 def _really_start_hb(self):
504 """callback for delayed heartbeat start
511 """callback for delayed heartbeat start
505
512
506 Only start the hb loop if we haven't been closed during the wait.
513 Only start the hb loop if we haven't been closed during the wait.
507 """
514 """
508 if self._beating and not self.hb_stream.closed():
515 if self._beating and not self.hb_stream.closed():
509 self._hb_periodic_callback.start()
516 self._hb_periodic_callback.start()
510
517
511 def stop_hb(self):
518 def stop_hb(self):
512 """Stop the heartbeating and cancel all related callbacks."""
519 """Stop the heartbeating and cancel all related callbacks."""
513 if self._beating:
520 if self._beating:
514 self._beating = False
521 self._beating = False
515 self._hb_periodic_callback.stop()
522 self._hb_periodic_callback.stop()
516 if not self.hb_stream.closed():
523 if not self.hb_stream.closed():
517 self.hb_stream.on_recv(None)
524 self.hb_stream.on_recv(None)
518
525
519 def kernel_died(self):
526 def kernel_died(self):
520 self.application.kernel_manager.delete_mapping_for_kernel(self.kernel_id)
527 self.application.kernel_manager.delete_mapping_for_kernel(self.kernel_id)
521 self.application.log.error("Kernel %s failed to respond to heartbeat", self.kernel_id)
528 self.application.log.error("Kernel %s failed to respond to heartbeat", self.kernel_id)
522 self.write_message(
529 self.write_message(
523 {'header': {'msg_type': 'status'},
530 {'header': {'msg_type': 'status'},
524 'parent_header': {},
531 'parent_header': {},
525 'content': {'execution_state':'dead'}
532 'content': {'execution_state':'dead'}
526 }
533 }
527 )
534 )
528 self.on_close()
535 self.on_close()
529
536
530
537
531 class ShellHandler(AuthenticatedZMQStreamHandler):
538 class ShellHandler(AuthenticatedZMQStreamHandler):
532
539
533 def initialize(self, *args, **kwargs):
540 def initialize(self, *args, **kwargs):
534 self.shell_stream = None
541 self.shell_stream = None
535
542
536 def on_first_message(self, msg):
543 def on_first_message(self, msg):
537 try:
544 try:
538 super(ShellHandler, self).on_first_message(msg)
545 super(ShellHandler, self).on_first_message(msg)
539 except web.HTTPError:
546 except web.HTTPError:
540 self.close()
547 self.close()
541 return
548 return
542 km = self.application.kernel_manager
549 km = self.application.kernel_manager
543 self.max_msg_size = km.max_msg_size
550 self.max_msg_size = km.max_msg_size
544 kernel_id = self.kernel_id
551 kernel_id = self.kernel_id
545 try:
552 try:
546 self.shell_stream = km.create_shell_stream(kernel_id)
553 self.shell_stream = km.create_shell_stream(kernel_id)
547 except web.HTTPError:
554 except web.HTTPError:
548 # WebSockets don't response to traditional error codes so we
555 # WebSockets don't response to traditional error codes so we
549 # close the connection.
556 # close the connection.
550 if not self.stream.closed():
557 if not self.stream.closed():
551 self.stream.close()
558 self.stream.close()
552 self.close()
559 self.close()
553 else:
560 else:
554 self.shell_stream.on_recv(self._on_zmq_reply)
561 self.shell_stream.on_recv(self._on_zmq_reply)
555
562
556 def on_message(self, msg):
563 def on_message(self, msg):
557 if len(msg) < self.max_msg_size:
564 if len(msg) < self.max_msg_size:
558 msg = jsonapi.loads(msg)
565 msg = jsonapi.loads(msg)
559 self.session.send(self.shell_stream, msg)
566 self.session.send(self.shell_stream, msg)
560
567
561 def on_close(self):
568 def on_close(self):
562 # Make sure the stream exists and is not already closed.
569 # Make sure the stream exists and is not already closed.
563 if self.shell_stream is not None and not self.shell_stream.closed():
570 if self.shell_stream is not None and not self.shell_stream.closed():
564 self.shell_stream.close()
571 self.shell_stream.close()
565
572
566
573
567 #-----------------------------------------------------------------------------
574 #-----------------------------------------------------------------------------
568 # Notebook web service handlers
575 # Notebook web service handlers
569 #-----------------------------------------------------------------------------
576 #-----------------------------------------------------------------------------
570
577
571 class NotebookRootHandler(AuthenticatedHandler):
578 class NotebookRootHandler(AuthenticatedHandler):
572
579
573 @authenticate_unless_readonly
580 @authenticate_unless_readonly
574 def get(self):
581 def get(self):
575
582
576 nbm = self.application.notebook_manager
583 nbm = self.application.notebook_manager
577 files = nbm.list_notebooks()
584 files = nbm.list_notebooks()
578 self.finish(jsonapi.dumps(files))
585 self.finish(jsonapi.dumps(files))
579
586
580 @web.authenticated
587 @web.authenticated
581 def post(self):
588 def post(self):
582 nbm = self.application.notebook_manager
589 nbm = self.application.notebook_manager
583 body = self.request.body.strip()
590 body = self.request.body.strip()
584 format = self.get_argument('format', default='json')
591 format = self.get_argument('format', default='json')
585 name = self.get_argument('name', default=None)
592 name = self.get_argument('name', default=None)
586 if body:
593 if body:
587 notebook_id = nbm.save_new_notebook(body, name=name, format=format)
594 notebook_id = nbm.save_new_notebook(body, name=name, format=format)
588 else:
595 else:
589 notebook_id = nbm.new_notebook()
596 notebook_id = nbm.new_notebook()
590 self.set_header('Location', '/'+notebook_id)
597 self.set_header('Location', '/'+notebook_id)
591 self.finish(jsonapi.dumps(notebook_id))
598 self.finish(jsonapi.dumps(notebook_id))
592
599
593
600
594 class NotebookHandler(AuthenticatedHandler):
601 class NotebookHandler(AuthenticatedHandler):
595
602
596 SUPPORTED_METHODS = ('GET', 'PUT', 'DELETE')
603 SUPPORTED_METHODS = ('GET', 'PUT', 'DELETE')
597
604
598 @authenticate_unless_readonly
605 @authenticate_unless_readonly
599 def get(self, notebook_id):
606 def get(self, notebook_id):
600 nbm = self.application.notebook_manager
607 nbm = self.application.notebook_manager
601 format = self.get_argument('format', default='json')
608 format = self.get_argument('format', default='json')
602 last_mod, name, data = nbm.get_notebook(notebook_id, format)
609 last_mod, name, data = nbm.get_notebook(notebook_id, format)
603
610
604 if format == u'json':
611 if format == u'json':
605 self.set_header('Content-Type', 'application/json')
612 self.set_header('Content-Type', 'application/json')
606 self.set_header('Content-Disposition','attachment; filename="%s.ipynb"' % name)
613 self.set_header('Content-Disposition','attachment; filename="%s.ipynb"' % name)
607 elif format == u'py':
614 elif format == u'py':
608 self.set_header('Content-Type', 'application/x-python')
615 self.set_header('Content-Type', 'application/x-python')
609 self.set_header('Content-Disposition','attachment; filename="%s.py"' % name)
616 self.set_header('Content-Disposition','attachment; filename="%s.py"' % name)
610 self.set_header('Last-Modified', last_mod)
617 self.set_header('Last-Modified', last_mod)
611 self.finish(data)
618 self.finish(data)
612
619
613 @web.authenticated
620 @web.authenticated
614 def put(self, notebook_id):
621 def put(self, notebook_id):
615 nbm = self.application.notebook_manager
622 nbm = self.application.notebook_manager
616 format = self.get_argument('format', default='json')
623 format = self.get_argument('format', default='json')
617 name = self.get_argument('name', default=None)
624 name = self.get_argument('name', default=None)
618 nbm.save_notebook(notebook_id, self.request.body, name=name, format=format)
625 nbm.save_notebook(notebook_id, self.request.body, name=name, format=format)
619 self.set_status(204)
626 self.set_status(204)
620 self.finish()
627 self.finish()
621
628
622 @web.authenticated
629 @web.authenticated
623 def delete(self, notebook_id):
630 def delete(self, notebook_id):
624 nbm = self.application.notebook_manager
631 nbm = self.application.notebook_manager
625 nbm.delete_notebook(notebook_id)
632 nbm.delete_notebook(notebook_id)
626 self.set_status(204)
633 self.set_status(204)
627 self.finish()
634 self.finish()
628
635
629
636
630 class NotebookCopyHandler(AuthenticatedHandler):
637 class NotebookCopyHandler(AuthenticatedHandler):
631
638
632 @web.authenticated
639 @web.authenticated
633 def get(self, notebook_id):
640 def get(self, notebook_id):
634 nbm = self.application.notebook_manager
641 nbm = self.application.notebook_manager
635 project = nbm.notebook_dir
642 project = nbm.notebook_dir
636 notebook_id = nbm.copy_notebook(notebook_id)
643 notebook_id = nbm.copy_notebook(notebook_id)
637 self.render(
644 self.render(
638 'notebook.html', project=project,
645 'notebook.html', project=project,
639 notebook_id=notebook_id,
646 notebook_id=notebook_id,
640 base_project_url=u'/', base_kernel_url=u'/',
647 base_project_url=self.application.ipython_app.base_project_url,
648 base_kernel_url=self.application.ipython_app.base_kernel_url,
641 kill_kernel=False,
649 kill_kernel=False,
642 read_only=False,
650 read_only=False,
643 logged_in=self.logged_in,
651 logged_in=self.logged_in,
644 login_available=self.login_available,
652 login_available=self.login_available,
645 mathjax_url=self.application.ipython_app.mathjax_url,
653 mathjax_url=self.application.ipython_app.mathjax_url,
646 )
654 )
647
655
648 #-----------------------------------------------------------------------------
656 #-----------------------------------------------------------------------------
649 # RST web service handlers
657 # RST web service handlers
650 #-----------------------------------------------------------------------------
658 #-----------------------------------------------------------------------------
651
659
652
660
653 class RSTHandler(AuthenticatedHandler):
661 class RSTHandler(AuthenticatedHandler):
654
662
655 @web.authenticated
663 @web.authenticated
656 def post(self):
664 def post(self):
657 if publish_string is None:
665 if publish_string is None:
658 raise web.HTTPError(503, u'docutils not available')
666 raise web.HTTPError(503, u'docutils not available')
659 body = self.request.body.strip()
667 body = self.request.body.strip()
660 source = body
668 source = body
661 # template_path=os.path.join(os.path.dirname(__file__), u'templates', u'rst_template.html')
669 # template_path=os.path.join(os.path.dirname(__file__), u'templates', u'rst_template.html')
662 defaults = {'file_insertion_enabled': 0,
670 defaults = {'file_insertion_enabled': 0,
663 'raw_enabled': 0,
671 'raw_enabled': 0,
664 '_disable_config': 1,
672 '_disable_config': 1,
665 'stylesheet_path': 0
673 'stylesheet_path': 0
666 # 'template': template_path
674 # 'template': template_path
667 }
675 }
668 try:
676 try:
669 html = publish_string(source, writer_name='html',
677 html = publish_string(source, writer_name='html',
670 settings_overrides=defaults
678 settings_overrides=defaults
671 )
679 )
672 except:
680 except:
673 raise web.HTTPError(400, u'Invalid RST')
681 raise web.HTTPError(400, u'Invalid RST')
674 print html
682 print html
675 self.set_header('Content-Type', 'text/html')
683 self.set_header('Content-Type', 'text/html')
676 self.finish(html)
684 self.finish(html)
677
685
678
686
@@ -1,410 +1,438 b''
1 """A tornado based IPython notebook server.
1 """A tornado based IPython notebook server.
2
2
3 Authors:
3 Authors:
4
4
5 * Brian Granger
5 * Brian Granger
6 """
6 """
7
7
8 #-----------------------------------------------------------------------------
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2008-2011 The IPython Development Team
9 # Copyright (C) 2008-2011 The IPython Development Team
10 #
10 #
11 # Distributed under the terms of the BSD License. The full license is in
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 # Imports
16 # Imports
17 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18
18
19 # stdlib
19 # stdlib
20 import errno
20 import errno
21 import logging
21 import logging
22 import os
22 import os
23 import signal
23 import signal
24 import socket
24 import socket
25 import sys
25 import sys
26 import threading
26 import threading
27 import webbrowser
27 import webbrowser
28
28
29 # Third party
29 # Third party
30 import zmq
30 import zmq
31
31
32 # Install the pyzmq ioloop. This has to be done before anything else from
32 # Install the pyzmq ioloop. This has to be done before anything else from
33 # tornado is imported.
33 # tornado is imported.
34 from zmq.eventloop import ioloop
34 from zmq.eventloop import ioloop
35 # FIXME: ioloop.install is new in pyzmq-2.1.7, so remove this conditional
35 # FIXME: ioloop.install is new in pyzmq-2.1.7, so remove this conditional
36 # when pyzmq dependency is updated beyond that.
36 # when pyzmq dependency is updated beyond that.
37 if hasattr(ioloop, 'install'):
37 if hasattr(ioloop, 'install'):
38 ioloop.install()
38 ioloop.install()
39 else:
39 else:
40 import tornado.ioloop
40 import tornado.ioloop
41 tornado.ioloop.IOLoop = ioloop.IOLoop
41 tornado.ioloop.IOLoop = ioloop.IOLoop
42
42
43 from tornado import httpserver
43 from tornado import httpserver
44 from tornado import web
44 from tornado import web
45
45
46 # Our own libraries
46 # Our own libraries
47 from .kernelmanager import MappingKernelManager
47 from .kernelmanager import MappingKernelManager
48 from .handlers import (LoginHandler, LogoutHandler,
48 from .handlers import (LoginHandler, LogoutHandler,
49 ProjectDashboardHandler, NewHandler, NamedNotebookHandler,
49 ProjectDashboardHandler, NewHandler, NamedNotebookHandler,
50 MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler,
50 MainKernelHandler, KernelHandler, KernelActionHandler, IOPubHandler,
51 ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
51 ShellHandler, NotebookRootHandler, NotebookHandler, NotebookCopyHandler,
52 RSTHandler, AuthenticatedFileHandler, PrintNotebookHandler
52 RSTHandler, AuthenticatedFileHandler, PrintNotebookHandler
53 )
53 )
54 from .notebookmanager import NotebookManager
54 from .notebookmanager import NotebookManager
55
55
56 from IPython.config.application import catch_config_error, boolean_flag
56 from IPython.config.application import catch_config_error, boolean_flag
57 from IPython.core.application import BaseIPythonApplication
57 from IPython.core.application import BaseIPythonApplication
58 from IPython.core.profiledir import ProfileDir
58 from IPython.core.profiledir import ProfileDir
59 from IPython.lib.kernel import swallow_argv
59 from IPython.lib.kernel import swallow_argv
60 from IPython.zmq.session import Session, default_secure
60 from IPython.zmq.session import Session, default_secure
61 from IPython.zmq.zmqshell import ZMQInteractiveShell
61 from IPython.zmq.zmqshell import ZMQInteractiveShell
62 from IPython.zmq.ipkernel import (
62 from IPython.zmq.ipkernel import (
63 flags as ipkernel_flags,
63 flags as ipkernel_flags,
64 aliases as ipkernel_aliases,
64 aliases as ipkernel_aliases,
65 IPKernelApp
65 IPKernelApp
66 )
66 )
67 from IPython.utils.traitlets import Dict, Unicode, Integer, List, Enum, Bool
67 from IPython.utils.traitlets import Dict, Unicode, Integer, List, Enum, Bool
68
68
69 #-----------------------------------------------------------------------------
69 #-----------------------------------------------------------------------------
70 # Module globals
70 # Module globals
71 #-----------------------------------------------------------------------------
71 #-----------------------------------------------------------------------------
72
72
73 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
73 _kernel_id_regex = r"(?P<kernel_id>\w+-\w+-\w+-\w+-\w+)"
74 _kernel_action_regex = r"(?P<action>restart|interrupt)"
74 _kernel_action_regex = r"(?P<action>restart|interrupt)"
75 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
75 _notebook_id_regex = r"(?P<notebook_id>\w+-\w+-\w+-\w+-\w+)"
76
76
77 LOCALHOST = '127.0.0.1'
77 LOCALHOST = '127.0.0.1'
78
78
79 _examples = """
79 _examples = """
80 ipython notebook # start the notebook
80 ipython notebook # start the notebook
81 ipython notebook --profile=sympy # use the sympy profile
81 ipython notebook --profile=sympy # use the sympy profile
82 ipython notebook --pylab=inline # pylab in inline plotting mode
82 ipython notebook --pylab=inline # pylab in inline plotting mode
83 ipython notebook --certfile=mycert.pem # use SSL/TLS certificate
83 ipython notebook --certfile=mycert.pem # use SSL/TLS certificate
84 ipython notebook --port=5555 --ip=* # Listen on port 5555, all interfaces
84 ipython notebook --port=5555 --ip=* # Listen on port 5555, all interfaces
85 """
85 """
86
86
87 #-----------------------------------------------------------------------------
87 #-----------------------------------------------------------------------------
88 # Helper functions
89 #-----------------------------------------------------------------------------
90
91 def url_path_join(a,b):
92 if a.endswith('/') and b.startswith('/'):
93 return a[:-1]+b
94 else:
95 return a+b
96
97 #-----------------------------------------------------------------------------
88 # The Tornado web application
98 # The Tornado web application
89 #-----------------------------------------------------------------------------
99 #-----------------------------------------------------------------------------
90
100
91 class NotebookWebApplication(web.Application):
101 class NotebookWebApplication(web.Application):
92
102
93 def __init__(self, ipython_app, kernel_manager, notebook_manager, log, settings_overrides):
103 def __init__(self, ipython_app, kernel_manager, notebook_manager, log,
104 base_project_url, settings_overrides):
94 handlers = [
105 handlers = [
95 (r"/", ProjectDashboardHandler),
106 (r"/", ProjectDashboardHandler),
96 (r"/login", LoginHandler),
107 (r"/login", LoginHandler),
97 (r"/logout", LogoutHandler),
108 (r"/logout", LogoutHandler),
98 (r"/new", NewHandler),
109 (r"/new", NewHandler),
99 (r"/%s" % _notebook_id_regex, NamedNotebookHandler),
110 (r"/%s" % _notebook_id_regex, NamedNotebookHandler),
100 (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
111 (r"/%s/copy" % _notebook_id_regex, NotebookCopyHandler),
101 (r"/%s/print" % _notebook_id_regex, PrintNotebookHandler),
112 (r"/%s/print" % _notebook_id_regex, PrintNotebookHandler),
102 (r"/kernels", MainKernelHandler),
113 (r"/kernels", MainKernelHandler),
103 (r"/kernels/%s" % _kernel_id_regex, KernelHandler),
114 (r"/kernels/%s" % _kernel_id_regex, KernelHandler),
104 (r"/kernels/%s/%s" % (_kernel_id_regex, _kernel_action_regex), KernelActionHandler),
115 (r"/kernels/%s/%s" % (_kernel_id_regex, _kernel_action_regex), KernelActionHandler),
105 (r"/kernels/%s/iopub" % _kernel_id_regex, IOPubHandler),
116 (r"/kernels/%s/iopub" % _kernel_id_regex, IOPubHandler),
106 (r"/kernels/%s/shell" % _kernel_id_regex, ShellHandler),
117 (r"/kernels/%s/shell" % _kernel_id_regex, ShellHandler),
107 (r"/notebooks", NotebookRootHandler),
118 (r"/notebooks", NotebookRootHandler),
108 (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler),
119 (r"/notebooks/%s" % _notebook_id_regex, NotebookHandler),
109 (r"/rstservice/render", RSTHandler),
120 (r"/rstservice/render", RSTHandler),
110 (r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}),
121 (r"/files/(.*)", AuthenticatedFileHandler, {'path' : notebook_manager.notebook_dir}),
111 ]
122 ]
112 settings = dict(
123 settings = dict(
113 template_path=os.path.join(os.path.dirname(__file__), "templates"),
124 template_path=os.path.join(os.path.dirname(__file__), "templates"),
114 static_path=os.path.join(os.path.dirname(__file__), "static"),
125 static_path=os.path.join(os.path.dirname(__file__), "static"),
115 cookie_secret=os.urandom(1024),
126 cookie_secret=os.urandom(1024),
116 login_url="/login",
127 login_url="/login",
117 )
128 )
118
129
119 # allow custom overrides for the tornado web app.
130 # allow custom overrides for the tornado web app.
120 settings.update(settings_overrides)
131 settings.update(settings_overrides)
121
132
122 super(NotebookWebApplication, self).__init__(handlers, **settings)
133 # prepend base_project_url onto the patterns that we match
134 new_handlers = []
135 for handler in handlers:
136 pattern = url_path_join(base_project_url, handler[0])
137 new_handler = tuple([pattern]+list(handler[1:]))
138 new_handlers.append( new_handler )
139
140 super(NotebookWebApplication, self).__init__(new_handlers, **settings)
123
141
124 self.kernel_manager = kernel_manager
142 self.kernel_manager = kernel_manager
125 self.log = log
143 self.log = log
126 self.notebook_manager = notebook_manager
144 self.notebook_manager = notebook_manager
127 self.ipython_app = ipython_app
145 self.ipython_app = ipython_app
128 self.read_only = self.ipython_app.read_only
146 self.read_only = self.ipython_app.read_only
129
147
130
148
131 #-----------------------------------------------------------------------------
149 #-----------------------------------------------------------------------------
132 # Aliases and Flags
150 # Aliases and Flags
133 #-----------------------------------------------------------------------------
151 #-----------------------------------------------------------------------------
134
152
135 flags = dict(ipkernel_flags)
153 flags = dict(ipkernel_flags)
136 flags['no-browser']=(
154 flags['no-browser']=(
137 {'NotebookApp' : {'open_browser' : False}},
155 {'NotebookApp' : {'open_browser' : False}},
138 "Don't open the notebook in a browser after startup."
156 "Don't open the notebook in a browser after startup."
139 )
157 )
140 flags['no-mathjax']=(
158 flags['no-mathjax']=(
141 {'NotebookApp' : {'enable_mathjax' : False}},
159 {'NotebookApp' : {'enable_mathjax' : False}},
142 """Disable MathJax
160 """Disable MathJax
143
161
144 MathJax is the javascript library IPython uses to render math/LaTeX. It is
162 MathJax is the javascript library IPython uses to render math/LaTeX. It is
145 very large, so you may want to disable it if you have a slow internet
163 very large, so you may want to disable it if you have a slow internet
146 connection, or for offline use of the notebook.
164 connection, or for offline use of the notebook.
147
165
148 When disabled, equations etc. will appear as their untransformed TeX source.
166 When disabled, equations etc. will appear as their untransformed TeX source.
149 """
167 """
150 )
168 )
151 flags['read-only'] = (
169 flags['read-only'] = (
152 {'NotebookApp' : {'read_only' : True}},
170 {'NotebookApp' : {'read_only' : True}},
153 """Allow read-only access to notebooks.
171 """Allow read-only access to notebooks.
154
172
155 When using a password to protect the notebook server, this flag
173 When using a password to protect the notebook server, this flag
156 allows unauthenticated clients to view the notebook list, and
174 allows unauthenticated clients to view the notebook list, and
157 individual notebooks, but not edit them, start kernels, or run
175 individual notebooks, but not edit them, start kernels, or run
158 code.
176 code.
159
177
160 If no password is set, the server will be entirely read-only.
178 If no password is set, the server will be entirely read-only.
161 """
179 """
162 )
180 )
163
181
164 # Add notebook manager flags
182 # Add notebook manager flags
165 flags.update(boolean_flag('script', 'NotebookManager.save_script',
183 flags.update(boolean_flag('script', 'NotebookManager.save_script',
166 'Auto-save a .py script everytime the .ipynb notebook is saved',
184 'Auto-save a .py script everytime the .ipynb notebook is saved',
167 'Do not auto-save .py scripts for every notebook'))
185 'Do not auto-save .py scripts for every notebook'))
168
186
169 # the flags that are specific to the frontend
187 # the flags that are specific to the frontend
170 # these must be scrubbed before being passed to the kernel,
188 # these must be scrubbed before being passed to the kernel,
171 # or it will raise an error on unrecognized flags
189 # or it will raise an error on unrecognized flags
172 notebook_flags = ['no-browser', 'no-mathjax', 'read-only', 'script', 'no-script']
190 notebook_flags = ['no-browser', 'no-mathjax', 'read-only', 'script', 'no-script']
173
191
174 aliases = dict(ipkernel_aliases)
192 aliases = dict(ipkernel_aliases)
175
193
176 aliases.update({
194 aliases.update({
177 'ip': 'NotebookApp.ip',
195 'ip': 'NotebookApp.ip',
178 'port': 'NotebookApp.port',
196 'port': 'NotebookApp.port',
179 'keyfile': 'NotebookApp.keyfile',
197 'keyfile': 'NotebookApp.keyfile',
180 'certfile': 'NotebookApp.certfile',
198 'certfile': 'NotebookApp.certfile',
181 'notebook-dir': 'NotebookManager.notebook_dir',
199 'notebook-dir': 'NotebookManager.notebook_dir',
182 })
200 })
183
201
184 # remove ipkernel flags that are singletons, and don't make sense in
202 # remove ipkernel flags that are singletons, and don't make sense in
185 # multi-kernel evironment:
203 # multi-kernel evironment:
186 aliases.pop('f', None)
204 aliases.pop('f', None)
187
205
188 notebook_aliases = [u'port', u'ip', u'keyfile', u'certfile',
206 notebook_aliases = [u'port', u'ip', u'keyfile', u'certfile',
189 u'notebook-dir']
207 u'notebook-dir']
190
208
191 #-----------------------------------------------------------------------------
209 #-----------------------------------------------------------------------------
192 # NotebookApp
210 # NotebookApp
193 #-----------------------------------------------------------------------------
211 #-----------------------------------------------------------------------------
194
212
195 class NotebookApp(BaseIPythonApplication):
213 class NotebookApp(BaseIPythonApplication):
196
214
197 name = 'ipython-notebook'
215 name = 'ipython-notebook'
198 default_config_file_name='ipython_notebook_config.py'
216 default_config_file_name='ipython_notebook_config.py'
199
217
200 description = """
218 description = """
201 The IPython HTML Notebook.
219 The IPython HTML Notebook.
202
220
203 This launches a Tornado based HTML Notebook Server that serves up an
221 This launches a Tornado based HTML Notebook Server that serves up an
204 HTML5/Javascript Notebook client.
222 HTML5/Javascript Notebook client.
205 """
223 """
206 examples = _examples
224 examples = _examples
207
225
208 classes = [IPKernelApp, ZMQInteractiveShell, ProfileDir, Session,
226 classes = [IPKernelApp, ZMQInteractiveShell, ProfileDir, Session,
209 MappingKernelManager, NotebookManager]
227 MappingKernelManager, NotebookManager]
210 flags = Dict(flags)
228 flags = Dict(flags)
211 aliases = Dict(aliases)
229 aliases = Dict(aliases)
212
230
213 kernel_argv = List(Unicode)
231 kernel_argv = List(Unicode)
214
232
215 log_level = Enum((0,10,20,30,40,50,'DEBUG','INFO','WARN','ERROR','CRITICAL'),
233 log_level = Enum((0,10,20,30,40,50,'DEBUG','INFO','WARN','ERROR','CRITICAL'),
216 default_value=logging.INFO,
234 default_value=logging.INFO,
217 config=True,
235 config=True,
218 help="Set the log level by value or name.")
236 help="Set the log level by value or name.")
219
237
220 # create requested profiles by default, if they don't exist:
238 # create requested profiles by default, if they don't exist:
221 auto_create = Bool(True)
239 auto_create = Bool(True)
222
240
223 # Network related information.
241 # Network related information.
224
242
225 ip = Unicode(LOCALHOST, config=True,
243 ip = Unicode(LOCALHOST, config=True,
226 help="The IP address the notebook server will listen on."
244 help="The IP address the notebook server will listen on."
227 )
245 )
228
246
229 def _ip_changed(self, name, old, new):
247 def _ip_changed(self, name, old, new):
230 if new == u'*': self.ip = u''
248 if new == u'*': self.ip = u''
231
249
232 port = Integer(8888, config=True,
250 port = Integer(8888, config=True,
233 help="The port the notebook server will listen on."
251 help="The port the notebook server will listen on."
234 )
252 )
235
253
236 certfile = Unicode(u'', config=True,
254 certfile = Unicode(u'', config=True,
237 help="""The full path to an SSL/TLS certificate file."""
255 help="""The full path to an SSL/TLS certificate file."""
238 )
256 )
239
257
240 keyfile = Unicode(u'', config=True,
258 keyfile = Unicode(u'', config=True,
241 help="""The full path to a private key file for usage with SSL/TLS."""
259 help="""The full path to a private key file for usage with SSL/TLS."""
242 )
260 )
243
261
244 password = Unicode(u'', config=True,
262 password = Unicode(u'', config=True,
245 help="""Hashed password to use for web authentication.
263 help="""Hashed password to use for web authentication.
246
264
247 To generate, type in a python/IPython shell:
265 To generate, type in a python/IPython shell:
248
266
249 from IPython.lib import passwd; passwd()
267 from IPython.lib import passwd; passwd()
250
268
251 The string should be of the form type:salt:hashed-password.
269 The string should be of the form type:salt:hashed-password.
252 """
270 """
253 )
271 )
254
272
255 open_browser = Bool(True, config=True,
273 open_browser = Bool(True, config=True,
256 help="Whether to open in a browser after starting.")
274 help="Whether to open in a browser after starting.")
257
275
258 read_only = Bool(False, config=True,
276 read_only = Bool(False, config=True,
259 help="Whether to prevent editing/execution of notebooks."
277 help="Whether to prevent editing/execution of notebooks."
260 )
278 )
261
279
262 webapp_settings = Dict(config=True,
280 webapp_settings = Dict(config=True,
263 help="Supply overrides for the tornado.web.Application that the "
281 help="Supply overrides for the tornado.web.Application that the "
264 "IPython notebook uses.")
282 "IPython notebook uses.")
265
283
266 enable_mathjax = Bool(True, config=True,
284 enable_mathjax = Bool(True, config=True,
267 help="""Whether to enable MathJax for typesetting math/TeX
285 help="""Whether to enable MathJax for typesetting math/TeX
268
286
269 MathJax is the javascript library IPython uses to render math/LaTeX. It is
287 MathJax is the javascript library IPython uses to render math/LaTeX. It is
270 very large, so you may want to disable it if you have a slow internet
288 very large, so you may want to disable it if you have a slow internet
271 connection, or for offline use of the notebook.
289 connection, or for offline use of the notebook.
272
290
273 When disabled, equations etc. will appear as their untransformed TeX source.
291 When disabled, equations etc. will appear as their untransformed TeX source.
274 """
292 """
275 )
293 )
276 def _enable_mathjax_changed(self, name, old, new):
294 def _enable_mathjax_changed(self, name, old, new):
277 """set mathjax url to empty if mathjax is disabled"""
295 """set mathjax url to empty if mathjax is disabled"""
278 if not new:
296 if not new:
279 self.mathjax_url = u''
297 self.mathjax_url = u''
280
298
299 base_project_url = Unicode('/', config=True,
300 help='''The base URL for the notebook server''')
301 base_kernel_url = Unicode('/', config=True,
302 help='''The base URL for the kernel server''')
303 websocket_host = Unicode("", config=True,
304 help="""The hostname for the websocket server."""
305 )
306
281 mathjax_url = Unicode("", config=True,
307 mathjax_url = Unicode("", config=True,
282 help="""The url for MathJax.js."""
308 help="""The url for MathJax.js."""
283 )
309 )
284 def _mathjax_url_default(self):
310 def _mathjax_url_default(self):
285 if not self.enable_mathjax:
311 if not self.enable_mathjax:
286 return u''
312 return u''
287 static_path = self.webapp_settings.get("static_path", os.path.join(os.path.dirname(__file__), "static"))
313 static_path = self.webapp_settings.get("static_path", os.path.join(os.path.dirname(__file__), "static"))
314 static_url_prefix = self.webapp_settings.get("static_url_prefix",
315 "/static/")
288 if os.path.exists(os.path.join(static_path, 'mathjax', "MathJax.js")):
316 if os.path.exists(os.path.join(static_path, 'mathjax', "MathJax.js")):
289 self.log.info("Using local MathJax")
317 self.log.info("Using local MathJax")
290 return u"/static/mathjax/MathJax.js"
318 return static_url_prefix+u"mathjax/MathJax.js"
291 else:
319 else:
292 self.log.info("Using MathJax from CDN")
320 self.log.info("Using MathJax from CDN")
293 return u"http://cdn.mathjax.org/mathjax/latest/MathJax.js"
321 return u"http://cdn.mathjax.org/mathjax/latest/MathJax.js"
294
322
295 def _mathjax_url_changed(self, name, old, new):
323 def _mathjax_url_changed(self, name, old, new):
296 if new and not self.enable_mathjax:
324 if new and not self.enable_mathjax:
297 # enable_mathjax=False overrides mathjax_url
325 # enable_mathjax=False overrides mathjax_url
298 self.mathjax_url = u''
326 self.mathjax_url = u''
299 else:
327 else:
300 self.log.info("Using MathJax: %s", new)
328 self.log.info("Using MathJax: %s", new)
301
329
302 def parse_command_line(self, argv=None):
330 def parse_command_line(self, argv=None):
303 super(NotebookApp, self).parse_command_line(argv)
331 super(NotebookApp, self).parse_command_line(argv)
304 if argv is None:
332 if argv is None:
305 argv = sys.argv[1:]
333 argv = sys.argv[1:]
306
334
307 # Scrub frontend-specific flags
335 # Scrub frontend-specific flags
308 self.kernel_argv = swallow_argv(argv, notebook_aliases, notebook_flags)
336 self.kernel_argv = swallow_argv(argv, notebook_aliases, notebook_flags)
309 # Kernel should inherit default config file from frontend
337 # Kernel should inherit default config file from frontend
310 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
338 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
311
339
312 def init_configurables(self):
340 def init_configurables(self):
313 # force Session default to be secure
341 # force Session default to be secure
314 default_secure(self.config)
342 default_secure(self.config)
315 # Create a KernelManager and start a kernel.
343 # Create a KernelManager and start a kernel.
316 self.kernel_manager = MappingKernelManager(
344 self.kernel_manager = MappingKernelManager(
317 config=self.config, log=self.log, kernel_argv=self.kernel_argv,
345 config=self.config, log=self.log, kernel_argv=self.kernel_argv,
318 connection_dir = self.profile_dir.security_dir,
346 connection_dir = self.profile_dir.security_dir,
319 )
347 )
320 self.notebook_manager = NotebookManager(config=self.config, log=self.log)
348 self.notebook_manager = NotebookManager(config=self.config, log=self.log)
321 self.notebook_manager.list_notebooks()
349 self.notebook_manager.list_notebooks()
322
350
323 def init_logging(self):
351 def init_logging(self):
324 super(NotebookApp, self).init_logging()
352 super(NotebookApp, self).init_logging()
325 # This prevents double log messages because tornado use a root logger that
353 # This prevents double log messages because tornado use a root logger that
326 # self.log is a child of. The logging module dipatches log messages to a log
354 # self.log is a child of. The logging module dipatches log messages to a log
327 # and all of its ancenstors until propagate is set to False.
355 # and all of its ancenstors until propagate is set to False.
328 self.log.propagate = False
356 self.log.propagate = False
329
357
330 def init_webapp(self):
358 def init_webapp(self):
331 """initialize tornado webapp and httpserver"""
359 """initialize tornado webapp and httpserver"""
332 self.web_app = NotebookWebApplication(
360 self.web_app = NotebookWebApplication(
333 self, self.kernel_manager, self.notebook_manager, self.log,
361 self, self.kernel_manager, self.notebook_manager, self.log,
334 self.webapp_settings
362 self.base_project_url, self.webapp_settings
335 )
363 )
336 if self.certfile:
364 if self.certfile:
337 ssl_options = dict(certfile=self.certfile)
365 ssl_options = dict(certfile=self.certfile)
338 if self.keyfile:
366 if self.keyfile:
339 ssl_options['keyfile'] = self.keyfile
367 ssl_options['keyfile'] = self.keyfile
340 else:
368 else:
341 ssl_options = None
369 ssl_options = None
342 self.web_app.password = self.password
370 self.web_app.password = self.password
343 self.http_server = httpserver.HTTPServer(self.web_app, ssl_options=ssl_options)
371 self.http_server = httpserver.HTTPServer(self.web_app, ssl_options=ssl_options)
344 if ssl_options is None and not self.ip and not (self.read_only and not self.password):
372 if ssl_options is None and not self.ip and not (self.read_only and not self.password):
345 self.log.critical('WARNING: the notebook server is listening on all IP addresses '
373 self.log.critical('WARNING: the notebook server is listening on all IP addresses '
346 'but not using any encryption or authentication. This is highly '
374 'but not using any encryption or authentication. This is highly '
347 'insecure and not recommended.')
375 'insecure and not recommended.')
348
376
349 # Try random ports centered around the default.
377 # Try random ports centered around the default.
350 from random import randint
378 from random import randint
351 n = 50 # Max number of attempts, keep reasonably large.
379 n = 50 # Max number of attempts, keep reasonably large.
352 for port in range(self.port, self.port+5) + [self.port + randint(-2*n, 2*n) for i in range(n-5)]:
380 for port in range(self.port, self.port+5) + [self.port + randint(-2*n, 2*n) for i in range(n-5)]:
353 try:
381 try:
354 self.http_server.listen(port, self.ip)
382 self.http_server.listen(port, self.ip)
355 except socket.error, e:
383 except socket.error, e:
356 if e.errno != errno.EADDRINUSE:
384 if e.errno != errno.EADDRINUSE:
357 raise
385 raise
358 self.log.info('The port %i is already in use, trying another random port.' % port)
386 self.log.info('The port %i is already in use, trying another random port.' % port)
359 else:
387 else:
360 self.port = port
388 self.port = port
361 break
389 break
362
390
363 @catch_config_error
391 @catch_config_error
364 def initialize(self, argv=None):
392 def initialize(self, argv=None):
365 super(NotebookApp, self).initialize(argv)
393 super(NotebookApp, self).initialize(argv)
366 self.init_configurables()
394 self.init_configurables()
367 self.init_webapp()
395 self.init_webapp()
368
396
369 def cleanup_kernels(self):
397 def cleanup_kernels(self):
370 """shutdown all kernels
398 """shutdown all kernels
371
399
372 The kernels will shutdown themselves when this process no longer exists,
400 The kernels will shutdown themselves when this process no longer exists,
373 but explicit shutdown allows the KernelManagers to cleanup the connection files.
401 but explicit shutdown allows the KernelManagers to cleanup the connection files.
374 """
402 """
375 self.log.info('Shutting down kernels')
403 self.log.info('Shutting down kernels')
376 km = self.kernel_manager
404 km = self.kernel_manager
377 # copy list, since kill_kernel deletes keys
405 # copy list, since kill_kernel deletes keys
378 for kid in list(km.kernel_ids):
406 for kid in list(km.kernel_ids):
379 km.kill_kernel(kid)
407 km.kill_kernel(kid)
380
408
381 def start(self):
409 def start(self):
382 ip = self.ip if self.ip else '[all ip addresses on your system]'
410 ip = self.ip if self.ip else '[all ip addresses on your system]'
383 proto = 'https' if self.certfile else 'http'
411 proto = 'https' if self.certfile else 'http'
384 info = self.log.info
412 info = self.log.info
385 info("The IPython Notebook is running at: %s://%s:%i" %
413 info("The IPython Notebook is running at: %s://%s:%i" %
386 (proto, ip, self.port) )
414 (proto, ip, self.port) )
387 info("Use Control-C to stop this server and shut down all kernels.")
415 info("Use Control-C to stop this server and shut down all kernels.")
388
416
389 if self.open_browser:
417 if self.open_browser:
390 ip = self.ip or '127.0.0.1'
418 ip = self.ip or '127.0.0.1'
391 b = lambda : webbrowser.open("%s://%s:%i" % (proto, ip, self.port),
419 b = lambda : webbrowser.open("%s://%s:%i" % (proto, ip, self.port),
392 new=2)
420 new=2)
393 threading.Thread(target=b).start()
421 threading.Thread(target=b).start()
394 try:
422 try:
395 ioloop.IOLoop.instance().start()
423 ioloop.IOLoop.instance().start()
396 except KeyboardInterrupt:
424 except KeyboardInterrupt:
397 info("Interrupted...")
425 info("Interrupted...")
398 finally:
426 finally:
399 self.cleanup_kernels()
427 self.cleanup_kernels()
400
428
401
429
402 #-----------------------------------------------------------------------------
430 #-----------------------------------------------------------------------------
403 # Main entry point
431 # Main entry point
404 #-----------------------------------------------------------------------------
432 #-----------------------------------------------------------------------------
405
433
406 def launch_new_instance():
434 def launch_new_instance():
407 app = NotebookApp.instance()
435 app = NotebookApp.instance()
408 app.initialize()
436 app.initialize()
409 app.start()
437 app.start()
410
438
@@ -1,179 +1,179 b''
1 //----------------------------------------------------------------------------
1 //----------------------------------------------------------------------------
2 // Copyright (C) 2008-2011 The IPython Development Team
2 // Copyright (C) 2008-2011 The IPython Development Team
3 //
3 //
4 // Distributed under the terms of the BSD License. The full license is in
4 // Distributed under the terms of the BSD License. The full license is in
5 // the file COPYING, distributed as part of this software.
5 // the file COPYING, distributed as part of this software.
6 //----------------------------------------------------------------------------
6 //----------------------------------------------------------------------------
7
7
8 //============================================================================
8 //============================================================================
9 // SaveWidget
9 // SaveWidget
10 //============================================================================
10 //============================================================================
11
11
12 var IPython = (function (IPython) {
12 var IPython = (function (IPython) {
13
13
14 var utils = IPython.utils;
14 var utils = IPython.utils;
15
15
16 var SaveWidget = function (selector) {
16 var SaveWidget = function (selector) {
17 this.selector = selector;
17 this.selector = selector;
18 this.notebook_name_blacklist_re = /[\/\\]/;
18 this.notebook_name_blacklist_re = /[\/\\]/;
19 this.last_saved_name = '';
19 this.last_saved_name = '';
20 if (this.selector !== undefined) {
20 if (this.selector !== undefined) {
21 this.element = $(selector);
21 this.element = $(selector);
22 this.style();
22 this.style();
23 this.bind_events();
23 this.bind_events();
24 }
24 }
25 };
25 };
26
26
27
27
28 SaveWidget.prototype.style = function () {
28 SaveWidget.prototype.style = function () {
29 this.element.find('span#save_widget').addClass('ui-widget');
29 this.element.find('span#save_widget').addClass('ui-widget');
30 this.element.find('span#notebook_name').addClass('ui-widget ui-widget-content');
30 this.element.find('span#notebook_name').addClass('ui-widget ui-widget-content');
31 this.element.find('span#save_status').addClass('ui-widget ui-widget-content')
31 this.element.find('span#save_status').addClass('ui-widget ui-widget-content')
32 .css({border: 'none', 'margin-left': '20px'});
32 .css({border: 'none', 'margin-left': '20px'});
33 };
33 };
34
34
35
35
36 SaveWidget.prototype.bind_events = function () {
36 SaveWidget.prototype.bind_events = function () {
37 var that = this;
37 var that = this;
38 this.element.find('span#notebook_name').click(function () {
38 this.element.find('span#notebook_name').click(function () {
39 that.rename_notebook();
39 that.rename_notebook();
40 });
40 });
41 this.element.find('span#notebook_name').hover(function () {
41 this.element.find('span#notebook_name').hover(function () {
42 $(this).addClass("ui-state-hover");
42 $(this).addClass("ui-state-hover");
43 }, function () {
43 }, function () {
44 $(this).removeClass("ui-state-hover");
44 $(this).removeClass("ui-state-hover");
45 });
45 });
46 };
46 };
47
47
48
48
49 SaveWidget.prototype.save_notebook = function () {
49 SaveWidget.prototype.save_notebook = function () {
50 IPython.notebook.save_notebook();
50 IPython.notebook.save_notebook();
51 };
51 };
52
52
53
53
54 SaveWidget.prototype.rename_notebook = function () {
54 SaveWidget.prototype.rename_notebook = function () {
55 var that = this;
55 var that = this;
56 var dialog = $('<div/>');
56 var dialog = $('<div/>');
57 dialog.append(
57 dialog.append(
58 $('<h3/>').html('Enter a new notebook name:')
58 $('<h3/>').html('Enter a new notebook name:')
59 .css({'margin-bottom': '10px'})
59 .css({'margin-bottom': '10px'})
60 );
60 );
61 dialog.append(
61 dialog.append(
62 $('<input/>').attr('type','text').attr('size','25')
62 $('<input/>').attr('type','text').attr('size','25')
63 .addClass('ui-widget ui-widget-content')
63 .addClass('ui-widget ui-widget-content')
64 .attr('value',that.get_notebook_name())
64 .attr('value',that.get_notebook_name())
65 );
65 );
66 // $(document).append(dialog);
66 // $(document).append(dialog);
67 dialog.dialog({
67 dialog.dialog({
68 resizable: false,
68 resizable: false,
69 modal: true,
69 modal: true,
70 title: "Rename Notebook",
70 title: "Rename Notebook",
71 closeText: "",
71 closeText: "",
72 close: function(event, ui) {$(this).dialog('destroy').remove();},
72 close: function(event, ui) {$(this).dialog('destroy').remove();},
73 buttons : {
73 buttons : {
74 "OK": function () {
74 "OK": function () {
75 var new_name = $(this).find('input').attr('value');
75 var new_name = $(this).find('input').attr('value');
76 if (!that.test_notebook_name(new_name)) {
76 if (!that.test_notebook_name(new_name)) {
77 $(this).find('h3').html(
77 $(this).find('h3').html(
78 "Invalid notebook name. Notebook names must "+
78 "Invalid notebook name. Notebook names must "+
79 "have 1 or more characters and can contain any characters " +
79 "have 1 or more characters and can contain any characters " +
80 "except / and \\. Please enter a new notebook name:"
80 "except / and \\. Please enter a new notebook name:"
81 );
81 );
82 } else {
82 } else {
83 that.set_notebook_name(new_name);
83 that.set_notebook_name(new_name);
84 that.save_notebook();
84 that.save_notebook();
85 $(this).dialog('close');
85 $(this).dialog('close');
86 }
86 }
87 },
87 },
88 "Cancel": function () {
88 "Cancel": function () {
89 $(this).dialog('close');
89 $(this).dialog('close');
90 }
90 }
91 }
91 }
92 });
92 });
93 }
93 }
94
94
95 SaveWidget.prototype.notebook_saved = function () {
95 SaveWidget.prototype.notebook_saved = function () {
96 this.set_document_title();
96 this.set_document_title();
97 this.last_saved_name = this.get_notebook_name();
97 this.last_saved_name = this.get_notebook_name();
98 };
98 };
99
99
100
100
101 SaveWidget.prototype.get_notebook_name = function () {
101 SaveWidget.prototype.get_notebook_name = function () {
102 return this.element.find('span#notebook_name').html();
102 return this.element.find('span#notebook_name').html();
103 };
103 };
104
104
105
105
106 SaveWidget.prototype.set_notebook_name = function (nbname) {
106 SaveWidget.prototype.set_notebook_name = function (nbname) {
107 this.element.find('span#notebook_name').html(nbname);
107 this.element.find('span#notebook_name').html(nbname);
108 this.set_document_title();
108 this.set_document_title();
109 this.last_saved_name = nbname;
109 this.last_saved_name = nbname;
110 };
110 };
111
111
112
112
113 SaveWidget.prototype.set_document_title = function () {
113 SaveWidget.prototype.set_document_title = function () {
114 nbname = this.get_notebook_name();
114 nbname = this.get_notebook_name();
115 document.title = nbname;
115 document.title = nbname;
116 };
116 };
117
117
118
118
119 SaveWidget.prototype.get_notebook_id = function () {
119 SaveWidget.prototype.get_notebook_id = function () {
120 return $('body').data('notebookId');
120 return $('body').data('notebookId');
121 };
121 };
122
122
123
123
124 SaveWidget.prototype.update_url = function () {
124 SaveWidget.prototype.update_url = function () {
125 var notebook_id = this.get_notebook_id();
125 var notebook_id = this.get_notebook_id();
126 if (notebook_id !== '') {
126 if (notebook_id !== '') {
127 var new_url = '/'+notebook_id;
127 var new_url = $('body').data('baseProjectUrl') + notebook_id;
128 window.history.replaceState({}, '', new_url);
128 window.history.replaceState({}, '', new_url);
129 };
129 };
130 };
130 };
131
131
132
132
133 SaveWidget.prototype.test_notebook_name = function (nbname) {
133 SaveWidget.prototype.test_notebook_name = function (nbname) {
134 nbname = nbname || '';
134 nbname = nbname || '';
135 if (this.notebook_name_blacklist_re.test(nbname) == false && nbname.length>0) {
135 if (this.notebook_name_blacklist_re.test(nbname) == false && nbname.length>0) {
136 return true;
136 return true;
137 } else {
137 } else {
138 return false;
138 return false;
139 };
139 };
140 };
140 };
141
141
142
142
143 SaveWidget.prototype.set_last_saved = function () {
143 SaveWidget.prototype.set_last_saved = function () {
144 var d = new Date();
144 var d = new Date();
145 $('#save_status').html('Last saved: '+d.format('mmm dd h:MM TT'));
145 $('#save_status').html('Last saved: '+d.format('mmm dd h:MM TT'));
146
146
147 };
147 };
148
148
149 SaveWidget.prototype.reset_status = function () {
149 SaveWidget.prototype.reset_status = function () {
150 this.element.find('span#save_status').html('');
150 this.element.find('span#save_status').html('');
151 };
151 };
152
152
153
153
154 SaveWidget.prototype.status_last_saved = function () {
154 SaveWidget.prototype.status_last_saved = function () {
155 this.set_last_saved();
155 this.set_last_saved();
156 };
156 };
157
157
158
158
159 SaveWidget.prototype.status_saving = function () {
159 SaveWidget.prototype.status_saving = function () {
160 this.element.find('span#save_status').html('Saving...');
160 this.element.find('span#save_status').html('Saving...');
161 };
161 };
162
162
163
163
164 SaveWidget.prototype.status_save_failed = function () {
164 SaveWidget.prototype.status_save_failed = function () {
165 this.element.find('span#save_status').html('Save failed');
165 this.element.find('span#save_status').html('Save failed');
166 };
166 };
167
167
168
168
169 SaveWidget.prototype.status_loading = function () {
169 SaveWidget.prototype.status_loading = function () {
170 this.element.find('span#save_status').html('Loading...');
170 this.element.find('span#save_status').html('Loading...');
171 };
171 };
172
172
173
173
174 IPython.SaveWidget = SaveWidget;
174 IPython.SaveWidget = SaveWidget;
175
175
176 return IPython;
176 return IPython;
177
177
178 }(IPython));
178 }(IPython));
179
179
@@ -1,86 +1,86 b''
1 <!DOCTYPE HTML>
1 <!DOCTYPE HTML>
2 <html>
2 <html>
3
3
4 <head>
4 <head>
5 <meta charset="utf-8">
5 <meta charset="utf-8">
6
6
7 <title>{% block title %}IPython Notebook{% end %}</title>
7 <title>{% block title %}IPython Notebook{% end %}</title>
8
8
9 <link rel="stylesheet" href="/static/jquery/css/themes/base/jquery-ui.min.css" type="text/css" />
9 <link rel="stylesheet" href="{{static_url("jquery/css/themes/base/jquery-ui.min.css") }}" type="text/css" />
10 <link rel="stylesheet" href="/static/css/boilerplate.css" type="text/css" />
10 <link rel="stylesheet" href="{{static_url("css/boilerplate.css") }}" type="text/css" />
11 <link rel="stylesheet" href="/static/css/layout.css" type="text/css" />
11 <link rel="stylesheet" href="{{static_url("css/layout.css") }}" type="text/css" />
12 <link rel="stylesheet" href="/static/css/base.css" type="text/css"/>
12 <link rel="stylesheet" href="{{static_url("css/base.css") }}" type="text/css"/>
13 {% block stylesheet %}
13 {% block stylesheet %}
14 {% end %}
14 {% end %}
15
15
16 {% block meta %}
16 {% block meta %}
17 {% end %}
17 {% end %}
18
18
19 </head>
19 </head>
20
20
21 <body {% block params %}{% end %}>
21 <body {% block params %}{% end %}>
22
22
23 <div id="header">
23 <div id="header">
24 <span id="ipython_notebook"><h1><img src='/static/ipynblogo.png' alt='IPython Notebook'/></h1></span>
24 <span id="ipython_notebook"><h1><img src='{{static_url("ipynblogo.png") }}' alt='IPython Notebook'/></h1></span>
25
25
26 {% block login_widget %}
26 {% block login_widget %}
27
27
28 <span id="login_widget">
28 <span id="login_widget">
29 {% if logged_in %}
29 {% if logged_in %}
30 <button id="logout">Logout</button>
30 <button id="logout">Logout</button>
31 {% elif login_available and not logged_in %}
31 {% elif login_available and not logged_in %}
32 <button id="login">Login</button>
32 <button id="login">Login</button>
33 {% end %}
33 {% end %}
34 </span>
34 </span>
35
35
36 {% end %}
36 {% end %}
37
37
38 {% block header %}
38 {% block header %}
39 {% end %}
39 {% end %}
40 </div>
40 </div>
41
41
42 <div id="header_border"></div>
42 <div id="header_border"></div>
43
43
44 <div id="main_app">
44 <div id="main_app">
45
45
46 <div id="app_hbox">
46 <div id="app_hbox">
47
47
48 <div id="left_panel">
48 <div id="left_panel">
49 {% block left_panel %}
49 {% block left_panel %}
50 {% end %}
50 {% end %}
51 </div>
51 </div>
52
52
53 <div id="content_panel">
53 <div id="content_panel">
54 {% if message %}
54 {% if message %}
55
55
56 {% for key in message %}
56 {% for key in message %}
57 <div class="message {{key}}">
57 <div class="message {{key}}">
58 {{message[key]}}
58 {{message[key]}}
59 </div>
59 </div>
60 {% end %}
60 {% end %}
61 {% end %}
61 {% end %}
62
62
63 {% block content_panel %}
63 {% block content_panel %}
64 {% end %}
64 {% end %}
65 </div>
65 </div>
66 <div id="right_panel">
66 <div id="right_panel">
67 {% block right_panel %}
67 {% block right_panel %}
68 {% end %}
68 {% end %}
69 </div>
69 </div>
70
70
71 </div>
71 </div>
72
72
73 </div>
73 </div>
74
74
75 <script src="/static/jquery/js/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
75 <script src="{{static_url("jquery/js/jquery-1.7.1.min.js") }}" type="text/javascript" charset="utf-8"></script>
76 <script src="/static/jquery/js/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
76 <script src="{{static_url("jquery/js/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script>
77 <script src="/static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
77 <script src="{{static_url("js/namespace.js") }}" type="text/javascript" charset="utf-8"></script>
78 <script src="/static/js/loginmain.js" type="text/javascript" charset="utf-8"></script>
78 <script src="{{static_url("js/loginmain.js") }}" type="text/javascript" charset="utf-8"></script>
79 <script src="/static/js/loginwidget.js" type="text/javascript" charset="utf-8"></script>
79 <script src="{{static_url("js/loginwidget.js") }}" type="text/javascript" charset="utf-8"></script>
80
80
81 {% block script %}
81 {% block script %}
82 {% end %}
82 {% end %}
83
83
84 </body>
84 </body>
85
85
86 </html>
86 </html>
@@ -1,227 +1,227 b''
1 <!DOCTYPE HTML>
1 <!DOCTYPE HTML>
2 <html>
2 <html>
3
3
4 <head>
4 <head>
5 <meta charset="utf-8">
5 <meta charset="utf-8">
6
6
7 <title>IPython Notebook</title>
7 <title>IPython Notebook</title>
8
8
9 {% if mathjax_url %}
9 {% if mathjax_url %}
10 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
10 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
11 {% end %}
11 {% end %}
12 <script type="text/javascript">
12 <script type="text/javascript">
13 // MathJax disabled, set as null to distingish from *missing* MathJax,
13 // MathJax disabled, set as null to distingish from *missing* MathJax,
14 // where it will be undefined, and should prompt a dialog later.
14 // where it will be undefined, and should prompt a dialog later.
15 window.mathjax_url = "{{mathjax_url}}";
15 window.mathjax_url = "{{mathjax_url}}";
16 </script>
16 </script>
17
17
18 <link rel="stylesheet" href="/static/jquery/css/themes/base/jquery-ui.min.css" type="text/css" />
18 <link rel="stylesheet" href="{{ static_url("jquery/css/themes/base/jquery-ui.min.css") }}" type="text/css" />
19 <link rel="stylesheet" href="/static/codemirror/lib/codemirror.css">
19 <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}">
20 <link rel="stylesheet" href="/static/codemirror/theme/ipython.css">
20 <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}">
21
21
22 <link rel="stylesheet" href="/static/prettify/prettify.css"/>
22 <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/>
23
23
24 <link rel="stylesheet" href="/static/css/boilerplate.css" type="text/css" />
24 <link rel="stylesheet" href="{{ static_url("css/boilerplate.css") }}" type="text/css" />
25 <link rel="stylesheet" href="/static/css/layout.css" type="text/css" />
25 <link rel="stylesheet" href="{{ static_url("css/layout.css") }}" type="text/css" />
26 <link rel="stylesheet" href="/static/css/base.css" type="text/css" />
26 <link rel="stylesheet" href="{{ static_url("css/base.css") }}" type="text/css" />
27 <link rel="stylesheet" href="/static/css/notebook.css" type="text/css" />
27 <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" />
28 <link rel="stylesheet" href="/static/css/renderedhtml.css" type="text/css" />
28 <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" />
29
29
30 {% comment In the notebook, the read-only flag is used to determine %}
30 {% comment In the notebook, the read-only flag is used to determine %}
31 {% comment whether to hide the side panels and switch off input %}
31 {% comment whether to hide the side panels and switch off input %}
32 <meta name="read_only" content="{{read_only and not logged_in}}"/>
32 <meta name="read_only" content="{{read_only and not logged_in}}"/>
33
33
34 </head>
34 </head>
35
35
36 <body
36 <body
37 data-project={{project}} data-notebook-id={{notebook_id}}
37 data-project={{project}} data-notebook-id={{notebook_id}}
38 data-base-project-url={{base_project_url}} data-base-kernel-url={{base_kernel_url}}
38 data-base-project-url={{base_project_url}} data-base-kernel-url={{base_kernel_url}}
39 >
39 >
40
40
41 <div id="header">
41 <div id="header">
42 <span id="ipython_notebook"><h1><a href='..' alt='dashboard'><img src='/static/ipynblogo.png' alt='IPython Notebook'/></a></h1></span>
42 <span id="ipython_notebook"><h1><a href='..' alt='dashboard'><img src='{{static_url("ipynblogo.png")}}' alt='IPython Notebook'/></a></h1></span>
43 <span id="save_widget">
43 <span id="save_widget">
44 <span id="notebook_name"></span>
44 <span id="notebook_name"></span>
45 <span id="save_status"></span>
45 <span id="save_status"></span>
46 </span>
46 </span>
47
47
48 <span id="login_widget">
48 <span id="login_widget">
49 {% comment This is a temporary workaround to hide the logout button %}
49 {% comment This is a temporary workaround to hide the logout button %}
50 {% comment when appropriate until notebook.html is templated %}
50 {% comment when appropriate until notebook.html is templated %}
51 {% if logged_in %}
51 {% if logged_in %}
52 <button id="logout">Logout</button>
52 <button id="logout">Logout</button>
53 {% elif not logged_in and login_available %}
53 {% elif not logged_in and login_available %}
54 <button id="login">Login</button>
54 <button id="login">Login</button>
55 {% end %}
55 {% end %}
56 </span>
56 </span>
57
57
58 <span id="kernel_status">Idle</span>
58 <span id="kernel_status">Idle</span>
59 </div>
59 </div>
60
60
61 <div id="menubar">
61 <div id="menubar">
62 <ul id="menus">
62 <ul id="menus">
63 <li><a href="#">File</a>
63 <li><a href="#">File</a>
64 <ul>
64 <ul>
65 <li id="new_notebook"><a href="#">New</a></li>
65 <li id="new_notebook"><a href="#">New</a></li>
66 <li id="open_notebook"><a href="#">Open...</a></li>
66 <li id="open_notebook"><a href="#">Open...</a></li>
67 <hr/>
67 <hr/>
68 <li id="copy_notebook"><a href="#">Make a Copy...</a></li>
68 <li id="copy_notebook"><a href="#">Make a Copy...</a></li>
69 <li id="rename_notebook"><a href="#">Rename...</a></li>
69 <li id="rename_notebook"><a href="#">Rename...</a></li>
70 <li id="save_notebook"><a href="#">Save</a></li>
70 <li id="save_notebook"><a href="#">Save</a></li>
71 <hr/>
71 <hr/>
72 <li><a href="#">Download as</a>
72 <li><a href="#">Download as</a>
73 <ul>
73 <ul>
74 <li id="download_ipynb"><a href="#">IPython (.ipynb)</a></li>
74 <li id="download_ipynb"><a href="#">IPython (.ipynb)</a></li>
75 <li id="download_py"><a href="#">Python (.py)</a></li>
75 <li id="download_py"><a href="#">Python (.py)</a></li>
76 </ul>
76 </ul>
77 </li>
77 </li>
78 <hr/>
78 <hr/>
79 <li id="print_notebook"><a href="/{{notebook_id}}/print" target="_blank">Print View</a></li>
79 <li id="print_notebook"><a href="/{{notebook_id}}/print" target="_blank">Print View</a></li>
80 </ul>
80 </ul>
81 </li>
81 </li>
82 <li><a href="#">Edit</a>
82 <li><a href="#">Edit</a>
83 <ul>
83 <ul>
84 <li id="cut_cell"><a href="#">Cut Cell</a></li>
84 <li id="cut_cell"><a href="#">Cut Cell</a></li>
85 <li id="copy_cell"><a href="#">Copy Cell</a></li>
85 <li id="copy_cell"><a href="#">Copy Cell</a></li>
86 <li id="paste_cell" class="ui-state-disabled"><a href="#">Paste Cell</a></li>
86 <li id="paste_cell" class="ui-state-disabled"><a href="#">Paste Cell</a></li>
87 <li id="paste_cell_above" class="ui-state-disabled"><a href="#">Paste Cell Above</a></li>
87 <li id="paste_cell_above" class="ui-state-disabled"><a href="#">Paste Cell Above</a></li>
88 <li id="paste_cell_below" class="ui-state-disabled"><a href="#">Paste Cell Below</a></li>
88 <li id="paste_cell_below" class="ui-state-disabled"><a href="#">Paste Cell Below</a></li>
89 <li id="delete_cell"><a href="#">Delete</a></li>
89 <li id="delete_cell"><a href="#">Delete</a></li>
90 <hr/>
90 <hr/>
91 <li id="split_cell"><a href="#">Split Cell</a></li>
91 <li id="split_cell"><a href="#">Split Cell</a></li>
92 <li id="merge_cell_above"><a href="#">Merge Cell Above</a></li>
92 <li id="merge_cell_above"><a href="#">Merge Cell Above</a></li>
93 <li id="merge_cell_below"><a href="#">Merge Cell Below</a></li>
93 <li id="merge_cell_below"><a href="#">Merge Cell Below</a></li>
94 <hr/>
94 <hr/>
95 <li id="move_cell_up"><a href="#">Move Cell Up</a></li>
95 <li id="move_cell_up"><a href="#">Move Cell Up</a></li>
96 <li id="move_cell_down"><a href="#">Move Cell Down</a></li>
96 <li id="move_cell_down"><a href="#">Move Cell Down</a></li>
97 <hr/>
97 <hr/>
98 <li id="select_previous"><a href="#">Select Previous Cell</a></li>
98 <li id="select_previous"><a href="#">Select Previous Cell</a></li>
99 <li id="select_next"><a href="#">Select Next Cell</a></li>
99 <li id="select_next"><a href="#">Select Next Cell</a></li>
100 </ul>
100 </ul>
101 </li>
101 </li>
102 <li><a href="#">View</a>
102 <li><a href="#">View</a>
103 <ul>
103 <ul>
104 <li id="toggle_header"><a href="#">Toggle Header</a></li>
104 <li id="toggle_header"><a href="#">Toggle Header</a></li>
105 <li id="toggle_toolbar"><a href="#">Toggle Toolbar</a></li>
105 <li id="toggle_toolbar"><a href="#">Toggle Toolbar</a></li>
106 </ul>
106 </ul>
107 </li>
107 </li>
108 <li><a href="#">Insert</a>
108 <li><a href="#">Insert</a>
109 <ul>
109 <ul>
110 <li id="insert_cell_above"><a href="#">Insert Cell Above</a></li>
110 <li id="insert_cell_above"><a href="#">Insert Cell Above</a></li>
111 <li id="insert_cell_below"><a href="#">Insert Cell Below</a></li>
111 <li id="insert_cell_below"><a href="#">Insert Cell Below</a></li>
112 </ul>
112 </ul>
113 </li>
113 </li>
114 <li><a href="#">Cell</a>
114 <li><a href="#">Cell</a>
115 <ul>
115 <ul>
116 <li id="run_cell"><a href="#">Run</a></li>
116 <li id="run_cell"><a href="#">Run</a></li>
117 <li id="run_cell_in_place"><a href="#">Run in Place</a></li>
117 <li id="run_cell_in_place"><a href="#">Run in Place</a></li>
118 <li id="run_all_cells"><a href="#">Run All</a></li>
118 <li id="run_all_cells"><a href="#">Run All</a></li>
119 <hr/>
119 <hr/>
120 <li id="to_code"><a href="#">Code Cell</a></li>
120 <li id="to_code"><a href="#">Code Cell</a></li>
121 <li id="to_markdown"><a href="#">Markdown Cell</a></li>
121 <li id="to_markdown"><a href="#">Markdown Cell</a></li>
122 <hr/>
122 <hr/>
123 <li id="toggle_output"><a href="#">Toggle Output</a></li>
123 <li id="toggle_output"><a href="#">Toggle Output</a></li>
124 <li id="clear_all_output"><a href="#">Clear All Output</a></li>
124 <li id="clear_all_output"><a href="#">Clear All Output</a></li>
125 </ul>
125 </ul>
126 </li>
126 </li>
127 <li><a href="#">Kernel</a>
127 <li><a href="#">Kernel</a>
128 <ul>
128 <ul>
129 <li id="int_kernel"><a href="#">Interrupt</a></li>
129 <li id="int_kernel"><a href="#">Interrupt</a></li>
130 <li id="restart_kernel"><a href="#">Restart</a></li>
130 <li id="restart_kernel"><a href="#">Restart</a></li>
131 </ul>
131 </ul>
132 </li>
132 </li>
133 <li><a href="#">Help</a>
133 <li><a href="#">Help</a>
134 <ul>
134 <ul>
135 <li><a href="http://ipython.org/documentation.html" target="_blank">IPython Help</a></li>
135 <li><a href="http://ipython.org/documentation.html" target="_blank">IPython Help</a></li>
136 <li><a href="http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html" target="_blank">Notebook Help</a></li>
136 <li><a href="http://ipython.org/ipython-doc/stable/interactive/htmlnotebook.html" target="_blank">Notebook Help</a></li>
137 <li id="keyboard_shortcuts"><a href="#">Keyboard Shortcuts</a></li>
137 <li id="keyboard_shortcuts"><a href="#">Keyboard Shortcuts</a></li>
138 <hr/>
138 <hr/>
139 <li><a href="http://docs.python.org" target="_blank">Python</a></li>
139 <li><a href="http://docs.python.org" target="_blank">Python</a></li>
140 <li><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></li>
140 <li><a href="http://docs.scipy.org/doc/numpy/reference/" target="_blank">NumPy</a></li>
141 <li><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></li>
141 <li><a href="http://docs.scipy.org/doc/scipy/reference/" target="_blank">SciPy</a></li>
142 <li><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></li>
142 <li><a href="http://docs.sympy.org/dev/index.html" target="_blank">SymPy</a></li>
143 <li><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></li>
143 <li><a href="http://matplotlib.sourceforge.net/" target="_blank">Matplotlib</a></li>
144 </ul>
144 </ul>
145 </li>
145 </li>
146 </ul>
146 </ul>
147
147
148 </div>
148 </div>
149
149
150 <div id="toolbar">
150 <div id="toolbar">
151
151
152 <span>
152 <span>
153 <button id="save_b">Save</button>
153 <button id="save_b">Save</button>
154 </span>
154 </span>
155 <span id="cut_copy_paste">
155 <span id="cut_copy_paste">
156 <button id="cut_b" title="Cut Cell">Cut Cell</button>
156 <button id="cut_b" title="Cut Cell">Cut Cell</button>
157 <button id="copy_b" title="Copy Cell">Copy Cell</button>
157 <button id="copy_b" title="Copy Cell">Copy Cell</button>
158 <button id="paste_b" title="Paste Cell">Paste Cell</button>
158 <button id="paste_b" title="Paste Cell">Paste Cell</button>
159 </span>
159 </span>
160 <span id="move_up_down">
160 <span id="move_up_down">
161 <button id="move_up_b" title="Move Cell Up">Move Cell Up</button>
161 <button id="move_up_b" title="Move Cell Up">Move Cell Up</button>
162 <button id="move_down_b" title="Move Cell Down">Move Down</button>
162 <button id="move_down_b" title="Move Cell Down">Move Down</button>
163 </span>
163 </span>
164 <span id="insert_above_below">
164 <span id="insert_above_below">
165 <button id="insert_above_b" title="Insert Cell Above">Insert Cell Above</button>
165 <button id="insert_above_b" title="Insert Cell Above">Insert Cell Above</button>
166 <button id="insert_below_b" title="Insert Cell Below">Insert Cell Below</button>
166 <button id="insert_below_b" title="Insert Cell Below">Insert Cell Below</button>
167 </span>
167 </span>
168 <span id="run_int">
168 <span id="run_int">
169 <button id="run_b" title="Run Cell">Run Cell</button>
169 <button id="run_b" title="Run Cell">Run Cell</button>
170 <button id="interrupt_b" title="Interrupt">Interrupt</button>
170 <button id="interrupt_b" title="Interrupt">Interrupt</button>
171 </span>
171 </span>
172 <span>
172 <span>
173 <select id="cell_type">
173 <select id="cell_type">
174 <option value="code">Code</option>
174 <option value="code">Code</option>
175 <option value="markdown">Markdown</option>
175 <option value="markdown">Markdown</option>
176 </select>
176 </select>
177 </span>
177 </span>
178
178
179 </div>
179 </div>
180
180
181 <div id="main_app">
181 <div id="main_app">
182
182
183 <div id="notebook_panel">
183 <div id="notebook_panel">
184 <div id="notebook"></div>
184 <div id="notebook"></div>
185 <div id="pager_splitter"></div>
185 <div id="pager_splitter"></div>
186 <div id="pager"></div>
186 <div id="pager"></div>
187 </div>
187 </div>
188
188
189 </div>
189 </div>
190
190
191 <script src="/static/jquery/js/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
191 <script src="{{ static_url("jquery/js/jquery-1.7.1.min.js") }}" type="text/javascript" charset="utf-8"></script>
192 <script src="/static/jquery/js/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
192 <script src="{{ static_url("jquery/js/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script>
193
193
194 <script src="/static/codemirror/lib/codemirror.js" charset="utf-8"></script>
194 <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
195 <script src="/static/codemirror/mode/python/python.js" charset="utf-8"></script>
195 <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script>
196 <script src="/static/codemirror/mode/htmlmixed/htmlmixed.js" charset="utf-8"></script>
196 <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
197 <script src="/static/codemirror/mode/xml/xml.js" charset="utf-8"></script>
197 <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
198 <script src="/static/codemirror/mode/javascript/javascript.js" charset="utf-8"></script>
198 <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
199 <script src="/static/codemirror/mode/css/css.js" charset="utf-8"></script>
199 <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script>
200 <script src="/static/codemirror/mode/rst/rst.js" charset="utf-8"></script>
200 <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
201 <script src="/static/codemirror/mode/markdown/markdown.js" charset="utf-8"></script>
201 <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
202
202
203 <script src="/static/pagedown/Markdown.Converter.js" charset="utf-8"></script>
203 <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script>
204
204
205 <script src="/static/prettify/prettify.js" charset="utf-8"></script>
205 <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script>
206 <script src="/static/dateformat/date.format.js" charset="utf-8"></script>
206 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
207
207
208 <script src="/static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
208 <script src="{{ static_url("js/namespace.js") }}" type="text/javascript" charset="utf-8"></script>
209 <script src="/static/js/utils.js" type="text/javascript" charset="utf-8"></script>
209 <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
210 <script src="/static/js/cell.js" type="text/javascript" charset="utf-8"></script>
210 <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
211 <script src="/static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
211 <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
212 <script src="/static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
212 <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
213 <script src="/static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
213 <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
214 <script src="/static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
214 <script src="{{ static_url("js/kernelstatus.js") }}" type="text/javascript" charset="utf-8"></script>
215 <script src="/static/js/layout.js" type="text/javascript" charset="utf-8"></script>
215 <script src="{{ static_url("js/layout.js") }}" type="text/javascript" charset="utf-8"></script>
216 <script src="/static/js/savewidget.js" type="text/javascript" charset="utf-8"></script>
216 <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script>
217 <script src="/static/js/quickhelp.js" type="text/javascript" charset="utf-8"></script>
217 <script src="{{ static_url("js/quickhelp.js") }}" type="text/javascript" charset="utf-8"></script>
218 <script src="/static/js/loginwidget.js" type="text/javascript" charset="utf-8"></script>
218 <script src="{{ static_url("js/loginwidget.js") }}" type="text/javascript" charset="utf-8"></script>
219 <script src="/static/js/pager.js" type="text/javascript" charset="utf-8"></script>
219 <script src="{{ static_url("js/pager.js") }}" type="text/javascript" charset="utf-8"></script>
220 <script src="/static/js/menubar.js" type="text/javascript" charset="utf-8"></script>
220 <script src="{{ static_url("js/menubar.js") }}" type="text/javascript" charset="utf-8"></script>
221 <script src="/static/js/toolbar.js" type="text/javascript" charset="utf-8"></script>
221 <script src="{{ static_url("js/toolbar.js") }}" type="text/javascript" charset="utf-8"></script>
222 <script src="/static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
222 <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
223 <script src="/static/js/notebookmain.js" type="text/javascript" charset="utf-8"></script>
223 <script src="{{ static_url("js/notebookmain.js") }}" type="text/javascript" charset="utf-8"></script>
224
224
225 </body>
225 </body>
226
226
227 </html>
227 </html>
@@ -1,104 +1,104 b''
1 <!DOCTYPE HTML>
1 <!DOCTYPE HTML>
2 <html>
2 <html>
3
3
4 <head>
4 <head>
5 <meta charset="utf-8">
5 <meta charset="utf-8">
6
6
7 <title>IPython Notebook</title>
7 <title>IPython Notebook</title>
8
8
9 {% if mathjax_url %}
9 {% if mathjax_url %}
10 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
10 <script type="text/javascript" src="{{mathjax_url}}?config=TeX-AMS_HTML" charset="utf-8"></script>
11 {% end %}
11 {% end %}
12 <script type="text/javascript">
12 <script type="text/javascript">
13 // MathJax disabled, set as null to distingish from *missing* MathJax,
13 // MathJax disabled, set as null to distingish from *missing* MathJax,
14 // where it will be undefined, and should prompt a dialog later.
14 // where it will be undefined, and should prompt a dialog later.
15 window.mathjax_url = "{{mathjax_url}}";
15 window.mathjax_url = "{{mathjax_url}}";
16 </script>
16 </script>
17
17
18 <link rel="stylesheet" href="/static/jquery/css/themes/base/jquery-ui.min.css" type="text/css" />
18 <link rel="stylesheet" href="{{ static_url("jquery/css/themes/base/jquery-ui.min.css") }}" type="text/css" />
19 <link rel="stylesheet" href="/static/codemirror/lib/codemirror.css">
19 <link rel="stylesheet" href="{{ static_url("codemirror/lib/codemirror.css") }}">
20 <link rel="stylesheet" href="/static/codemirror/mode/markdown/markdown.css">
20 <link rel="stylesheet" href="{{ static_url("codemirror/mode/markdown/markdown.css") }}">
21 <link rel="stylesheet" href="/static/codemirror/mode/rst/rst.css">
21 <link rel="stylesheet" href="{{ static_url("codemirror/mode/rst/rst.css") }}">
22 <link rel="stylesheet" href="/static/codemirror/theme/ipython.css">
22 <link rel="stylesheet" href="{{ static_url("codemirror/theme/ipython.css") }}">
23 <link rel="stylesheet" href="/static/codemirror/theme/default.css">
23 <link rel="stylesheet" href="{{ static_url("codemirror/theme/default.css") }}">
24
24
25 <link rel="stylesheet" href="/static/prettify/prettify.css"/>
25 <link rel="stylesheet" href="{{ static_url("prettify/prettify.css") }}"/>
26
26
27 <link rel="stylesheet" href="/static/css/boilerplate.css" type="text/css" />
27 <link rel="stylesheet" href="{{ static_url("css/boilerplate.css") }}" type="text/css" />
28 <link rel="stylesheet" href="/static/css/layout.css" type="text/css" />
28 <link rel="stylesheet" href="{{ static_url("css/layout.css") }}" type="text/css" />
29 <link rel="stylesheet" href="/static/css/base.css" type="text/css" />
29 <link rel="stylesheet" href="{{ static_url("css/base.css") }}" type="text/css" />
30 <link rel="stylesheet" href="/static/css/notebook.css" type="text/css" />
30 <link rel="stylesheet" href="{{ static_url("css/notebook.css") }}" type="text/css" />
31 <link rel="stylesheet" href="/static/css/printnotebook.css" type="text/css" />
31 <link rel="stylesheet" href="{{ static_url("css/printnotebook.css") }}" type="text/css" />
32 <link rel="stylesheet" href="/static/css/renderedhtml.css" type="text/css" />
32 <link rel="stylesheet" href="{{ static_url("css/renderedhtml.css") }}" type="text/css" />
33
33
34 {% comment In the notebook, the read-only flag is used to determine %}
34 {% comment In the notebook, the read-only flag is used to determine %}
35 {% comment whether to hide the side panels and switch off input %}
35 {% comment whether to hide the side panels and switch off input %}
36 <meta name="read_only" content="{{read_only and not logged_in}}"/>
36 <meta name="read_only" content="{{read_only and not logged_in}}"/>
37
37
38 </head>
38 </head>
39
39
40 <body
40 <body
41 data-project={{project}} data-notebook-id={{notebook_id}}
41 data-project={{project}} data-notebook-id={{notebook_id}}
42 data-base-project-url={{base_project_url}} data-base-kernel-url={{base_kernel_url}}
42 data-base-project-url={{base_project_url}} data-base-kernel-url={{base_kernel_url}}
43 >
43 >
44
44
45 <div id="header">
45 <div id="header">
46 <span id="ipython_notebook"><h1><a href='..' alt='dashboard'><img src='/static/ipynblogo.png' alt='IPython Notebook'/></a></h1></span>
46 <span id="ipython_notebook"><h1><a href='..' alt='dashboard'><img src='{{static_url("ipynblogo.png") }}' alt='IPython Notebook'/></a></h1></span>
47 <span id="save_widget">
47 <span id="save_widget">
48 <span id="notebook_name"></span>
48 <span id="notebook_name"></span>
49 <span id="save_status"></span>
49 <span id="save_status"></span>
50 </span>
50 </span>
51
51
52 <span id="login_widget">
52 <span id="login_widget">
53 {% comment This is a temporary workaround to hide the logout button %}
53 {% comment This is a temporary workaround to hide the logout button %}
54 {% comment when appropriate until notebook.html is templated %}
54 {% comment when appropriate until notebook.html is templated %}
55 {% if logged_in %}
55 {% if logged_in %}
56 <button id="logout">Logout</button>
56 <button id="logout">Logout</button>
57 {% elif not logged_in and login_available %}
57 {% elif not logged_in and login_available %}
58 <button id="login">Login</button>
58 <button id="login">Login</button>
59 {% end %}
59 {% end %}
60 </span>
60 </span>
61
61
62 </div>
62 </div>
63
63
64
64
65 <div id="main_app">
65 <div id="main_app">
66
66
67 <div id="notebook_panel">
67 <div id="notebook_panel">
68 <div id="notebook"></div>
68 <div id="notebook"></div>
69 </div>
69 </div>
70
70
71 </div>
71 </div>
72
72
73 <script src="/static/jquery/js/jquery-1.7.1.min.js" type="text/javascript" charset="utf-8"></script>
73 <script src="{{ static_url("jquery/js/jquery-1.7.1.min.js") }}" type="text/javascript" charset="utf-8"></script>
74 <script src="/static/jquery/js/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
74 <script src="{{ static_url("jquery/js/jquery-ui.min.js") }}" type="text/javascript" charset="utf-8"></script>
75
75
76 <script src="/static/codemirror/lib/codemirror.js" charset="utf-8"></script>
76 <script src="{{ static_url("codemirror/lib/codemirror.js") }}" charset="utf-8"></script>
77 <script src="/static/codemirror/mode/python/python.js" charset="utf-8"></script>
77 <script src="{{ static_url("codemirror/mode/python/python.js") }}" charset="utf-8"></script>
78 <script src="/static/codemirror/mode/htmlmixed/htmlmixed.js" charset="utf-8"></script>
78 <script src="{{ static_url("codemirror/mode/htmlmixed/htmlmixed.js") }}" charset="utf-8"></script>
79 <script src="/static/codemirror/mode/xml/xml.js" charset="utf-8"></script>
79 <script src="{{ static_url("codemirror/mode/xml/xml.js") }}" charset="utf-8"></script>
80 <script src="/static/codemirror/mode/javascript/javascript.js" charset="utf-8"></script>
80 <script src="{{ static_url("codemirror/mode/javascript/javascript.js") }}" charset="utf-8"></script>
81 <script src="/static/codemirror/mode/css/css.js" charset="utf-8"></script>
81 <script src="{{ static_url("codemirror/mode/css/css.js") }}" charset="utf-8"></script>
82 <script src="/static/codemirror/mode/rst/rst.js" charset="utf-8"></script>
82 <script src="{{ static_url("codemirror/mode/rst/rst.js") }}" charset="utf-8"></script>
83 <script src="/static/codemirror/mode/markdown/markdown.js" charset="utf-8"></script>
83 <script src="{{ static_url("codemirror/mode/markdown/markdown.js") }}" charset="utf-8"></script>
84
84
85 <script src="/static/pagedown/Markdown.Converter.js" charset="utf-8"></script>
85 <script src="{{ static_url("pagedown/Markdown.Converter.js") }}" charset="utf-8"></script>
86
86
87 <script src="/static/prettify/prettify.js" charset="utf-8"></script>
87 <script src="{{ static_url("prettify/prettify.js") }}" charset="utf-8"></script>
88 <script src="/static/dateformat/date.format.js" charset="utf-8"></script>
88 <script src="{{ static_url("dateformat/date.format.js") }}" charset="utf-8"></script>
89
89
90 <script src="/static/js/namespace.js" type="text/javascript" charset="utf-8"></script>
90 <script src="{{ static_url("js/namespace.js") }}" type="text/javascript" charset="utf-8"></script>
91 <script src="/static/js/utils.js" type="text/javascript" charset="utf-8"></script>
91 <script src="{{ static_url("js/utils.js") }}" type="text/javascript" charset="utf-8"></script>
92 <script src="/static/js/cell.js" type="text/javascript" charset="utf-8"></script>
92 <script src="{{ static_url("js/cell.js") }}" type="text/javascript" charset="utf-8"></script>
93 <script src="/static/js/codecell.js" type="text/javascript" charset="utf-8"></script>
93 <script src="{{ static_url("js/codecell.js") }}" type="text/javascript" charset="utf-8"></script>
94 <script src="/static/js/textcell.js" type="text/javascript" charset="utf-8"></script>
94 <script src="{{ static_url("js/textcell.js") }}" type="text/javascript" charset="utf-8"></script>
95 <script src="/static/js/kernel.js" type="text/javascript" charset="utf-8"></script>
95 <script src="{{ static_url("js/kernel.js") }}" type="text/javascript" charset="utf-8"></script>
96 <script src="/static/js/kernelstatus.js" type="text/javascript" charset="utf-8"></script>
96 <script src="{{ static_url("js/kernelstatus.js") }}" type="text/javascript" charset="utf-8"></script>
97 <script src="/static/js/savewidget.js" type="text/javascript" charset="utf-8"></script>
97 <script src="{{ static_url("js/savewidget.js") }}" type="text/javascript" charset="utf-8"></script>
98 <script src="/static/js/loginwidget.js" type="text/javascript" charset="utf-8"></script>
98 <script src="{{ static_url("js/loginwidget.js") }}" type="text/javascript" charset="utf-8"></script>
99 <script src="/static/js/notebook.js" type="text/javascript" charset="utf-8"></script>
99 <script src="{{ static_url("js/notebook.js") }}" type="text/javascript" charset="utf-8"></script>
100 <script src="/static/js/printnotebookmain.js" type="text/javascript" charset="utf-8"></script>
100 <script src="{{ static_url("js/printnotebookmain.js") }}" type="text/javascript" charset="utf-8"></script>
101
101
102 </body>
102 </body>
103
103
104 </html>
104 </html>
@@ -1,43 +1,43 b''
1 {% extends layout.html %}
1 {% extends layout.html %}
2
2
3 {% block title %}
3 {% block title %}
4 IPython Dashboard
4 IPython Dashboard
5 {% end %}
5 {% end %}
6
6
7 {% block stylesheet %}
7 {% block stylesheet %}
8 <link rel="stylesheet" href="/static/css/projectdashboard.css" type="text/css" />
8 <link rel="stylesheet" href="{{static_url("css/projectdashboard.css") }}" type="text/css" />
9 {% end %}
9 {% end %}
10
10
11 {% block meta %}
11 {% block meta %}
12 <meta name="read_only" content="{{read_only}}"/>
12 <meta name="read_only" content="{{read_only}}"/>
13 {% end %}
13 {% end %}
14
14
15 {% block params %}
15 {% block params %}
16 data-project={{project}}
16 data-project={{project}}
17 data-base-project-url={{base_project_url}}
17 data-base-project-url={{base_project_url}}
18 data-base-kernel-url={{base_kernel_url}}
18 data-base-kernel-url={{base_kernel_url}}
19 {% end %}
19 {% end %}
20
20
21 {% block content_panel %}
21 {% block content_panel %}
22 {% if logged_in or not read_only %}
22 {% if logged_in or not read_only %}
23
23
24 <div id="content_toolbar">
24 <div id="content_toolbar">
25 <span id="drag_info">Drag files onto the list to import
25 <span id="drag_info">Drag files onto the list to import
26 notebooks.</span>
26 notebooks.</span>
27
27
28 <span id="notebooks_buttons">
28 <span id="notebooks_buttons">
29 <button id="new_notebook">New Notebook</button>
29 <button id="new_notebook">New Notebook</button>
30 </span>
30 </span>
31 </div>
31 </div>
32
32
33 {% end %}
33 {% end %}
34
34
35 <div id="notebook_list">
35 <div id="notebook_list">
36 <div id="project_name"><h2>{{project}}</h2></div>
36 <div id="project_name"><h2>{{project}}</h2></div>
37 </div>
37 </div>
38 {% end %}
38 {% end %}
39
39
40 {% block script %}
40 {% block script %}
41 <script src="/static/js/notebooklist.js" type="text/javascript" charset="utf-8"></script>
41 <script src="{{static_url("js/notebooklist.js") }}" type="text/javascript" charset="utf-8"></script>
42 <script src="/static/js/projectdashboardmain.js" type="text/javascript" charset="utf-8"></script>
42 <script src="{{static_url("js/projectdashboardmain.js") }}" type="text/javascript" charset="utf-8"></script>
43 {% end %}
43 {% end %}
@@ -1,417 +1,432 b''
1 .. _htmlnotebook:
1 .. _htmlnotebook:
2
2
3 =========================
3 =========================
4 An HTML Notebook IPython
4 An HTML Notebook IPython
5 =========================
5 =========================
6
6
7 .. seealso::
7 .. seealso::
8
8
9 :ref:`Installation requirements <installnotebook>` for the Notebook.
9 :ref:`Installation requirements <installnotebook>` for the Notebook.
10
10
11 The IPython Notebook consists of two related components:
11 The IPython Notebook consists of two related components:
12
12
13 * An JSON based Notebook document format for recording and distributing
13 * An JSON based Notebook document format for recording and distributing
14 Python code and rich text.
14 Python code and rich text.
15 * A web-based user interface for authoring and running notebook documents.
15 * A web-based user interface for authoring and running notebook documents.
16
16
17 The Notebook can be used by starting the Notebook server with the
17 The Notebook can be used by starting the Notebook server with the
18 command::
18 command::
19
19
20 $ ipython notebook
20 $ ipython notebook
21
21
22 Note that by default, the notebook doesn't load pylab, it's just a normal
22 Note that by default, the notebook doesn't load pylab, it's just a normal
23 IPython session like any other. If you want pylab support, you must use::
23 IPython session like any other. If you want pylab support, you must use::
24
24
25 $ ipython notebook --pylab
25 $ ipython notebook --pylab
26
26
27 which will behave similar to the terminal and Qt console versions, using your
27 which will behave similar to the terminal and Qt console versions, using your
28 default matplotlib backend and providing floating interactive plot windows. If
28 default matplotlib backend and providing floating interactive plot windows. If
29 you want inline figures, you must manually select the ``inline`` backend::
29 you want inline figures, you must manually select the ``inline`` backend::
30
30
31 $ ipython notebook --pylab inline
31 $ ipython notebook --pylab inline
32
32
33 This server uses the same ZeroMQ-based two process kernel architecture as
33 This server uses the same ZeroMQ-based two process kernel architecture as
34 the QT Console as well Tornado for serving HTTP/S requests. Some of the main
34 the QT Console as well Tornado for serving HTTP/S requests. Some of the main
35 features of the Notebook include:
35 features of the Notebook include:
36
36
37 * Display rich data (png/html/latex/svg) in the browser as a result of
37 * Display rich data (png/html/latex/svg) in the browser as a result of
38 computations.
38 computations.
39 * Compose text cells using HTML and Markdown.
39 * Compose text cells using HTML and Markdown.
40 * Import and export notebook documents in range of formats (.ipynb, .py).
40 * Import and export notebook documents in range of formats (.ipynb, .py).
41 * In browser syntax highlighting, tab completion and autoindentation.
41 * In browser syntax highlighting, tab completion and autoindentation.
42 * Inline matplotlib plots that can be stored in Notebook documents and opened
42 * Inline matplotlib plots that can be stored in Notebook documents and opened
43 later.
43 later.
44
44
45 See :ref:`our installation documentation <install_index>` for directions on
45 See :ref:`our installation documentation <install_index>` for directions on
46 how to install the notebook and its dependencies.
46 how to install the notebook and its dependencies.
47
47
48 .. note::
48 .. note::
49
49
50 You can start more than one notebook server at the same time, if you want to
50 You can start more than one notebook server at the same time, if you want to
51 work on notebooks in different directories. By default the first notebook
51 work on notebooks in different directories. By default the first notebook
52 server starts in port 8888, later notebooks search for random ports near
52 server starts in port 8888, later notebooks search for random ports near
53 that one. You can also manually specify the port with the ``--port``
53 that one. You can also manually specify the port with the ``--port``
54 option.
54 option.
55
55
56
56
57 Basic Usage
57 Basic Usage
58 ===========
58 ===========
59
59
60 The landing page of the notebook server application, which we call the IPython
60 The landing page of the notebook server application, which we call the IPython
61 Notebook *dashboard*, shows the notebooks currently available in the directory
61 Notebook *dashboard*, shows the notebooks currently available in the directory
62 in which the application was started, and allows you to create new notebooks.
62 in which the application was started, and allows you to create new notebooks.
63
63
64 A notebook is a combination of two things:
64 A notebook is a combination of two things:
65
65
66 1. An interactive session connected to an IPython kernel, controlled by a web
66 1. An interactive session connected to an IPython kernel, controlled by a web
67 application that can send input to the console and display many types of
67 application that can send input to the console and display many types of
68 output (text, graphics, mathematics and more). This is the same kernel used
68 output (text, graphics, mathematics and more). This is the same kernel used
69 by the :ref:`Qt console <qtconsole>`, but in this case the web console sends
69 by the :ref:`Qt console <qtconsole>`, but in this case the web console sends
70 input in persistent cells that you can edit in-place instead of the
70 input in persistent cells that you can edit in-place instead of the
71 vertically scrolling terminal style used by the Qt console.
71 vertically scrolling terminal style used by the Qt console.
72
72
73 2. A document that can save the inputs and outputs of the session as well as
73 2. A document that can save the inputs and outputs of the session as well as
74 additional text that accompanies the code but is not meant for execution.
74 additional text that accompanies the code but is not meant for execution.
75 In this way, notebook files serve as a complete computational record of a
75 In this way, notebook files serve as a complete computational record of a
76 session including explanatory text and mathematics, code and resulting
76 session including explanatory text and mathematics, code and resulting
77 figures. These documents are internally JSON files and are saved with the
77 figures. These documents are internally JSON files and are saved with the
78 ``.ipynb`` extension.
78 ``.ipynb`` extension.
79
79
80 If you have ever used the Mathematica or Sage notebooks (the latter is also
80 If you have ever used the Mathematica or Sage notebooks (the latter is also
81 web-based__) you should feel right at home. If you have not, you should be
81 web-based__) you should feel right at home. If you have not, you should be
82 able to learn how to use it in just a few minutes.
82 able to learn how to use it in just a few minutes.
83
83
84 .. __: http://sagenb.org
84 .. __: http://sagenb.org
85
85
86
86
87 Creating and editing notebooks
87 Creating and editing notebooks
88 ------------------------------
88 ------------------------------
89
89
90 You can create new notebooks from the dashboard with the ``New Notebook``
90 You can create new notebooks from the dashboard with the ``New Notebook``
91 button or open existing ones by clicking on their name. Once in a notebook,
91 button or open existing ones by clicking on their name. Once in a notebook,
92 your browser tab will reflect the name of that notebook (prefixed with "IPy:").
92 your browser tab will reflect the name of that notebook (prefixed with "IPy:").
93 The URL for that notebook is not meant to be human-readable and is *not*
93 The URL for that notebook is not meant to be human-readable and is *not*
94 persistent across invocations of the notebook server.
94 persistent across invocations of the notebook server.
95
95
96 You can also drag and drop into the area listing files any python file: it
96 You can also drag and drop into the area listing files any python file: it
97 will be imported into a notebook with the same name (but ``.ipynb`` extension)
97 will be imported into a notebook with the same name (but ``.ipynb`` extension)
98 located in the directory where the notebook server was started. This notebook
98 located in the directory where the notebook server was started. This notebook
99 will consist of a single cell with all the code in the file, which you can
99 will consist of a single cell with all the code in the file, which you can
100 later manually partition into individual cells for gradual execution, add text
100 later manually partition into individual cells for gradual execution, add text
101 and graphics, etc.
101 and graphics, etc.
102
102
103
103
104 Workflow and limitations
104 Workflow and limitations
105 ------------------------
105 ------------------------
106
106
107 The normal workflow in a notebook is quite similar to a normal IPython session,
107 The normal workflow in a notebook is quite similar to a normal IPython session,
108 with the difference that you can edit a cell in-place multiple times until you
108 with the difference that you can edit a cell in-place multiple times until you
109 obtain the desired results rather than having to rerun separate scripts with
109 obtain the desired results rather than having to rerun separate scripts with
110 the ``%run`` magic (though magics also work in the notebook). Typically
110 the ``%run`` magic (though magics also work in the notebook). Typically
111 you'll work on a problem in pieces, organizing related pieces into cells and
111 you'll work on a problem in pieces, organizing related pieces into cells and
112 moving forward as previous parts work correctly. This is much more convenient
112 moving forward as previous parts work correctly. This is much more convenient
113 for interactive exploration than breaking up a computation into scripts that
113 for interactive exploration than breaking up a computation into scripts that
114 must be executed together, especially if parts of them take a long time to run
114 must be executed together, especially if parts of them take a long time to run
115 (In the traditional terminal-based IPython, you can use tricks with namespaces
115 (In the traditional terminal-based IPython, you can use tricks with namespaces
116 and ``%run -i`` to achieve this capability, but we think the notebook is a more
116 and ``%run -i`` to achieve this capability, but we think the notebook is a more
117 natural solution for that kind of problem).
117 natural solution for that kind of problem).
118
118
119 The only significant limitation the notebook currently has, compared to the qt
119 The only significant limitation the notebook currently has, compared to the qt
120 console, is that it can not run any code that expects input from the kernel
120 console, is that it can not run any code that expects input from the kernel
121 (such as scripts that call :func:`raw_input`). Very importantly, this means
121 (such as scripts that call :func:`raw_input`). Very importantly, this means
122 that the ``%debug`` magic does *not* work in the notebook! We intend to
122 that the ``%debug`` magic does *not* work in the notebook! We intend to
123 correct this limitation, but in the meantime, there is a way to debug problems
123 correct this limitation, but in the meantime, there is a way to debug problems
124 in the notebook: you can attach a Qt console to your existing notebook kernel,
124 in the notebook: you can attach a Qt console to your existing notebook kernel,
125 and run ``%debug`` from the Qt console. If your notebook is running on a local
125 and run ``%debug`` from the Qt console. If your notebook is running on a local
126 computer (i.e. if you are accessing it via your localhost address at
126 computer (i.e. if you are accessing it via your localhost address at
127 127.0.0.1), you can just type ``%qtconsole`` in the notebook and a Qt console
127 127.0.0.1), you can just type ``%qtconsole`` in the notebook and a Qt console
128 will open up connected to that same kernel.
128 will open up connected to that same kernel.
129
129
130 In general, the notebook server prints the full details of how to connect to
130 In general, the notebook server prints the full details of how to connect to
131 each kernel at the terminal, with lines like::
131 each kernel at the terminal, with lines like::
132
132
133 [IPKernelApp] To connect another client to this kernel, use:
133 [IPKernelApp] To connect another client to this kernel, use:
134 [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
134 [IPKernelApp] --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
135
135
136 This is the name of a JSON file that contains all the port and validation
136 This is the name of a JSON file that contains all the port and validation
137 information necessary to connect to the kernel. You can manually start a
137 information necessary to connect to the kernel. You can manually start a
138 qt console with::
138 qt console with::
139
139
140 ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
140 ipython qtconsole --existing kernel-3bb93edd-6b5a-455c-99c8-3b658f45dde5.json
141
141
142 and if you only have a single kernel running, simply typing::
142 and if you only have a single kernel running, simply typing::
143
143
144 ipython qtconsole --existing
144 ipython qtconsole --existing
145
145
146 will automatically find it (it will always find the most recently started
146 will automatically find it (it will always find the most recently started
147 kernel if there is more than one). You can also request this connection data
147 kernel if there is more than one). You can also request this connection data
148 by typing ``%connect_info``; this will print the same file information as well
148 by typing ``%connect_info``; this will print the same file information as well
149 as the content of the JSON data structure it contains.
149 as the content of the JSON data structure it contains.
150
150
151
151
152 Text input
152 Text input
153 ----------
153 ----------
154
154
155 In addition to code cells and the output they produce (such as figures), you
155 In addition to code cells and the output they produce (such as figures), you
156 can also type text not meant for execution. To type text, change the type of a
156 can also type text not meant for execution. To type text, change the type of a
157 cell from ``Code`` to ``Markdown`` by using the button or the :kbd:`Ctrl-m m`
157 cell from ``Code`` to ``Markdown`` by using the button or the :kbd:`Ctrl-m m`
158 keybinding (see below). You can then type any text in Markdown_ syntax, as
158 keybinding (see below). You can then type any text in Markdown_ syntax, as
159 well as mathematical expressions if you use ``$...$`` for inline math or
159 well as mathematical expressions if you use ``$...$`` for inline math or
160 ``$$...$$`` for displayed math.
160 ``$$...$$`` for displayed math.
161
161
162
162
163 Exporting a notebook and importing existing scripts
163 Exporting a notebook and importing existing scripts
164 ---------------------------------------------------
164 ---------------------------------------------------
165
165
166 If you want to provide others with a static HTML or PDF view of your notebook,
166 If you want to provide others with a static HTML or PDF view of your notebook,
167 use the ``Print`` button. This opens a static view of the document, which you
167 use the ``Print`` button. This opens a static view of the document, which you
168 can print to PDF using your operating system's facilities, or save to a file
168 can print to PDF using your operating system's facilities, or save to a file
169 with your web browser's 'Save' option (note that typically, this will create
169 with your web browser's 'Save' option (note that typically, this will create
170 both an html file *and* a directory called `notebook_name_files` next to it
170 both an html file *and* a directory called `notebook_name_files` next to it
171 that contains all the necessary style information, so if you intend to share
171 that contains all the necessary style information, so if you intend to share
172 this, you must send the directory along with the main html file).
172 this, you must send the directory along with the main html file).
173
173
174 The `Download` button lets you save a notebook file to the Download area
174 The `Download` button lets you save a notebook file to the Download area
175 configured by your web browser (particularly useful if you are running the
175 configured by your web browser (particularly useful if you are running the
176 notebook server on a remote host and need a file locally). The notebook is
176 notebook server on a remote host and need a file locally). The notebook is
177 saved by default with the ``.ipynb`` extension and the files contain JSON data
177 saved by default with the ``.ipynb`` extension and the files contain JSON data
178 that is not meant for human editing or consumption. But you can always export
178 that is not meant for human editing or consumption. But you can always export
179 the input part of a notebook to a plain python script by choosing Python format
179 the input part of a notebook to a plain python script by choosing Python format
180 in the `Download` drop list. This removes all output and saves the text cells
180 in the `Download` drop list. This removes all output and saves the text cells
181 in comment areas. See ref:`below <notebook_format>` for more details on the
181 in comment areas. See ref:`below <notebook_format>` for more details on the
182 notebook format.
182 notebook format.
183
183
184 The notebook can also *import* ``.py`` files as notebooks, by dragging and
184 The notebook can also *import* ``.py`` files as notebooks, by dragging and
185 dropping the file into the notebook dashboard file list area. By default, the
185 dropping the file into the notebook dashboard file list area. By default, the
186 entire contents of the file will be loaded into a single code cell. But if
186 entire contents of the file will be loaded into a single code cell. But if
187 prior to import, you manually add the ``# <nbformat>2</nbformat>`` marker at
187 prior to import, you manually add the ``# <nbformat>2</nbformat>`` marker at
188 the start and then add separators for text/code cells, you can get a cleaner
188 the start and then add separators for text/code cells, you can get a cleaner
189 import with the file broken into individual cells.
189 import with the file broken into individual cells.
190
190
191 .. warning::
191 .. warning::
192
192
193 While in simple cases you can roundtrip a notebook to Python, edit the
193 While in simple cases you can roundtrip a notebook to Python, edit the
194 python file and import it back without loss of main content, this is in
194 python file and import it back without loss of main content, this is in
195 general *not guaranteed to work at all*. First, there is extra metadata
195 general *not guaranteed to work at all*. First, there is extra metadata
196 saved in the notebook that may not be saved to the ``.py`` format. And as
196 saved in the notebook that may not be saved to the ``.py`` format. And as
197 the notebook format evolves in complexity, there will be attributes of the
197 the notebook format evolves in complexity, there will be attributes of the
198 notebook that will not survive a roundtrip through the Python form. You
198 notebook that will not survive a roundtrip through the Python form. You
199 should think of the Python format as a way to output a script version of a
199 should think of the Python format as a way to output a script version of a
200 notebook and the import capabilities as a way to load existing code to get a
200 notebook and the import capabilities as a way to load existing code to get a
201 notebook started. But the Python version is *not* an alternate notebook
201 notebook started. But the Python version is *not* an alternate notebook
202 format.
202 format.
203
203
204
204
205 Importing or executing a notebook as a normal Python file
205 Importing or executing a notebook as a normal Python file
206 ---------------------------------------------------------
206 ---------------------------------------------------------
207
207
208 The native format of the notebook, a file with a ``.ipynb`` extension, is a
208 The native format of the notebook, a file with a ``.ipynb`` extension, is a
209 JSON container of all the input and output of the notebook, and therefore not
209 JSON container of all the input and output of the notebook, and therefore not
210 valid Python by itself. This means that by default, you can not import a
210 valid Python by itself. This means that by default, you can not import a
211 notebook or execute it as a normal python script. But if you want use
211 notebook or execute it as a normal python script. But if you want use
212 notebooks as regular Python files, you can start the notebook server with::
212 notebooks as regular Python files, you can start the notebook server with::
213
213
214 ipython notebook --script
214 ipython notebook --script
215
215
216 or you can set this option permanently in your configuration file with::
216 or you can set this option permanently in your configuration file with::
217
217
218 c.NotebookManager.save_script=True
218 c.NotebookManager.save_script=True
219
219
220 This will instruct the notebook server to save the ``.py`` export of each
220 This will instruct the notebook server to save the ``.py`` export of each
221 notebook adjacent to the ``.ipynb`` at every save. These files can be
221 notebook adjacent to the ``.ipynb`` at every save. These files can be
222 ``%run``, imported from regular IPython sessions or other notebooks, or
222 ``%run``, imported from regular IPython sessions or other notebooks, or
223 executed at the command-line as normal Python files. Since we export the raw
223 executed at the command-line as normal Python files. Since we export the raw
224 code you have typed, for these files to be importable from other code you will
224 code you have typed, for these files to be importable from other code you will
225 have to avoid using syntax such as ``%magics`` and other IPython-specific
225 have to avoid using syntax such as ``%magics`` and other IPython-specific
226 extensions to the language.
226 extensions to the language.
227
227
228 In regular practice, the standard way to differentiate importable code from the
228 In regular practice, the standard way to differentiate importable code from the
229 'executable' part of a script is to put at the bottom::
229 'executable' part of a script is to put at the bottom::
230
230
231 if __name__ == '__main__':
231 if __name__ == '__main__':
232 # rest of the code...
232 # rest of the code...
233
233
234 Since all cells in the notebook are run as top-level code, you'll need to
234 Since all cells in the notebook are run as top-level code, you'll need to
235 similarly protect *all* cells that you do not want executed when other scripts
235 similarly protect *all* cells that you do not want executed when other scripts
236 try to import your notebook. A convenient shortand for this is to define early
236 try to import your notebook. A convenient shortand for this is to define early
237 on::
237 on::
238
238
239 script = __name__ == '__main__':
239 script = __name__ == '__main__':
240
240
241 and then on any cell that you need to protect, use::
241 and then on any cell that you need to protect, use::
242
242
243 if script:
243 if script:
244 # rest of the cell...
244 # rest of the cell...
245
245
246
246
247 Keyboard use
247 Keyboard use
248 ------------
248 ------------
249
249
250 All actions in the notebook can be achieved with the mouse, but we have also
250 All actions in the notebook can be achieved with the mouse, but we have also
251 added keyboard shortcuts for the most common ones, so that productive use of
251 added keyboard shortcuts for the most common ones, so that productive use of
252 the notebook can be achieved with minimal mouse intervention. The main
252 the notebook can be achieved with minimal mouse intervention. The main
253 key bindings you need to remember are:
253 key bindings you need to remember are:
254
254
255 * :kbd:`Shift-Enter`: execute the current cell (similar to the Qt console),
255 * :kbd:`Shift-Enter`: execute the current cell (similar to the Qt console),
256 show output (if any) and create a new cell below. Note that in the notebook,
256 show output (if any) and create a new cell below. Note that in the notebook,
257 simply using :kbd:`Enter` *never* forces execution, it simply inserts a new
257 simply using :kbd:`Enter` *never* forces execution, it simply inserts a new
258 line in the current cell. Therefore, in the notebook you must always use
258 line in the current cell. Therefore, in the notebook you must always use
259 :kbd:`Shift-Enter` to get execution (or use the mouse and click on the ``Run
259 :kbd:`Shift-Enter` to get execution (or use the mouse and click on the ``Run
260 Selected`` button).
260 Selected`` button).
261
261
262 * :kbd:`Ctrl-Enter`: execute the current cell in "terminal mode", where any
262 * :kbd:`Ctrl-Enter`: execute the current cell in "terminal mode", where any
263 output is shown but the cursor stays in the current cell, whose input
263 output is shown but the cursor stays in the current cell, whose input
264 area is flushed empty. This is convenient to do quick in-place experiments
264 area is flushed empty. This is convenient to do quick in-place experiments
265 or query things like filesystem content without creating additional cells you
265 or query things like filesystem content without creating additional cells you
266 may not want saved in your notebook.
266 may not want saved in your notebook.
267
267
268 * :kbd:`Ctrl-m`: this is the prefix for all other keybindings, which consist
268 * :kbd:`Ctrl-m`: this is the prefix for all other keybindings, which consist
269 of an additional single letter. Type :kbd:`Ctrl-m h` (that is, the sole
269 of an additional single letter. Type :kbd:`Ctrl-m h` (that is, the sole
270 letter :kbd:`h` after :kbd:`Ctrl-m`) and IPython will show you the remaining
270 letter :kbd:`h` after :kbd:`Ctrl-m`) and IPython will show you the remaining
271 available keybindings.
271 available keybindings.
272
272
273
273
274 .. _notebook_security:
274 .. _notebook_security:
275
275
276 Security
276 Security
277 ========
277 ========
278
278
279 You can protect your notebook server with a simple single-password by
279 You can protect your notebook server with a simple single-password by
280 setting the :attr:`NotebookApp.password` configurable. You can prepare a
280 setting the :attr:`NotebookApp.password` configurable. You can prepare a
281 hashed password using the function :func:`IPython.lib.security.passwd`:
281 hashed password using the function :func:`IPython.lib.security.passwd`:
282
282
283 .. sourcecode:: ipython
283 .. sourcecode:: ipython
284
284
285 In [1]: from IPython.lib import passwd
285 In [1]: from IPython.lib import passwd
286 In [2]: passwd()
286 In [2]: passwd()
287 Enter password:
287 Enter password:
288 Verify password:
288 Verify password:
289 Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
289 Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
290
290
291 .. note::
291 .. note::
292
292
293 :func:`~IPython.lib.security.passwd` can also take the password as a string
293 :func:`~IPython.lib.security.passwd` can also take the password as a string
294 argument. **Do not** pass it as an argument inside an IPython session, as it
294 argument. **Do not** pass it as an argument inside an IPython session, as it
295 will be saved in your input history.
295 will be saved in your input history.
296
296
297 You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
297 You can then add this to your :file:`ipython_notebook_config.py`, e.g.::
298
298
299 # Password to use for web authentication
299 # Password to use for web authentication
300 c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
300 c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
301
301
302 When using a password, it is a good idea to also use SSL, so that your password
302 When using a password, it is a good idea to also use SSL, so that your password
303 is not sent unencrypted by your browser. You can start the notebook to
303 is not sent unencrypted by your browser. You can start the notebook to
304 communicate via a secure protocol mode using a self-signed certificate by
304 communicate via a secure protocol mode using a self-signed certificate by
305 typing::
305 typing::
306
306
307 $ ipython notebook --certfile=mycert.pem
307 $ ipython notebook --certfile=mycert.pem
308
308
309 .. note::
309 .. note::
310
310
311 A self-signed certificate can be generated with openssl. For example, the
311 A self-signed certificate can be generated with openssl. For example, the
312 following command will create a certificate valid for 365 days with both
312 following command will create a certificate valid for 365 days with both
313 the key and certificate data written to the same file::
313 the key and certificate data written to the same file::
314
314
315 $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
315 $ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem
316
316
317 Your browser will warn you of a dangerous certificate because it is
317 Your browser will warn you of a dangerous certificate because it is
318 self-signed. If you want to have a fully compliant certificate that will not
318 self-signed. If you want to have a fully compliant certificate that will not
319 raise warnings, it is possible (but rather involved) to obtain one for free,
319 raise warnings, it is possible (but rather involved) to obtain one for free,
320 `as explained in detailed in this tutorial`__.
320 `as explained in detailed in this tutorial`__.
321
321
322 .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars
322 .. __: http://arstechnica.com/security/news/2009/12/how-to-get-set-with-a-secure-sertificate-for-free.ars
323
323
324 Keep in mind that when you enable SSL support, you'll need to access the
324 Keep in mind that when you enable SSL support, you'll need to access the
325 notebook server over ``https://``, not over plain ``http://``. The startup
325 notebook server over ``https://``, not over plain ``http://``. The startup
326 message from the server prints this, but it's easy to overlook and think the
326 message from the server prints this, but it's easy to overlook and think the
327 server is for some reason non-responsive.
327 server is for some reason non-responsive.
328
328
329
329
330 Quick Howto: running a public notebook server
330 Quick Howto: running a public notebook server
331 =============================================
331 =============================================
332
332
333 If you want to access your notebook server remotely with just a web browser,
333 If you want to access your notebook server remotely with just a web browser,
334 here is a quick set of instructions. Start by creating a certificate file and
334 here is a quick set of instructions. Start by creating a certificate file and
335 a hashed password as explained above. Then, create a custom profile for the
335 a hashed password as explained above. Then, create a custom profile for the
336 notebook. At the command line, type::
336 notebook. At the command line, type::
337
337
338 ipython profile create nbserver
338 ipython profile create nbserver
339
339
340 In the profile directory, edit the file ``ipython_notebook_config.py``. By
340 In the profile directory, edit the file ``ipython_notebook_config.py``. By
341 default the file has all fields commented, the minimum set you need to
341 default the file has all fields commented, the minimum set you need to
342 uncomment and edit is here::
342 uncomment and edit is here::
343
343
344 c = get_config()
344 c = get_config()
345
345
346 # Kernel config
346 # Kernel config
347 c.IPKernelApp.pylab = 'inline' # if you want plotting support always
347 c.IPKernelApp.pylab = 'inline' # if you want plotting support always
348
348
349 # Notebook config
349 # Notebook config
350 c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
350 c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
351 c.NotebookApp.ip = '*'
351 c.NotebookApp.ip = '*'
352 c.NotebookApp.open_browser = False
352 c.NotebookApp.open_browser = False
353 c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
353 c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
354 # It's a good idea to put it on a known, fixed port
354 # It's a good idea to put it on a known, fixed port
355 c.NotebookApp.port = 9999
355 c.NotebookApp.port = 9999
356
356
357 You can then start the notebook and access it later by pointing your browser to
357 You can then start the notebook and access it later by pointing your browser to
358 ``https://your.host.com:9999``.
358 ``https://your.host.com:9999`` with ``ipython notebook --profile=nbserver``.
359
360 Running with a different URL prefix
361 ===================================
362
363 The notebook dashboard (i.e. the default landing page with an overview
364 of all your notebooks) typically lives at a URL path of
365 "http://localhost:8888/". If you want to have it, and the rest of the
366 notebook, live under a sub-directory,
367 e.g. "http://localhost:8888/ipython/", you can do so with command-line
368 options like these:
369
370 $ ipython notebook --NotebookApp.webapp_settings="\
371 {'base_project_url':'/ipython/', \
372 'base_kernel_url':'/ipython/', \
373 'static_url_prefix':'/ipython/static/'}"
359
374
360 .. _notebook_format:
375 .. _notebook_format:
361
376
362 The notebook format
377 The notebook format
363 ===================
378 ===================
364
379
365 The notebooks themselves are JSON files with an ``ipynb`` extension, formatted
380 The notebooks themselves are JSON files with an ``ipynb`` extension, formatted
366 as legibly as possible with minimal extra indentation and cell content broken
381 as legibly as possible with minimal extra indentation and cell content broken
367 across lines to make them reasonably friendly to use in version-control
382 across lines to make them reasonably friendly to use in version-control
368 workflows. You should be very careful if you ever edit manually this JSON
383 workflows. You should be very careful if you ever edit manually this JSON
369 data, as it is extremely easy to corrupt its internal structure and make the
384 data, as it is extremely easy to corrupt its internal structure and make the
370 file impossible to load. In general, you should consider the notebook as a
385 file impossible to load. In general, you should consider the notebook as a
371 file meant only to be edited by IPython itself, not for hand-editing.
386 file meant only to be edited by IPython itself, not for hand-editing.
372
387
373 .. note::
388 .. note::
374
389
375 Binary data such as figures are directly saved in the JSON file. This
390 Binary data such as figures are directly saved in the JSON file. This
376 provides convenient single-file portability but means the files can be
391 provides convenient single-file portability but means the files can be
377 large and diffs of binary data aren't very meaningful. Since the binary
392 large and diffs of binary data aren't very meaningful. Since the binary
378 blobs are encoded in a single line they only affect one line of the diff
393 blobs are encoded in a single line they only affect one line of the diff
379 output, but they are typically very long lines. You can use the
394 output, but they are typically very long lines. You can use the
380 'ClearAll' button to remove all output from a notebook prior to
395 'ClearAll' button to remove all output from a notebook prior to
381 committing it to version control, if this is a concern.
396 committing it to version control, if this is a concern.
382
397
383 The notebook server can also generate a pure-python version of your notebook,
398 The notebook server can also generate a pure-python version of your notebook,
384 by clicking on the 'Download' button and selecting ``py`` as the format. This
399 by clicking on the 'Download' button and selecting ``py`` as the format. This
385 file will contain all the code cells from your notebook verbatim, and all text
400 file will contain all the code cells from your notebook verbatim, and all text
386 cells prepended with a comment marker. The separation between code and text
401 cells prepended with a comment marker. The separation between code and text
387 cells is indicated with special comments and there is a header indicating the
402 cells is indicated with special comments and there is a header indicating the
388 format version. All output is stripped out when exporting to python.
403 format version. All output is stripped out when exporting to python.
389
404
390 Here is an example of a simple notebook with one text cell and one code input
405 Here is an example of a simple notebook with one text cell and one code input
391 cell, when exported to python format::
406 cell, when exported to python format::
392
407
393 # <nbformat>2</nbformat>
408 # <nbformat>2</nbformat>
394
409
395 # <markdowncell>
410 # <markdowncell>
396
411
397 # A text cell
412 # A text cell
398
413
399 # <codecell>
414 # <codecell>
400
415
401 print "hello IPython"
416 print "hello IPython"
402
417
403
418
404 Known Issues
419 Known Issues
405 ============
420 ============
406
421
407 When behind a proxy, especially if your system or browser is set to autodetect
422 When behind a proxy, especially if your system or browser is set to autodetect
408 the proxy, the html notebook might fail to connect to the server's websockets,
423 the proxy, the html notebook might fail to connect to the server's websockets,
409 and present you with a warning at startup. In this case, you need to configure
424 and present you with a warning at startup. In this case, you need to configure
410 your system not to use the proxy for the server's address.
425 your system not to use the proxy for the server's address.
411
426
412 In Firefox, for example, go to the Preferences panel, Advanced section,
427 In Firefox, for example, go to the Preferences panel, Advanced section,
413 Network tab, click 'Settings...', and add the address of the notebook server
428 Network tab, click 'Settings...', and add the address of the notebook server
414 to the 'No proxy for' field.
429 to the 'No proxy for' field.
415
430
416
431
417 .. _Markdown: http://daringfireball.net/projects/markdown/basics
432 .. _Markdown: http://daringfireball.net/projects/markdown/basics
General Comments 0
You need to be logged in to leave comments. Login now