1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
From: =?utf-8?q?Picca_Fr=C3=A9d=C3=A9ric-Emmanuel?= <picca@debian.org>
Date: Wed, 21 May 2025 10:16:13 +0200
Subject: fix handler with the 1.3.1 version
---
nbclassic/tree/handlers.py | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/nbclassic/tree/handlers.py b/nbclassic/tree/handlers.py
index 2d69d2d..08c2085 100644
--- a/nbclassic/tree/handlers.py
+++ b/nbclassic/tree/handlers.py
@@ -6,8 +6,8 @@ This is a fork from jupyter/notebook#5.7.x
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
-from tornado import web
import os
+from tornado import web, gen
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.extension.handler import (
@@ -15,7 +15,7 @@ from jupyter_server.extension.handler import (
ExtensionHandlerJinjaMixin
)
from jupyter_server.base.handlers import path_regex
-from jupyter_server.utils import url_path_join, url_escape
+from jupyter_server.utils import url_path_join, url_escape, ensure_async
class TreeHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler):
@@ -44,12 +44,18 @@ class TreeHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHand
return 'Home'
@web.authenticated
+ @gen.coroutine
def get(self, path=''):
path = path.strip('/')
cm = self.contents_manager
- if cm.dir_exists(path=path):
- if cm.is_hidden(path) and not cm.allow_hidden:
+ file_exists = False
+ dir_exists = yield ensure_async(cm.dir_exists(path=path))
+ if not dir_exists:
+ file_exists = yield ensure_async(cm.file_exists(path))
+ if dir_exists:
+ is_hidden = yield ensure_async(cm.is_hidden(path))
+ if is_hidden and not cm.allow_hidden:
self.log.info("Refusing to serve hidden directory, via 404 Error")
raise web.HTTPError(404)
breadcrumbs = self.generate_breadcrumbs(path)
@@ -58,13 +64,13 @@ class TreeHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHand
page_title=page_title,
notebook_path=path,
breadcrumbs=breadcrumbs,
- terminals_available=self.settings['terminals_available'],
+ terminals_available=self.settings.get('terminals_available', False),
server_root=self.settings['server_root_dir'],
shutdown_button=self.settings.get('shutdown_button', False)
))
- elif cm.file_exists(path):
+ elif file_exists :
# it's not a directory, we have redirecting to do
- model = cm.get(path, content=False)
+ model = yield ensure_async(cm.get(path, content=False))
# redirect to /api/notebooks if it's a notebook, otherwise /api/files
service = 'notebooks' if model['type'] == 'notebook' else 'files'
url = url_path_join(
|