Allow contents manager get to return future

This is a follow up to https://github.com/jupyter/notebook/pull/4099,
wrapping other uses of contents manager get with `maybe_future` to
allow it to yield the event loop.
This commit is contained in:
Michal Charemza 2019-11-24 14:09:06 +00:00
parent 9640e1f943
commit b7a354d8fa
No known key found for this signature in database
GPG Key ID: 4BBAF0F6B73C4363
2 changed files with 12 additions and 5 deletions

View File

@ -7,13 +7,14 @@ import io
import os
import zipfile
from tornado import web, escape
from tornado import gen, web, escape
from tornado.log import app_log
from ..base.handlers import (
IPythonHandler, FilesRedirectHandler,
path_regex,
)
from ..utils import maybe_future
from nbformat import from_dict
from ipython_genutils.py3compat import cast_bytes
@ -86,6 +87,7 @@ class NbconvertFileHandler(IPythonHandler):
"; sandbox allow-scripts"
@web.authenticated
@gen.coroutine
def get(self, format, path):
exporter = get_exporter(format, config=self.config, log=self.log)
@ -99,7 +101,7 @@ class NbconvertFileHandler(IPythonHandler):
else:
ext_resources_dir = None
model = self.contents_manager.get(path=path)
model = yield maybe_future(self.contents_manager.get(path=path))
name = model['name']
if model['type'] != 'notebook':
# not a notebook, redirect to files

View File

@ -5,13 +5,17 @@
from collections import namedtuple
import os
from tornado import web
from tornado import (
gen, web,
)
HTTPError = web.HTTPError
from ..base.handlers import (
IPythonHandler, FilesRedirectHandler, path_regex,
)
from ..utils import url_escape
from ..utils import (
maybe_future, url_escape,
)
from ..transutils import _
@ -68,6 +72,7 @@ def get_frontend_exporters():
class NotebookHandler(IPythonHandler):
@web.authenticated
@gen.coroutine
def get(self, path):
"""get renders the notebook template if a name is given, or
redirects to the '/files/' handler if the name is not given."""
@ -76,7 +81,7 @@ class NotebookHandler(IPythonHandler):
# will raise 404 on not found
try:
model = cm.get(path, content=False)
model = yield maybe_future(cm.get(path, content=False))
except web.HTTPError as e:
if e.status_code == 404 and 'files' in path.split('/'):
# 404, but '/files/' in URL, let FilesRedirect take care of it