-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add terminal and editor handlers #31
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#encoding: utf-8 | ||
"""Tornado handlers for the terminal emulator.""" | ||
|
||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
from tornado import web | ||
from jupyter_server.base.handlers import JupyterHandler, path_regex | ||
from jupyter_server.utils import url_escape | ||
from jupyter_server.extension.handler import ( | ||
ExtensionHandlerMixin, | ||
ExtensionHandlerJinjaMixin | ||
) | ||
|
||
class EditorHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): | ||
"""Render the text editor interface.""" | ||
|
||
@web.authenticated | ||
def get(self, path): | ||
path = path.strip('/') | ||
if not self.contents_manager.file_exists(path): | ||
raise web.HTTPError(404, u'File does not exist: %s' % path) | ||
|
||
basename = path.rsplit('/', 1)[-1] | ||
self.write(self.render_template('edit.html', | ||
file_path=url_escape(path), | ||
basename=basename, | ||
page_title=basename + " (editing)", | ||
) | ||
) | ||
|
||
default_handlers = [ | ||
(r"/edit%s" % path_regex, EditorHandler), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,14 @@ | |
from jupyter_server.log import log_request | ||
from jupyter_server.transutils import _ | ||
from jupyter_server.serverapp import ( | ||
ServerApp, | ||
random_ports, | ||
load_handlers | ||
) | ||
from jupyter_server.utils import url_path_join as ujoin | ||
|
||
from .terminal.handlers import TerminalHandler, TermSocket | ||
|
||
|
||
#----------------------------------------------------------------------------- | ||
# Module globals | ||
|
@@ -88,13 +93,13 @@ | |
'ip': 'ServerApp.ip', | ||
'port': 'ServerApp.port', | ||
'port-retries': 'ServerApp.port_retries', | ||
'transport': 'ServerApp.KernelManager.transport', | ||
#'transport': 'KernelManager.transport', | ||
'keyfile': 'ServerApp.keyfile', | ||
'certfile': 'ServerApp.certfile', | ||
'client-ca': 'ServerApp.client_ca', | ||
'notebook-dir': 'ServerApp.notebook_dir', | ||
'browser': 'ServerApp.browser', | ||
'gateway-url': 'ServerApp.GatewayClient.url', | ||
#'gateway-url': 'GatewayClient.url', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a known issue. |
||
}) | ||
|
||
#----------------------------------------------------------------------------- | ||
|
@@ -209,6 +214,21 @@ def initialize_handlers(self): | |
|
||
handlers.extend(load_handlers('nbclassic.tree.handlers')) | ||
handlers.extend(load_handlers('nbclassic.notebook.handlers')) | ||
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"/nbextensions/(.*)", FileFindHandler, { | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#encoding: utf-8 | ||
"""Tornado handlers for the terminal emulator.""" | ||
|
||
# Copyright (c) Jupyter Development Team. | ||
# 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 | ||
) | ||
|
||
class TerminalHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): | ||
"""Render the terminal interface.""" | ||
@web.authenticated | ||
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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a known issue.