From: Ben Darnell Date: Sun, 22 Apr 2018 03:39:00 +0000 (-0400) Subject: iostream: Deprecated callback argument to write() X-Git-Tag: v5.1.0b1~23^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6464aabef1a457528d8b1cc0eee331204c7e27c8;p=thirdparty%2Ftornado.git iostream: Deprecated callback argument to write() --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 0220e1796..9f8fdf257 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -560,6 +560,12 @@ class BaseIOStream(object): .. versionchanged:: 4.5 Added support for `memoryview` arguments. + + .. deprecated:: 5.1 + + The ``callback`` argument is deprecated and will be removed + in Tornado 6.0. Use the returned `.Future` instead. + """ self._check_closed() if data: @@ -569,6 +575,8 @@ class BaseIOStream(object): self._write_buffer.append(data) self._total_write_index += len(data) if callback is not None: + warnings.warn("callback argument is deprecated, use returned Future instead", + DeprecationWarning) self._write_callback = stack_context.wrap(callback) future = None else: diff --git a/tornado/test/httpclient_test.py b/tornado/test/httpclient_test.py index db0492de6..851f12688 100644 --- a/tornado/test/httpclient_test.py +++ b/tornado/test/httpclient_test.py @@ -197,7 +197,7 @@ class HTTPClientCommonTestCase(AsyncHTTPTestCase): request_data = yield stream.read_until(b"\r\n\r\n") if b"HTTP/1." not in request_data: self.skipTest("requires HTTP/1.x") - stream.write(b"""\ + yield stream.write(b"""\ HTTP/1.1 200 OK Transfer-Encoding: chunked @@ -207,7 +207,8 @@ Transfer-Encoding: chunked 2 0 -""".replace(b"\n", b"\r\n"), callback=stream.close) +""".replace(b"\n", b"\r\n")) + stream.close() netutil.add_accept_handler(sock, accept_callback) resp = self.fetch("http://127.0.0.1:%d/" % port) resp.rethrow() @@ -386,12 +387,13 @@ Transfer-Encoding: chunked request_data = yield stream.read_until(b"\r\n\r\n") if b"HTTP/1." not in request_data: self.skipTest("requires HTTP/1.x") - stream.write(b"""\ + yield stream.write(b"""\ HTTP/1.1 200 OK X-XSS-Protection: 1; \tmode=block -""".replace(b"\n", b"\r\n"), callback=stream.close) +""".replace(b"\n", b"\r\n")) + stream.close() netutil.add_accept_handler(sock, accept_callback) resp = self.fetch("http://127.0.0.1:%d/" % port) diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index c6049dd46..8f3ef1077 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -109,8 +109,9 @@ class TestIOStreamWebMixin(object): def write_callback(): written[0] = True cond.notify() - stream.write(b"GET / HTTP/1.0\r\nConnection: close\r\n\r\n", - callback=write_callback) + with ignore_deprecation(): + stream.write(b"GET / HTTP/1.0\r\nConnection: close\r\n\r\n", + callback=write_callback) self.assertTrue(not connected[0]) # by the time the write has flushed, the connection callback has # also run diff --git a/tornado/test/simple_httpclient_test.py b/tornado/test/simple_httpclient_test.py index bff9cb50f..818fdad83 100644 --- a/tornado/test/simple_httpclient_test.py +++ b/tornado/test/simple_httpclient_test.py @@ -576,14 +576,16 @@ class HTTP100ContinueTestCase(AsyncHTTPTestCase): request.connection.finish() return self.request = request - self.request.connection.stream.write( - b"HTTP/1.1 100 CONTINUE\r\n\r\n", - self.respond_200) + with ignore_deprecation(): + self.request.connection.stream.write( + b"HTTP/1.1 100 CONTINUE\r\n\r\n", + self.respond_200) def respond_200(self): - self.request.connection.stream.write( - b"HTTP/1.1 200 OK\r\nContent-Length: 1\r\n\r\nA", - self.request.connection.stream.close) + with ignore_deprecation(): + self.request.connection.stream.write( + b"HTTP/1.1 200 OK\r\nContent-Length: 1\r\n\r\nA", + self.request.connection.stream.close) def get_app(self): # Not a full Application, but works as an HTTPServer callback