##// END OF EJS Templates
DEV: Refactor checkpoint logic from FileContentsManager....
DEV: Refactor checkpoint logic from FileContentsManager. - Add a `CheckpointManager` base class and infrastructure for creating a `checkpoint_manager` instance attribute on `ContentsManager`. - Provide default implementations of `delete` and `rename` in the base `ContentsManager` class. `ContentsManager` subclasses are now required to implement `delete_file` and `rename_file`. These methods no longer need to manage checkpoints. - Move checkpoint-related functionality from `FileContentsManager` to a dedicated `FileCheckpointManager` subclass. - Move shared filesystem interaction logic into `FileManagerMixin` used by both `FileContentsManager` and `FileCheckpointManager`. - Minor tweaks to ContentsManager tests to get methods from the right object. The purpose of this change is to provide an API for users to replace just the checkpoint logic associated with a particular `ContentsManager`. In particular, this change makes it possible to easily support remote storage of checkpoints while otherwise retaining normal filesystem interactions.

File last commit:

r18616:d4e327ea
r19727:974ebd4a
Show More
api_handlers.py
43 lines | 1.3 KiB | text/x-python | PythonLexer
Thomas Kluyver
Initial REST API for terminals
r18483 import json
from tornado import web
from ..base.handlers import IPythonHandler, json_errors
Min RK
create new terminals with POST /api/terminals...
r18616 from ..utils import url_path_join
Thomas Kluyver
Initial REST API for terminals
r18483
class TerminalRootHandler(IPythonHandler):
@web.authenticated
@json_errors
def get(self):
Min RK
create new terminals with POST /api/terminals...
r18616 tm = self.terminal_manager
Thomas Kluyver
Initial REST API for terminals
r18483 terms = [{'name': name} for name in tm.terminals]
self.finish(json.dumps(terms))
Min RK
create new terminals with POST /api/terminals...
r18616 @web.authenticated
@json_errors
def post(self):
"""POST /terminals creates a new terminal and redirects to it"""
name, _ = self.terminal_manager.new_named_terminal()
self.finish(json.dumps({'name': name}))
Thomas Kluyver
Initial REST API for terminals
r18483 class TerminalHandler(IPythonHandler):
SUPPORTED_METHODS = ('GET', 'DELETE')
@web.authenticated
@json_errors
def get(self, name):
Min RK
create new terminals with POST /api/terminals...
r18616 tm = self.terminal_manager
Thomas Kluyver
Initial REST API for terminals
r18483 if name in tm.terminals:
self.finish(json.dumps({'name': name}))
else:
raise web.HTTPError(404, "Terminal not found: %r" % name)
@web.authenticated
@json_errors
def delete(self, name):
Min RK
create new terminals with POST /api/terminals...
r18616 tm = self.terminal_manager
Thomas Kluyver
Initial REST API for terminals
r18483 if name in tm.terminals:
tm.kill(name)
# XXX: Should this wait for terminal to finish before returning?
self.set_status(204)
self.finish()
else:
raise web.HTTPError(404, "Terminal not found: %r" % name)