diff --git a/aiohttp/http_writer.py b/aiohttp/http_writer.py index 0c890b593b7..96df99d7613 100644 --- a/aiohttp/http_writer.py +++ b/aiohttp/http_writer.py @@ -151,8 +151,8 @@ def set_transport(self, transport): self._transport = transport if self._buffer is not None: - for b in self._buffer: - transport.write(b) + for chunk in self._buffer: + transport.write(chunk) self._buffer = None if self._drain_waiter is not None: @@ -163,10 +163,9 @@ def set_transport(self, transport): async def get_transport(self): if self._transport is None: if self._drain_waiter is None: - self._drain_waiter = create_future(self.loop) + self._drain_waiter = self.loop.create_future() await self._drain_waiter - assert self._transport is not None return self._transport @property @@ -198,7 +197,6 @@ def _write(self, chunk): # see set_transport: exactly one of _buffer or _transport is None if self._transport is not None: - assert self._buffer is None self._transport.write(chunk) else: self._buffer.append(chunk) @@ -275,7 +273,7 @@ async def write_eof(self, chunk=b''): self._transport = None self._stream.release() - async def drain(self, last=False): + async def drain(self): if self._transport is not None: await self._stream.drain() else: diff --git a/aiohttp/web_fileresponse.py b/aiohttp/web_fileresponse.py index 39e71a375d5..1b0cd6d6103 100644 --- a/aiohttp/web_fileresponse.py +++ b/aiohttp/web_fileresponse.py @@ -19,7 +19,7 @@ class SendfilePayloadWriter(PayloadWriter): def __init__(self, *args, **kwargs): - self.__buffer = [] + self._sendfile_buffer = [] super().__init__(*args, **kwargs) def _write(self, chunk): @@ -27,7 +27,7 @@ def _write(self, chunk): # _buffer, and nothing is written to the transport directly by the # parent class self.output_size += len(chunk) - self.__buffer.append(chunk) + self._sendfile_buffer.append(chunk) def _sendfile_cb(self, fut, out_fd, in_fd, offset, count, loop, registered): @@ -62,8 +62,9 @@ async def sendfile(self, fobj, count): offset = fobj.tell() loop = self.loop + data = b''.join(self._sendfile_buffer) try: - await loop.sock_sendall(out_socket, b''.join(self._buffer)) + await loop.sock_sendall(out_socket, data) fut = loop.create_future() self._sendfile_cb(fut, out_fd, in_fd, offset, count, loop, False) await fut