From 7be47edf6cc5ff38699abdc5855cb0e34180378a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 22 Feb 2017 09:59:34 -0800 Subject: [PATCH] deprecate output_length --- aiohttp/file_sender.py | 3 +-- aiohttp/helpers.py | 2 +- aiohttp/http_message.py | 8 ++++---- aiohttp/web_response.py | 7 ++----- tests/test_helpers.py | 7 +++---- tests/test_web_response.py | 3 ++- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/aiohttp/file_sender.py b/aiohttp/file_sender.py index 909ba269a61..079c1fd103c 100644 --- a/aiohttp/file_sender.py +++ b/aiohttp/file_sender.py @@ -97,8 +97,7 @@ def write_eof(): bheaders = ''.join(headers).encode('utf-8') headers_length = len(bheaders) - resp_impl.headers_length = headers_length - resp_impl.output_length = headers_length + count + resp_impl.output_size = headers_length + count try: yield from loop.sock_sendall(out_socket, bheaders) diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 6da1edb41ba..fae5bf3ec8c 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -351,7 +351,7 @@ def _format_b(args): @staticmethod def _format_O(args): - return args[2].output_length + return args[2].body_length @staticmethod def _format_T(args): diff --git a/aiohttp/http_message.py b/aiohttp/http_message.py index 14c8b89154a..383619a5f7d 100644 --- a/aiohttp/http_message.py +++ b/aiohttp/http_message.py @@ -47,7 +47,7 @@ def __init__(self, stream, loop): self.length = None self.chunked = False self.buffer_size = 0 - self.output_length = 0 + self.output_size = 0 self._buffer = [] self._compress = None @@ -98,13 +98,13 @@ def buffer_data(self, chunk): if chunk: size = len(chunk) self.buffer_size += size - self.output_length += size + self.output_size += size self._buffer.append(chunk) def _write(self, chunk): size = len(chunk) self.buffer_size += size - self.output_length += size + self.output_size += size if self._transport is not None: if self._buffer: @@ -217,7 +217,7 @@ def __init__(self, transport, version, close, loop=None): @property def body_length(self): - return self.output_length + return self.output_size def force_close(self): self.closing = True diff --git a/aiohttp/web_response.py b/aiohttp/web_response.py index 2050eebad5f..6cff229e6f2 100644 --- a/aiohttp/web_response.py +++ b/aiohttp/web_response.py @@ -103,6 +103,7 @@ def body_length(self): @property def output_length(self): + warnings.warn('output_length is deprecated', DeprecationWarning) return self._payload_writer.buffer_size def enable_chunked_encoding(self, chunk_size=None): @@ -372,10 +373,6 @@ def _start(self, request, return writer def _send_headers(self, version, headers, writer, _sep=': ', _end='\r\n'): - # Durty hack required for - # https://github.com/KeepSafe/aiohttp/issues/1093 - # File sender may override it - status_line = 'HTTP/{}.{} {} {}\r\n'.format( version[0], version[1], self._status, self._reason) @@ -419,7 +416,7 @@ def write_eof(self, data=b''): yield from self._payload_writer.write_eof(data) self._eof_sent = True self._req = None - self._body_length = self._payload_writer.output_length + self._body_length = self._payload_writer.output_size self._payload_writer = None def __repr__(self): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index a396283bf5c..be7aca8e0e9 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -123,16 +123,15 @@ def test_access_logger_atoms(mocker): access_logger = helpers.AccessLogger(mock_logger, log_format) message = mock.Mock(headers={}, method="GET", path="/path", version=(1, 1)) environ = {} - response = mock.Mock(headers={}, output_length=123, - body_length=42, status=200) + response = mock.Mock(headers={}, body_length=42, status=200) transport = mock.Mock() transport.get_extra_info.return_value = ("127.0.0.2", 1234) access_logger.log(message, environ, response, transport, 3.1415926) assert not mock_logger.exception.called expected = ('127.0.0.2 [01/Jan/1843:00:00:00 +0000] <42> - - ' - 'GET /path HTTP/1.1 200 42 123 3 3.141593 3141593') + 'GET /path HTTP/1.1 200 42 42 3 3.141593 3141593') extra = { - 'bytes_sent': 123, + 'bytes_sent': 42, 'first_request_line': 'GET /path HTTP/1.1', 'process_id': '<42>', 'remote_address': '127.0.0.2', diff --git a/tests/test_web_response.py b/tests/test_web_response.py index 222edcdee5e..43de3d28802 100644 --- a/tests/test_web_response.py +++ b/tests/test_web_response.py @@ -472,7 +472,8 @@ def test_force_close(): def test_response_output_length(): resp = StreamResponse() yield from resp.prepare(make_request('GET', '/')) - assert resp.output_length + with pytest.warns(DeprecationWarning): + assert resp.output_length def test_response_cookies():