]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
iostream: Deprecated callback argument to write()
authorBen Darnell <ben@bendarnell.com>
Sun, 22 Apr 2018 03:39:00 +0000 (23:39 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 23 Apr 2018 13:08:26 +0000 (09:08 -0400)
tornado/iostream.py
tornado/test/httpclient_test.py
tornado/test/iostream_test.py
tornado/test/simple_httpclient_test.py

index 0220e1796b033a3aff0b2842ab843ded3f49231f..9f8fdf2578dfe32591eb6ff87875fed4f92b671e 100644 (file)
@@ -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:
index db0492de6dceb8163229859c36160827a15272de..851f126885c49dab616b5c6e9e27f00a07e24ac9 100644 (file)
@@ -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)
index c6049dd463af41c1adbddc8fc13d8ebe7f7409fa..8f3ef1077eadbeb416fc58526679e67a751b40f3 100644 (file)
@@ -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
index bff9cb50f051b134ac4f5ddfe704ba18fcd8b6f6..818fdad83b2e96fb6d82426e755046743fa2613a 100644 (file)
@@ -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