-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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 support for creating terminals via GET #5813
Changes from all commits
ac50d2e
7778dc3
84ba421
639da8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
import json | ||
from tornado import web | ||
import terminado | ||
from notebook._tz import utcnow | ||
|
@@ -15,7 +16,34 @@ class TerminalHandler(IPythonHandler): | |
@web.authenticated | ||
def get(self, term_name): | ||
self.write(self.render_template('terminal.html', | ||
ws_path="terminals/websocket/%s" % term_name)) | ||
ws_path="terminals/websocket/%s" % term_name)) | ||
|
||
|
||
class NamedTerminalHandler(IPythonHandler): | ||
"""Creates and renders a named terminal interface.""" | ||
@web.authenticated | ||
def get(self): | ||
model = self.terminal_manager.create() | ||
term_name = model['name'] | ||
new_path = self.request.path.replace("terminals/new", "terminals/" + term_name) | ||
self.redirect(new_path) | ||
|
||
|
||
class NewTerminalHandler(IPythonHandler): | ||
"""Creates and renders a terminal interface using the named argument.""" | ||
@web.authenticated | ||
def get(self, term_name): | ||
if term_name == 'new': | ||
raise web.HTTPError(400, "Terminal name 'new' is reserved.") | ||
new_path = self.request.path.replace("new/{}".format(term_name), term_name) | ||
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. If the 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. Good point. I added a commit supporting this. This does preclude someone from creating their own named terminal of 'new' (via |
||
if term_name in self.terminal_manager.terminals: | ||
self.set_header('Location', new_path) | ||
self.set_status(302) | ||
self.finish(json.dumps(self.terminal_manager.get_terminal_model(term_name))) | ||
return | ||
|
||
self.terminal_manager.create_with_name(term_name) | ||
self.redirect(new_path) | ||
|
||
|
||
class TermSocket(WebSocketMixin, IPythonHandler, terminado.TermSocket): | ||
|
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.
❤️