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