-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from afshin/terminal-editor
Add terminal and editor handlers
- Loading branch information
Showing
5 changed files
with
101 additions
and
2 deletions.
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
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() |