Merge pull request #1904 from minrk/json_errors_first

json_errors should be outermost decorator on API handlers
Thomas Kluyver 10 years ago committed by GitHub
commit 6f32903e16

@ -13,21 +13,21 @@ from ...base.handlers import APIHandler, json_errors
class ConfigHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
def get(self, section_name):
self.set_header("Content-Type", 'application/json')
self.finish(json.dumps(self.config_manager.get(section_name)))
@web.authenticated
@json_errors
@web.authenticated
def put(self, section_name):
data = self.get_json_body() # Will raise 400 if content is not valid JSON
self.config_manager.set(section_name, data)
self.set_status(204)
@web.authenticated
@json_errors
@web.authenticated
def patch(self, section_name):
new_data = self.get_json_body()
section = self.config_manager.update(section_name, new_data)

@ -98,8 +98,8 @@ class ContentsHandler(APIHandler):
self.set_header('Content-Type', 'application/json')
self.finish(json.dumps(model, default=date_default))
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def get(self, path=''):
"""Return a model for a file or directory.
@ -130,8 +130,8 @@ class ContentsHandler(APIHandler):
validate_model(model, expect_content=content)
self._finish_model(model, location=False)
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def patch(self, path=''):
"""PATCH renames a file or directory without re-uploading content."""
@ -181,8 +181,8 @@ class ContentsHandler(APIHandler):
validate_model(model, expect_content=False)
self._finish_model(model)
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def post(self, path=''):
"""Create a new file in the specified path.
@ -217,8 +217,8 @@ class ContentsHandler(APIHandler):
else:
yield self._new_untitled(path)
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def put(self, path=''):
"""Saves the file in the location specified by name and path.
@ -243,8 +243,8 @@ class ContentsHandler(APIHandler):
else:
yield gen.maybe_future(self._new_untitled(path))
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def delete(self, path=''):
"""delete a file in the given path"""
@ -257,8 +257,8 @@ class ContentsHandler(APIHandler):
class CheckpointsHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def get(self, path=''):
"""get lists checkpoints for a file"""
@ -267,8 +267,8 @@ class CheckpointsHandler(APIHandler):
data = json.dumps(checkpoints, default=date_default)
self.finish(data)
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def post(self, path=''):
"""post creates a new checkpoint"""
@ -284,8 +284,8 @@ class CheckpointsHandler(APIHandler):
class ModifyCheckpointsHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def post(self, path, checkpoint_id):
"""post restores a file from a checkpoint"""
@ -294,8 +294,8 @@ class ModifyCheckpointsHandler(APIHandler):
self.set_status(204)
self.finish()
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def delete(self, path, checkpoint_id):
"""delete clears a checkpoint for a given file"""

@ -25,16 +25,16 @@ from jupyter_client import protocol_version as client_protocol_version
class MainKernelHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def get(self):
km = self.kernel_manager
kernels = yield gen.maybe_future(km.list_kernels())
self.finish(json.dumps(kernels))
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def post(self):
km = self.kernel_manager
@ -56,16 +56,16 @@ class MainKernelHandler(APIHandler):
class KernelHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
def get(self, kernel_id):
km = self.kernel_manager
km._check_kernel_id(kernel_id)
model = km.kernel_model(kernel_id)
self.finish(json.dumps(model))
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def delete(self, kernel_id):
km = self.kernel_manager
@ -76,8 +76,8 @@ class KernelHandler(APIHandler):
class KernelActionHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def post(self, kernel_id, action):
km = self.kernel_manager

@ -45,8 +45,8 @@ def kernelspec_model(handler, name):
class MainKernelSpecHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
def get(self):
ksm = self.kernel_spec_manager
km = self.kernel_manager
@ -66,8 +66,8 @@ class MainKernelSpecHandler(APIHandler):
class KernelSpecHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
def get(self, kernel_name):
print('hello', kernel_name, url_unescape(kernel_name))
try:

@ -6,8 +6,8 @@ from ...base.handlers import APIHandler, json_errors
class NbconvertRootHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
def get(self):
try:
from nbconvert.exporters.export import exporter_map

@ -10,8 +10,8 @@ from . import csp_report_uri
class CSPReportHandler(APIHandler):
'''Accepts a content security policy violation report'''
@web.authenticated
@json_errors
@web.authenticated
def post(self):
'''Log a content security policy violation report'''
csp_report = self.get_json_body()

@ -19,8 +19,8 @@ from jupyter_client.kernelspec import NoSuchKernel
class SessionRootHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def get(self):
# Return a list of running sessions
@ -28,8 +28,8 @@ class SessionRootHandler(APIHandler):
sessions = yield gen.maybe_future(sm.list_sessions())
self.finish(json.dumps(sessions, default=date_default))
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def post(self):
# Creates a new session
@ -90,8 +90,8 @@ class SessionRootHandler(APIHandler):
class SessionHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def get(self, session_id):
# Returns the JSON model for a single session
@ -99,8 +99,8 @@ class SessionHandler(APIHandler):
model = yield gen.maybe_future(sm.get_session(session_id=session_id))
self.finish(json.dumps(model, default=date_default))
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def patch(self, session_id):
"""Patch updates sessions:
@ -153,8 +153,8 @@ class SessionHandler(APIHandler):
)
self.finish(json.dumps(model, default=date_default))
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def delete(self, session_id):
# Deletes the session with given session_id

@ -4,15 +4,15 @@ from ..base.handlers import APIHandler, json_errors
from ..utils import url_path_join
class TerminalRootHandler(APIHandler):
@web.authenticated
@json_errors
@web.authenticated
def get(self):
tm = self.terminal_manager
terms = [{'name': name} for name in tm.terminals]
self.finish(json.dumps(terms))
@web.authenticated
@json_errors
@web.authenticated
def post(self):
"""POST /terminals creates a new terminal and redirects to it"""
name, _ = self.terminal_manager.new_named_terminal()
@ -22,8 +22,8 @@ class TerminalRootHandler(APIHandler):
class TerminalHandler(APIHandler):
SUPPORTED_METHODS = ('GET', 'DELETE')
@web.authenticated
@json_errors
@web.authenticated
def get(self, name):
tm = self.terminal_manager
if name in tm.terminals:
@ -31,8 +31,8 @@ class TerminalHandler(APIHandler):
else:
raise web.HTTPError(404, "Terminal not found: %r" % name)
@web.authenticated
@json_errors
@web.authenticated
@gen.coroutine
def delete(self, name):
tm = self.terminal_manager

Loading…
Cancel
Save