handlers.py
85 lines
| 2.3 KiB
| text/x-python
|
PythonLexer
Zachary Sailer
|
r13006 | """Tornado handlers for the contents web service. | ||
Authors: | ||||
* Zach Sailer | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
Zachary Sailer
|
r13011 | # Copyright (C) 2013 The IPython Development Team | ||
Zachary Sailer
|
r13006 | # | ||
# Distributed under the terms of the BSD License. The full license is in | ||||
# the file COPYING, distributed as part of this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
from tornado import web | ||||
from zmq.utils import jsonapi | ||||
from IPython.utils.jsonutil import date_default | ||||
Zachary Sailer
|
r13014 | from ...base.handlers import IPythonHandler | ||
Zachary Sailer
|
r13006 | |||
#----------------------------------------------------------------------------- | ||||
# Contents web service handlers | ||||
#----------------------------------------------------------------------------- | ||||
class ContentRootHandler(IPythonHandler): | ||||
Zachary Sailer
|
r13014 | @web.authenticated | ||
Zachary Sailer
|
r13006 | def get(self): | ||
cm = self.content_manager | ||||
contents = cm.list_contents("") | ||||
self.finish(jsonapi.dumps(contents)) | ||||
class ContentHandler(IPythonHandler): | ||||
@web.authenticated | ||||
def get(self, content_path): | ||||
cm = self.content_manager | ||||
contents = cm.list_contents(content_path) | ||||
self.finish(jsonapi.dumps(contents)) | ||||
@web.authenticated | ||||
def delete(self, content_path): | ||||
Zachary Sailer
|
r13007 | cm = self.content_manager | ||
cm.delete_content(content_path) | ||||
Zachary Sailer
|
r13006 | self.set_status(204) | ||
self.finish() | ||||
Zachary Sailer
|
r13015 | class ServicesRedirectHandler(IPythonHandler): | ||
@web.authenticated | ||||
def get(self): | ||||
url = self.base_project_url + 'api' | ||||
self.redirect(url) | ||||
class ServicesHandler(IPythonHandler): | ||||
@web.authenticated | ||||
def get(self): | ||||
services = ['contents', 'notebooks', 'sessions', 'kernels', 'clusters'] | ||||
self.finish(jsonapi.dumps(services)) | ||||
Zachary Sailer
|
r13006 | |||
#----------------------------------------------------------------------------- | ||||
# URL to handler mappings | ||||
#----------------------------------------------------------------------------- | ||||
_content_path_regex = r"(?P<content_path>.+)" | ||||
default_handlers = [ | ||||
(r"api/contents/%s" % _content_path_regex, ContentHandler), | ||||
Zachary Sailer
|
r13015 | (r"api/contents", ContentRootHandler), | ||
(r"api/", ServicesRedirectHandler), | ||||
(r"api", ServicesHandler) | ||||
Zachary Sailer
|
r13006 | ] | ||