Skip to content

Allow contents manager get to return future #5077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions notebook/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
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
Expand Down Expand Up @@ -86,6 +87,7 @@ def content_security_policy(self):
"; sandbox allow-scripts"

@web.authenticated
@gen.coroutine
def get(self, format, path):

exporter = get_exporter(format, config=self.config, log=self.log)
Expand All @@ -99,7 +101,7 @@ def get(self, format, path):
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
Expand Down
11 changes: 8 additions & 3 deletions notebook/notebook/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _


Expand Down Expand Up @@ -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."""
Expand All @@ -76,7 +81,7 @@ def get(self, path):

# 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
Expand Down