##// END OF EJS Templates
Fix terminals with Tornado 3...
Thomas Kluyver -
Show More
@@ -1,44 +1,48 b''
1 #encoding: utf-8
1 #encoding: utf-8
2 """Tornado handlers for the terminal emulator."""
2 """Tornado handlers for the terminal emulator."""
3
3
4 # Copyright (c) IPython Development Team.
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
5 # Distributed under the terms of the Modified BSD License.
6
6
7 import tornado
7 import tornado
8 from tornado import web
8 from tornado import web
9 import terminado
9 import terminado
10 from ..base.handlers import IPythonHandler
10 from ..base.handlers import IPythonHandler
11
11
12 class TerminalHandler(IPythonHandler):
12 class TerminalHandler(IPythonHandler):
13 """Render the terminal interface."""
13 """Render the terminal interface."""
14 @web.authenticated
14 @web.authenticated
15 def get(self, term_name):
15 def get(self, term_name):
16 self.write(self.render_template('terminal.html',
16 self.write(self.render_template('terminal.html',
17 ws_path="terminals/websocket/%s" % term_name))
17 ws_path="terminals/websocket/%s" % term_name))
18
18
19 class NewTerminalHandler(IPythonHandler):
19 class NewTerminalHandler(IPythonHandler):
20 """Redirect to a new terminal."""
20 """Redirect to a new terminal."""
21 @web.authenticated
21 @web.authenticated
22 def get(self):
22 def get(self):
23 name, _ = self.application.terminal_manager.new_named_terminal()
23 name, _ = self.application.terminal_manager.new_named_terminal()
24 self.redirect(name, permanent=False)
24 self.redirect(name, permanent=False)
25
25
26 class TermSocket(terminado.TermSocket, IPythonHandler):
26 class TermSocket(terminado.TermSocket, IPythonHandler):
27 def get(self, *args, **kwargs):
27 def get(self, *args, **kwargs):
28 if not self.get_current_user():
28 if not self.get_current_user():
29 raise web.HTTPError(403)
29 raise web.HTTPError(403)
30
30
31 # FIXME: only do super get on tornado ≥ 4
31 # FIXME: only do super get on tornado ≥ 4
32 # tornado 3 has no get, will raise 405
32 # tornado 3 has no get, will raise 405
33 if tornado.version_info >= (4,):
33 if tornado.version_info >= (4,):
34 return super(TermSocket, self).get(*args, **kwargs)
34 return super(TermSocket, self).get(*args, **kwargs)
35
36 def clear_cookie(self, *args, **kwargs):
37 """meaningless for websockets"""
38 pass
35
39
36 def open(self, *args, **kwargs):
40 def open(self, *args, **kwargs):
37 if tornado.version_info < (4,):
41 if tornado.version_info < (4,):
38 try:
42 try:
39 self.get(*self.open_args, **self.open_kwargs)
43 self.get(*self.open_args, **self.open_kwargs)
40 except web.HTTPError:
44 except web.HTTPError:
41 self.close()
45 self.close()
42 raise
46 raise
43
47
44 super(TermSocket, self).open(*args, **kwargs)
48 super(TermSocket, self).open(*args, **kwargs)
General Comments 0
You need to be logged in to leave comments. Login now