From: Ben Darnell Date: Fri, 6 Jul 2018 23:03:08 +0000 (-0400) Subject: web,http1connection: Remove callback argument to flush() X-Git-Tag: v6.0.0b1~48^2~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d1d02fa5e2be955ec7869657ee7b13566137fa4;p=thirdparty%2Ftornado.git web,http1connection: Remove callback argument to flush() --- diff --git a/tornado/http1connection.py b/tornado/http1connection.py index af7abe7c8..d924d621b 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -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 diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 9a435c300..ebe9e264d 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -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") diff --git a/tornado/web.py b/tornado/web.py index 6760b0b9a..a0488f6b9 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -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)