From ea896c3f1635e75736f8fbd1e105f3e34bf7f760 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sat, 25 Oct 2014 17:10:41 -0700 Subject: [PATCH] Compatibility fix for Tornado 3.x --- IPython/html/terminal/handlers.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/IPython/html/terminal/handlers.py b/IPython/html/terminal/handlers.py index 20dfd2c92..b0e2e4f4b 100644 --- a/IPython/html/terminal/handlers.py +++ b/IPython/html/terminal/handlers.py @@ -3,6 +3,7 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. +import tornado from tornado import web import terminado from ..base.handlers import IPythonHandler @@ -25,4 +26,18 @@ class TermSocket(terminado.TermSocket, IPythonHandler): def get(self, *args, **kwargs): if not self.get_current_user(): raise web.HTTPError(403) - return super(TermSocket, self).get(*args, **kwargs) + + # FIXME: only do super get on tornado ≥ 4 + # tornado 3 has no get, will raise 405 + if tornado.version_info >= (4,): + return super(TermSocket, self).get(*args, **kwargs) + + def open(self, *args, **kwargs): + if tornado.version_info < (4,): + try: + self.get(*self.open_args, **self.open_kwargs) + except web.HTTPError: + self.close() + raise + + super(TermSocket, self).open(*args, **kwargs)