``ssl_options=dict(cert_reqs=ssl.CERT_NONE)`` or a
suitably-configured `ssl.SSLContext` to the
`SSLIOStream` constructor to disable.
+
+ .. deprecated:: 5.1
+
+ The ``callback`` argument is deprecated and will be removed
+ in Tornado 6.0. Use the returned `.Future` instead.
+
"""
self._connecting = True
if callback is not None:
+ warnings.warn("callback argument is deprecated, use returned Future instead",
+ DeprecationWarning)
self._connect_callback = stack_context.wrap(callback)
future = None
else:
def connect(self, address, callback=None, server_hostname=None):
self._server_hostname = server_hostname
- # Pass a dummy callback to super.connect(), which is slightly
- # more efficient than letting it return a Future we ignore.
- super(SSLIOStream, self).connect(address, callback=lambda: None)
+ # Ignore the result of connect(). If it fails,
+ # wait_for_handshake will raise an error too. This is
+ # necessary for the old semantics of the connect callback
+ # (which takes no arguments). In 6.0 this can be refactored to
+ # be a regular coroutine.
+ fut = super(SSLIOStream, self).connect(address)
+ fut.add_done_callback(lambda f: f.exception())
return self.wait_for_handshake(callback)
def _handle_connect(self):
from tornado.netutil import ssl_options_to_context
from tornado.simple_httpclient import SimpleAsyncHTTPClient
from tornado.testing import AsyncHTTPTestCase, AsyncHTTPSTestCase, AsyncTestCase, ExpectLog, gen_test # noqa: E501
-from tornado.test.util import unittest, skipOnTravis
+from tornado.test.util import unittest, skipOnTravis, ignore_deprecation
from tornado.web import Application, RequestHandler, asynchronous, stream_request_body
from contextlib import closing
def raw_fetch(self, headers, body, newline=b"\r\n"):
with closing(IOStream(socket.socket())) as stream:
- stream.connect(('127.0.0.1', self.get_http_port()), self.stop)
+ with ignore_deprecation():
+ stream.connect(('127.0.0.1', self.get_http_port()), self.stop)
self.wait()
stream.write(
newline.join(headers +
def setUp(self):
super(HTTPServerRawTest, self).setUp()
self.stream = IOStream(socket.socket())
- self.stream.connect(('127.0.0.1', self.get_http_port()), self.stop)
- self.wait()
+ self.io_loop.run_sync(lambda: self.stream.connect(('127.0.0.1', self.get_http_port())))
def tearDown(self):
self.stream.close()
self.server = HTTPServer(app)
self.server.add_socket(sock)
self.stream = IOStream(socket.socket(socket.AF_UNIX))
- self.stream.connect(self.sockfile, self.stop)
- self.wait()
+ self.io_loop.run_sync(lambda: self.stream.connect(self.sockfile))
def tearDown(self):
self.stream.close()
def connected_callback():
connected[0] = True
cond.notify()
- stream.connect(("127.0.0.1", self.get_http_port()),
- callback=connected_callback)
+ with ignore_deprecation():
+ stream.connect(("127.0.0.1", self.get_http_port()),
+ callback=connected_callback)
# unlike the previous tests, try to write before the connection
# is complete.
written = [False]
stream.set_close_callback(self.stop)
# log messages vary by platform and ioloop implementation
with ExpectLog(gen_log, ".*", required=False):
- stream.connect(("127.0.0.1", port), connect_callback)
+ with ignore_deprecation():
+ stream.connect(("127.0.0.1", port), connect_callback)
self.wait()
self.assertFalse(self.connect_called)
self.assertTrue(isinstance(stream.error, socket.error), stream.error)
with mock.patch('socket.socket.connect',
side_effect=socket.gaierror(errno.EIO, 'boom')):
with ExpectLog(gen_log, "Connect error"):
- stream.connect(('localhost', 80), callback=self.stop)
+ with ignore_deprecation():
+ stream.connect(('localhost', 80), callback=self.stop)
self.wait()
self.assertIsInstance(stream.error, socket.gaierror)