##// END OF EJS Templates
Removing default input prompt number....
Removing default input prompt number. In a notebook setting being able to delete and add cells makes it virtually impossible to correctly guess what the next input prompt number should be. We now follow the convention that our prompts look like "In [ ]:" before execution.

File last commit:

r4347:fd1d84c8
r4391:b1f1ddea
Show More
handlers.py
116 lines | 3.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
Server side of file based notebook store implemented.
r4301 import datetime
Brian Granger
Work on the server side of the html notebook.
r4297 import json
import logging
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 import os
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
Work to adapt routers to new Session message protocol.
r4346 #-----------------------------------------------------------------------------
# Handlers
#-----------------------------------------------------------------------------
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292
Brian Granger
Work on the server side of the html notebook.
r4297
class MainHandler(web.RequestHandler):
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292 def get(self):
self.render('notebook.html')
Brian Granger
Different clients now share a single zmq session....
r4306 class KernelHandler(web.RequestHandler):
Brian Granger
Work on the server side of the html notebook.
r4297
def get(self):
Brian Granger
Different clients now share a single zmq session....
r4306 self.write(json.dumps(self.application.kernel_ids))
Brian Granger
Basic server for htmlnotebook working.
r4298
Brian Granger
Different clients now share a single zmq session....
r4306 def post(self):
kernel_id = self.application.start_kernel()
Brian Granger
Basic server for htmlnotebook working.
r4298 self.write(json.dumps(kernel_id))
Brian Granger
Work on the server side of the html notebook.
r4297
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 Granger
Interrupt and restart work for kernels.
r4308 # TODO: figure out a better way of handling RPC style calls.
Brian Granger
Cleaned up kernel action interface....
r4309 if action == 'interrupt':
Brian Granger
Interrupt and restart work for kernels.
r4308 self.application.interrupt_kernel(kernel_id)
Brian Granger
Cleaned up kernel action interface....
r4309 if action == 'restart':
Brian Granger
Interrupt and restart work for kernels.
r4308 new_kernel_id = self.application.restart_kernel(kernel_id)
self.write(json.dumps(new_kernel_id))
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):
self.router = self.application.get_router(kernel_id, self.stream_name)
self.client_id = self.router.register_client(self)
logging.info("Connection open: %s, %s" % (kernel_id, self.client_id))
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)
logging.info("Connection closed: %s" % self.client_id)
Brian Granger
Work on the server side of the html notebook.
r4297
Brian Granger
Server side of file based notebook store implemented.
r4301 class NotebookRootHandler(web.RequestHandler):
def get(self):
files = os.listdir(os.getcwd())
Brian Granger
Basic notebook saving and loading....
r4315 files = [file for file in files if file.endswith(".ipynb")]
Brian Granger
Server side of file based notebook store implemented.
r4301 self.write(json.dumps(files))
class NotebookHandler(web.RequestHandler):
SUPPORTED_METHODS = ("GET", "DELETE", "PUT")
def find_path(self, filename):
Brian Granger
Basic notebook saving and loading....
r4315 filename = urllib.unquote(filename)
if not filename.endswith('.ipynb'):
raise web.HTTPError(400)
Brian Granger
Server side of file based notebook store implemented.
r4301 path = os.path.join(os.getcwd(), filename)
return path
def get(self, filename):
path = self.find_path(filename)
if not os.path.isfile(path):
raise web.HTTPError(404)
info = os.stat(path)
self.set_header("Content-Type", "application/unknown")
self.set_header("Last-Modified", datetime.datetime.utcfromtimestamp(
info.st_mtime))
f = open(path, "r")
try:
self.finish(f.read())
finally:
f.close()
def put(self, filename):
path = self.find_path(filename)
f = open(path, "w")
f.write(self.request.body)
f.close()
self.finish()
def delete(self, filename):
path = self.find_path(filename)
if not os.path.isfile(path):
raise web.HTTPError(404)
os.unlink(path)
self.set_status(204)
self.finish()
Brian E. Granger
Fixing import statments in handlers and notebookapp.
r4340
Brian Granger
Initial draft of HTML5/JS/CSS3 notebook.
r4292