Allow more contents manager functions to return futures

This allows slower contents managers to not block the event loop by allowing
more of their API to return futures.

Other usages of contents manager functions are already wrapped in maybe_future,
including a use of `file_exists` in contents/handlers.py
Michal Charemza 7 years ago
parent b663bf1b14
commit 815ed3ce56
No known key found for this signature in database
GPG Key ID: 4BBAF0F6B73C4363

@ -12,7 +12,7 @@ except ImportError: #PY2
from base64 import decodestring as decodebytes
from tornado import web
from tornado import gen, web
from notebook.base.handlers import IPythonHandler
@ -51,7 +51,7 @@ class FilesHandler(IPythonHandler):
else:
name = path
model = cm.get(path, type='file', content=include_body)
model = yield gen.maybe_future(cm.get(path, type='file', content=include_body))
if self.get_argument("download", False):
self.set_attachment_header(name)

@ -182,10 +182,12 @@ class ContentsHandler(APIHandler):
cm = self.contents_manager
if cm.file_exists(path):
file_exists = yield gen.maybe_future(cm.file_exists(path))
if file_exists:
raise web.HTTPError(400, "Cannot POST to files, use PUT instead.")
if not cm.dir_exists(path):
dir_exists = yield gen.maybe_future(cm.dir_exists(path))
if not dir_exists:
raise web.HTTPError(404, "No such directory: %s" % path)
model = self.get_json_body()

Loading…
Cancel
Save