From ed377cfb294a8740fa873dff11790b843aa4e46e Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Sat, 29 Oct 2022 18:35:12 -0400 Subject: [PATCH] Modernize AssetServer for new/current Jupyter Lab/Server extensions --- .../webio_jupyter_extension/serverextension.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/webio_jupyter_extension/webio_jupyter_extension/serverextension.py b/webio_jupyter_extension/webio_jupyter_extension/serverextension.py index 2e59750f..4b75a93c 100644 --- a/webio_jupyter_extension/webio_jupyter_extension/serverextension.py +++ b/webio_jupyter_extension/webio_jupyter_extension/serverextension.py @@ -1,21 +1,22 @@ -from notebook.utils import url_path_join -from notebook.base.handlers import IPythonHandler +from jupyter_server.utils import url_path_join +from jupyter_server.base.handlers import JupyterHandler from tornado.web import StaticFileHandler, HTTPError -from tornado import gen +from tornado import gen, web import os import json -class JuliaPackageAssetServer(IPythonHandler, StaticFileHandler): +class JuliaPackageAssetServer(JupyterHandler, StaticFileHandler): def initialize(self, *args): self.root = "" - IPythonHandler.initialize(self, *args) + JupyterHandler.initialize(self, *args) StaticFileHandler.initialize(self, "", *args) def set_extra_headers(self, path): # Disable cache self.set_header('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0') + @web.authenticated @gen.coroutine def get(self, pkg, fpath): homedir = os.path.expanduser("~") @@ -52,3 +53,5 @@ def load_jupyter_server_extension(nb_server_app): route_pattern = url_path_join(web_app.settings['base_url'], '/(assetserver)/(.*)$') web_app.add_handlers( host_pattern, [(route_pattern, JuliaPackageAssetServer)]) + +_load_jupyter_server_extension = load_jupyter_server_extension