Skip to content

Commit

Permalink
Moves terminal websocket handling back to Jupyter Server
Browse files Browse the repository at this point in the history
jupyter#31 moved a bit too much from jupyter server to nbclassic. This moves some back. See also jupyter-server/jupyter_server#314
  • Loading branch information
jasongrout committed Sep 29, 2020
1 parent 61ea2a7 commit 923db3c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 39 deletions.
17 changes: 4 additions & 13 deletions nbclassic/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
)
from jupyter_server.utils import url_path_join as ujoin

from .terminal.handlers import TerminalHandler, TermSocket
from .terminal.handlers import TerminalHandler


#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -217,18 +217,9 @@ def initialize_handlers(self):
handlers.extend(load_handlers('nbclassic.edit.handlers'))

# Add terminal handlers
try:
term_mgr = self.serverapp.web_app.settings['terminal_manager']
except KeyError:
pass # Terminals not enabled
else:
handlers.append(
(r"/terminals/(\w+)", TerminalHandler)
)
handlers.append(
(r"/terminals/websocket/(\w+)", TermSocket,
{'term_manager': term_mgr})
)
handlers.append(
(r"/terminals/(\w+)", TerminalHandler)
)

handlers.append(
(r"/nbextensions/(.*)", FileFindHandler, {
Expand Down
26 changes: 0 additions & 26 deletions nbclassic/terminal/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
# Distributed under the terms of the Modified BSD License.

from tornado import web
import terminado
from jupyter_server._tz import utcnow
from jupyter_server.base.handlers import JupyterHandler
from jupyter_server.base.zmqhandlers import WebSocketMixin
from jupyter_server.extension.handler import (
ExtensionHandlerMixin,
ExtensionHandlerJinjaMixin
Expand All @@ -20,26 +17,3 @@ class TerminalHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, Jupyter
def get(self, term_name):
self.write(self.render_template('terminal.html',
ws_path="terminals/websocket/%s" % term_name))


class TermSocket(WebSocketMixin, JupyterHandler, terminado.TermSocket):

def origin_check(self):
"""Terminado adds redundant origin_check
Tornado already calls check_origin, so don't do anything here.
"""
return True

def get(self, *args, **kwargs):
if not self.get_current_user():
raise web.HTTPError(403)
return super(TermSocket, self).get(*args, **kwargs)

def on_message(self, message):
super(TermSocket, self).on_message(message)
self.application.settings['terminal_last_activity'] = utcnow()

def write_message(self, message, binary=False):
super(TermSocket, self).write_message(message, binary=binary)
self.application.settings['terminal_last_activity'] = utcnow()

0 comments on commit 923db3c

Please sign in to comment.