Skip to content

Commit

Permalink
deprecate output_length
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Feb 22, 2017
1 parent b22eb32 commit 7be47ed
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
3 changes: 1 addition & 2 deletions aiohttp/file_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions aiohttp/http_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 7be47ed

Please sign in to comment.