From b32ba8caf1d32ce8fd95d9db5f0c7eefeb77b9d4 Mon Sep 17 00:00:00 2001 From: Michal Charemza Date: Sun, 24 Nov 2019 14:09:06 +0000 Subject: [PATCH] Allow contents manager get to return future This is a follow up to https://github.com/jupyter/notebook/pull/4099 --- notebook/notebook/handlers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/notebook/notebook/handlers.py b/notebook/notebook/handlers.py index 14f927bef06..638931d6be3 100644 --- a/notebook/notebook/handlers.py +++ b/notebook/notebook/handlers.py @@ -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 @@ 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