]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
web,http1connection: Remove callback argument to flush()
authorBen Darnell <ben@bendarnell.com>
Fri, 6 Jul 2018 23:03:08 +0000 (19:03 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 14 Jul 2018 20:58:48 +0000 (16:58 -0400)
tornado/http1connection.py
tornado/test/web_test.py
tornado/web.py

index af7abe7c856db0ad59c76c44bebdf84d691239e1..d924d621b80adcb2da443421c71b0c880c625da9 100644 (file)
@@ -21,7 +21,6 @@
 from __future__ import absolute_import, division, print_function
 
 import re
-import warnings
 
 from tornado.concurrent import (Future, future_add_done_callback,
                                 future_set_result_unless_cancelled)
@@ -31,7 +30,7 @@ from tornado import httputil
 from tornado import iostream
 from tornado.log import gen_log, app_log
 from tornado import stack_context
-from tornado.util import GzipDecompressor, PY3
+from tornado.util import GzipDecompressor
 
 
 class _QuietException(Exception):
@@ -337,7 +336,7 @@ class HTTP1Connection(httputil.HTTPConnection):
         """
         self._max_body_size = max_body_size
 
-    def write_headers(self, start_line, headers, chunk=None, callback=None):
+    def write_headers(self, start_line, headers, chunk=None):
         """Implements `.HTTPConnection.write_headers`."""
         lines = []
         if self.is_client:
@@ -388,10 +387,7 @@ class HTTP1Connection(httputil.HTTPConnection):
         # cases that let bytes slip through. Remove these native_str calls when those
         # are fixed.
         header_lines = (native_str(n) + ": " + native_str(v) for n, v in headers.get_all())
-        if PY3:
-            lines.extend(l.encode('latin1') for l in header_lines)
-        else:
-            lines.extend(header_lines)
+        lines.extend(l.encode('latin1') for l in header_lines)
         for line in lines:
             if b'\n' in line:
                 raise ValueError('Newline in header: ' + repr(line))
@@ -401,12 +397,7 @@ class HTTP1Connection(httputil.HTTPConnection):
             future.set_exception(iostream.StreamClosedError())
             future.exception()
         else:
-            if callback is not None:
-                warnings.warn("callback argument is deprecated, use returned Future instead",
-                              DeprecationWarning)
-                self._write_callback = stack_context.wrap(callback)
-            else:
-                future = self._write_future = Future()
+            future = self._write_future = Future()
             data = b"\r\n".join(lines) + b"\r\n\r\n"
             if chunk:
                 data += self._format_chunk(chunk)
@@ -429,7 +420,7 @@ class HTTP1Connection(httputil.HTTPConnection):
         else:
             return chunk
 
-    def write(self, chunk, callback=None):
+    def write(self, chunk):
         """Implements `.HTTPConnection.write`.
 
         For backwards compatibility it is allowed but deprecated to
@@ -442,12 +433,7 @@ class HTTP1Connection(httputil.HTTPConnection):
             self._write_future.set_exception(iostream.StreamClosedError())
             self._write_future.exception()
         else:
-            if callback is not None:
-                warnings.warn("callback argument is deprecated, use returned Future instead",
-                              DeprecationWarning)
-                self._write_callback = stack_context.wrap(callback)
-            else:
-                future = self._write_future = Future()
+            future = self._write_future = Future()
             self._pending_write = self.stream.write(self._format_chunk(chunk))
             self._pending_write.add_done_callback(self._on_write_complete)
         return future
index 9a435c3006a928d25552b0264c34fd705ec44721..ebe9e264d00978840ec4c1fd33a6ac681afcc1c6 100644 (file)
@@ -582,26 +582,6 @@ class OptionalPathHandler(RequestHandler):
         self.write({"path": path})
 
 
-class FlowControlHandler(RequestHandler):
-    # These writes are too small to demonstrate real flow control,
-    # but at least it shows that the callbacks get run.
-    with ignore_deprecation():
-        @asynchronous
-        def get(self):
-            self.write("1")
-            with ignore_deprecation():
-                self.flush(callback=self.step2)
-
-    def step2(self):
-        self.write("2")
-        with ignore_deprecation():
-            self.flush(callback=self.step3)
-
-    def step3(self):
-        self.write("3")
-        self.finish()
-
-
 class MultiHeaderHandler(RequestHandler):
     def get(self):
         self.set_header("x-overwrite", "1")
@@ -911,13 +891,9 @@ js_embed()
 
 class NonWSGIWebTests(WebTestCase):
     def get_handlers(self):
-        return [("/flow_control", FlowControlHandler),
-                ("/empty_flush", EmptyFlushCallbackHandler),
+        return [("/empty_flush", EmptyFlushCallbackHandler),
                 ]
 
-    def test_flow_control(self):
-        self.assertEqual(self.fetch("/flow_control").body, b"123")
-
     def test_empty_flush(self):
         response = self.fetch("/empty_flush")
         self.assertEqual(response.body, b"ok")
index 6760b0b9a166c79ccbbbf9abe1c0c7994bdd4384..a0488f6b97e0749375cdc75174d09c87422e4a9f 100644 (file)
@@ -950,7 +950,7 @@ class RequestHandler(object):
             kwargs["whitespace"] = settings["template_whitespace"]
         return template.Loader(template_path, **kwargs)
 
-    def flush(self, include_footers=False, callback=None):
+    def flush(self, include_footers=False):
         """Flushes the current output buffer to the network.
 
         The ``callback`` argument, if given, can be used for flow control:
@@ -962,10 +962,9 @@ class RequestHandler(object):
         .. versionchanged:: 4.0
            Now returns a `.Future` if no callback is given.
 
-        .. deprecated:: 5.1
+        .. versionchanged:: 6.0
 
-           The ``callback`` argument is deprecated and will be removed in
-           Tornado 6.0.
+           The ``callback`` argument was removed.
         """
         chunk = b"".join(self._write_buffer)
         self._write_buffer = []
@@ -991,13 +990,13 @@ class RequestHandler(object):
                                                     self._status_code,
                                                     self._reason)
             return self.request.connection.write_headers(
-                start_line, self._headers, chunk, callback=callback)
+                start_line, self._headers, chunk)
         else:
             for transform in self._transforms:
                 chunk = transform.transform_chunk(chunk, include_footers)
             # Ignore the chunk and only write the headers for HEAD requests
             if self.request.method != "HEAD":
-                return self.request.connection.write(chunk, callback=callback)
+                return self.request.connection.write(chunk)
             else:
                 future = Future()
                 future.set_result(None)