##// END OF EJS Templates
Fixing HTML cell syntax highlighting.
Fixing HTML cell syntax highlighting.

File last commit:

r4496:7640e547
r4505:3896ff19
Show More
handlers.py
158 lines | 5.2 KiB | text/x-python | PythonLexer
Brian E. Granger
Work to adapt routers to new Session message protocol.
r4346 """Tornado handlers for the notebook."""
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Brian Granger
Work on the server side of the html notebook.
r4297 import json
import logging
Brian Granger
Server side of file based notebook store implemented.
r4301 import urllib
Brian Granger
Work on the server side of the html notebook.
r4297
from tornado import web
from tornado import websocket
Brian E. Granger
Massive work on the notebook document format....
r4484
Brian E. Granger
Work to adapt routers to new Session message protocol.
r4346 #-----------------------------------------------------------------------------
Brian E. Granger
Adding kernel/notebook associations.
r4494 # Top-level handlers
Brian E. Granger
Work to adapt routers to new Session message protocol.
r4346 #-----------------------------------------------------------------------------
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian Granger
Work on the server side of the html notebook.
r4297
Brian E. Granger
Implemented basic notebook browser and fixed numerous bugs.
r4488 class NBBrowserHandler(web.RequestHandler):
def get(self):
nbm = self.application.notebook_manager
project = nbm.notebook_dir
self.render('nbbrowser.html', project=project)
class NewHandler(web.RequestHandler):
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 def get(self):
Brian E. Granger
Massive work on the notebook document format....
r4484 notebook_id = self.application.notebook_manager.new_notebook()
self.render('notebook.html', notebook_id=notebook_id)
class NamedNotebookHandler(web.RequestHandler):
def get(self, notebook_id):
nbm = self.application.notebook_manager
if not nbm.notebook_exists(notebook_id):
raise web.HTTPError(404)
self.render('notebook.html', notebook_id=notebook_id)
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian E. Granger
Adding kernel/notebook associations.
r4494 #-----------------------------------------------------------------------------
# Kernel handlers
#-----------------------------------------------------------------------------
class MainKernelHandler(web.RequestHandler):
Brian Granger
Work on the server side of the html notebook.
r4297
def get(self):
Brian E. Granger
Adding kernel/notebook associations.
r4494 rkm = self.application.routing_kernel_manager
self.finish(json.dumps(rkm.kernel_ids))
Brian Granger
Basic server for htmlnotebook working.
r4298
Brian Granger
Different clients now share a single zmq session....
r4306 def post(self):
Brian E. Granger
Adding kernel/notebook associations.
r4494 rkm = self.application.routing_kernel_manager
notebook_id = self.get_argument('notebook', default=None)
kernel_id = rkm.start_kernel(notebook_id)
Brian E. Granger
Massive work on the notebook document format....
r4484 self.set_header('Location', '/'+kernel_id)
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 self.finish(json.dumps(kernel_id))
Brian Granger
Work on the server side of the html notebook.
r4297
Brian E. Granger
Adding kernel/notebook associations.
r4494 class KernelHandler(web.RequestHandler):
SUPPORTED_METHODS = ('DELETE')
def delete(self, kernel_id):
rkm = self.application.routing_kernel_manager
Brian E. Granger
Using beforeunload to save at exit and kill the kernel.
r4496 rkm.kill_kernel(kernel_id)
Brian E. Granger
Adding kernel/notebook associations.
r4494 self.set_status(204)
self.finish()
Brian Granger
Interrupt and restart work for kernels.
r4308 class KernelActionHandler(web.RequestHandler):
Brian Granger
Cleaned up kernel action interface....
r4309 def post(self, kernel_id, action):
Brian E. Granger
Adding kernel/notebook associations.
r4494 rkm = self.application.routing_kernel_manager
Brian Granger
Cleaned up kernel action interface....
r4309 if action == 'interrupt':
Brian E. Granger
Adding kernel/notebook associations.
r4494 rkm.interrupt_kernel(kernel_id)
self.set_status(204)
Brian Granger
Cleaned up kernel action interface....
r4309 if action == 'restart':
Brian E. Granger
Adding kernel/notebook associations.
r4494 new_kernel_id = rkm.restart_kernel(kernel_id)
Brian Granger
Interrupt and restart work for kernels.
r4308 self.write(json.dumps(new_kernel_id))
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 self.finish()
Brian Granger
Interrupt and restart work for kernels.
r4308
Brian Granger
Different clients now share a single zmq session....
r4306 class ZMQStreamHandler(websocket.WebSocketHandler):
Brian Granger
Work on the server side of the html notebook.
r4297
Brian Granger
Different clients now share a single zmq session....
r4306 def initialize(self, stream_name):
self.stream_name = stream_name
Brian Granger
Work on the server side of the html notebook.
r4297
Brian Granger
Different clients now share a single zmq session....
r4306 def open(self, kernel_id):
Brian E. Granger
Adding kernel/notebook associations.
r4494 rkm = self.application.routing_kernel_manager
self.router = rkm.get_router(kernel_id, self.stream_name)
Brian Granger
Different clients now share a single zmq session....
r4306 self.client_id = self.router.register_client(self)
Brian Granger
Work on the server side of the html notebook.
r4297
Brian Granger
Different clients now share a single zmq session....
r4306 def on_message(self, msg):
Brian E. Granger
More work on updating the notebook zmq forwarding.
r4347 self.router.forward_msg(self.client_id, msg)
Brian Granger
Work on the server side of the html notebook.
r4297
Brian Granger
Different clients now share a single zmq session....
r4306 def on_close(self):
self.router.unregister_client(self.client_id)
Brian Granger
Work on the server side of the html notebook.
r4297
Brian E. Granger
Adding kernel/notebook associations.
r4494 #-----------------------------------------------------------------------------
# Notebook web service handlers
#-----------------------------------------------------------------------------
Brian Granger
Server side of file based notebook store implemented.
r4301 class NotebookRootHandler(web.RequestHandler):
def get(self):
Brian E. Granger
Massive work on the notebook document format....
r4484 nbm = self.application.notebook_manager
files = nbm.list_notebooks()
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 self.finish(json.dumps(files))
Brian Granger
Server side of file based notebook store implemented.
r4301
Brian E. Granger
Massive work on the notebook document format....
r4484 def post(self):
nbm = self.application.notebook_manager
body = self.request.body.strip()
format = self.get_argument('format', default='json')
Brian E. Granger
File upload/import working from notebook browser.
r4491 name = self.get_argument('name', default=None)
Brian E. Granger
Massive work on the notebook document format....
r4484 if body:
Brian E. Granger
File upload/import working from notebook browser.
r4491 notebook_id = nbm.save_new_notebook(body, name=name, format=format)
Brian E. Granger
Massive work on the notebook document format....
r4484 else:
notebook_id = nbm.new_notebook()
self.set_header('Location', '/'+notebook_id)
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 self.finish(json.dumps(notebook_id))
Brian Granger
Server side of file based notebook store implemented.
r4301
Brian E. Granger
Massive work on the notebook document format....
r4484 class NotebookHandler(web.RequestHandler):
Brian Granger
Server side of file based notebook store implemented.
r4301
Brian E. Granger
Massive work on the notebook document format....
r4484 SUPPORTED_METHODS = ('GET', 'PUT', 'DELETE')
def get(self, notebook_id):
nbm = self.application.notebook_manager
format = self.get_argument('format', default='json')
last_mod, name, data = nbm.get_notebook(notebook_id, format)
if format == u'json':
self.set_header('Content-Type', 'application/json')
self.set_header('Content-Disposition','attachment; filename=%s.json' % name)
elif format == u'xml':
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 self.set_header('Content-Type', 'application/xml')
Brian E. Granger
Massive work on the notebook document format....
r4484 self.set_header('Content-Disposition','attachment; filename=%s.ipynb' % name)
elif format == u'py':
Brian E. Granger
Improvements to file uploaded, mime types and .py reader....
r4493 self.set_header('Content-Type', 'application/x-python')
Brian E. Granger
Massive work on the notebook document format....
r4484 self.set_header('Content-Disposition','attachment; filename=%s.py' % name)
self.set_header('Last-Modified', last_mod)
self.finish(data)
def put(self, notebook_id):
nbm = self.application.notebook_manager
format = self.get_argument('format', default='json')
Brian E. Granger
File upload/import working from notebook browser.
r4491 name = self.get_argument('name', default=None)
nbm.save_notebook(notebook_id, self.request.body, name=name, format=format)
Brian E. Granger
Massive work on the notebook document format....
r4484 self.set_status(204)
Brian Granger
Server side of file based notebook store implemented.
r4301 self.finish()
Brian E. Granger
Massive work on the notebook document format....
r4484 def delete(self, notebook_id):
nbm = self.application.notebook_manager
nbm.delete_notebook(notebook_id)
Brian Granger
Server side of file based notebook store implemented.
r4301 self.set_status(204)
self.finish()