Skip to content

Commit 7cf9436

Browse files
authored
Merge pull request #174 from datalayer-contrib/extension_handlers
Make ExtensionHandler a Mixin
2 parents ae0fde3 + 4601830 commit 7cf9436

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

docs/source/frontends.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Writing a frontend application
1414
Jupyter Server provides two key classes for writing a server frontend:
1515

1616
- ``ExtensionApp``
17-
- ``ExtensionHandler``
17+
- ``ExtensionHandlerMixin``
1818

1919
The ExtensionApp:
2020

@@ -81,13 +81,13 @@ Properties
8181
Writing frontend handlers
8282
-------------------------
8383

84-
To write handlers for an ``ExtensionApp``, use the ``ExtensionHandler`` class. This class routes Tornado's ``static_url`` attribute to the ``/static/<extension_name>/`` namespace where your frontend's static files will be served.
84+
To write handlers for an ``ExtensionApp``, use the ``ExtensionHandlerMixin`` class. This class routes Tornado's ``static_url`` attribute to the ``/static/<extension_name>/`` namespace where your frontend's static files will be served.
8585

8686
.. code-block:: python
8787
88-
from jupyter_server.extension import ExtensionHandler
88+
from jupyter_server.extension import ExtensionHandlerMixin
8989
90-
class MyFrontendHandler(ExtensionHandler):
90+
class MyFrontendHandler(ExtensionHandlerMixin, JupyterHandler):
9191
9292
urls = ['/myfrontend/hello']
9393
@@ -97,7 +97,7 @@ To write handlers for an ``ExtensionApp``, use the ``ExtensionHandler`` class. T
9797
def post(self):
9898
...
9999
100-
ExtensionHandler comes with the following properties:
100+
ExtensionHandlerMixin comes with the following properties:
101101

102102
* ``config``: the ExtensionApp's config object.
103103
* ``server_config``: the ServerApp's config object.

jupyter_server/extension/application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from jupyter_server.serverapp import ServerApp, aliases, flags
1919
from jupyter_server.transutils import _
2020
from jupyter_server.utils import url_path_join
21-
from .handler import ExtensionHandler
21+
from .handler import ExtensionHandlerMixin
2222

2323
# Remove alias for nested classes in ServerApp.
2424
# Nested classes are not allowed in ExtensionApp.
@@ -321,7 +321,7 @@ def _prepare_handlers(self):
321321

322322
# Get handler kwargs, if given
323323
kwargs = {}
324-
if issubclass(handler, ExtensionHandler):
324+
if issubclass(handler, ExtensionHandlerMixin):
325325
kwargs['extension_name'] = self.extension_name
326326
try:
327327
kwargs.update(handler_items[2])

jupyter_server/extension/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from jupyter_server.base.handlers import JupyterHandler, FileFindHandler
1+
from jupyter_server.base.handlers import FileFindHandler
22
from traitlets import Unicode, default
33

44

@@ -12,7 +12,7 @@ def get_template(self, name):
1212
return self.settings[env].get_template(name)
1313

1414

15-
class ExtensionHandler(JupyterHandler):
15+
class ExtensionHandlerMixin():
1616
"""Base class for Jupyter server extension handlers.
1717
1818
Subclasses can serve static files behind a namespaced

tests/extension/conftest.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44

55

66
from jupyter_core import paths
7+
from jupyter_server.base.handlers import JupyterHandler
78
from jupyter_server.extension import serverextension
89
from jupyter_server.extension.serverextension import _get_config_dir
910
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
10-
from jupyter_server.extension.handler import ExtensionHandler, ExtensionHandlerJinjaMixin
11+
from jupyter_server.extension.handler import ExtensionHandlerMixin, ExtensionHandlerJinjaMixin
1112

1213
# ----------------- Mock Extension App ----------------------
1314

14-
class MockExtensionHandler(ExtensionHandler):
15+
class MockExtensionHandler(ExtensionHandlerMixin, JupyterHandler):
1516

1617
def get(self):
1718
self.finish(self.config.mock_trait)
1819

1920

20-
class MockExtensionTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandler):
21+
class MockExtensionTemplateHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler):
2122

2223
def get(self):
2324
self.write(self.render_template("index.html"))

0 commit comments

Comments
 (0)