##// END OF EJS Templates
add websocket workarounds for tornado 3...
MinRK -
Show More
@@ -1,3 +1,4 b''
1 # coding: utf-8
1 2 """Tornado handlers for WebSocket <-> ZMQ sockets."""
2 3
3 4 # Copyright (c) IPython Development Team.
@@ -11,12 +12,6 b' try:'
11 12 except ImportError:
12 13 from urlparse import urlparse # Py 2
13 14
14 try:
15 from http.cookies import SimpleCookie # Py 3
16 except ImportError:
17 from Cookie import SimpleCookie # Py 2
18 import logging
19
20 15 import tornado
21 16 from tornado import ioloop
22 17 from tornado import web
@@ -24,7 +19,7 b' from tornado import websocket'
24 19
25 20 from IPython.kernel.zmq.session import Session
26 21 from IPython.utils.jsonutil import date_default, extract_dates
27 from IPython.utils.py3compat import PY3, cast_unicode
22 from IPython.utils.py3compat import cast_unicode
28 23
29 24 from .handlers import IPythonHandler
30 25
@@ -218,13 +213,21 b' class AuthenticatedZMQStreamHandler(ZMQStreamHandler, IPythonHandler):'
218 213 self.session.session = cast_unicode(self.get_argument('session_id'))
219 214 else:
220 215 self.log.warn("No session ID specified")
221
216 # FIXME: only do super get on tornado ≥ 4
217 # tornado 3 has no get, will raise 405
218 if tornado.version_info >= (4,):
222 219 return super(AuthenticatedZMQStreamHandler, self).get(*args, **kwargs)
223 220
224 221 def initialize(self):
225 222 self.session = Session(config=self.config)
226 223
227 224 def open(self, *args, **kwargs):
225 if tornado.version_info < (4,):
226 try:
227 self.get(*self.open_args, **self.open_kwargs)
228 except web.HTTPError:
229 self.close()
230 raise
228 231
229 232 # start the pinging
230 233 if self.ping_interval > 0:
@@ -155,6 +155,7 b' class ZMQChannelHandler(AuthenticatedZMQStreamHandler):'
155 155 def initialize(self):
156 156 super(ZMQChannelHandler, self).initialize()
157 157 self.zmq_stream = None
158 self.kernel_id = None
158 159 self.kernel_info_channel = None
159 160 self._kernel_info_future = Future()
160 161
@@ -168,7 +169,8 b' class ZMQChannelHandler(AuthenticatedZMQStreamHandler):'
168 169 super(ZMQChannelHandler, self).open()
169 170 try:
170 171 self.create_stream()
171 except web.HTTPError:
172 except web.HTTPError as e:
173 self.log.error("Error opening stream: %s", e)
172 174 # WebSockets don't response to traditional error codes so we
173 175 # close the connection.
174 176 if not self.stream.closed():
General Comments 0
You need to be logged in to leave comments. Login now