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)
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):
"""
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:
# 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))
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)
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
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
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")
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")
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:
.. 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 = []
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)