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