From 4f7c91bfdc71d0de7e22b146d20c1adc718b8004 Mon Sep 17 00:00:00 2001 From: Amin Etesamian Date: Tue, 31 Oct 2017 20:37:48 +0330 Subject: [PATCH] payload.py now uses async/await syntax (#2452) --- aiohttp/payload.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/aiohttp/payload.py b/aiohttp/payload.py index 7296594c90b..fca80e7dc2b 100644 --- a/aiohttp/payload.py +++ b/aiohttp/payload.py @@ -126,9 +126,8 @@ def set_content_disposition(self, disptype, quote_fields=True, **params): self._headers[hdrs.CONTENT_DISPOSITION] = content_disposition_header( disptype, quote_fields=quote_fields, **params) - @asyncio.coroutine # pragma: no branch @abstractmethod - def write(self, writer): + async def write(self, writer): """Write payload. writer is an AbstractPayloadWriter instance: @@ -234,12 +233,11 @@ def size(self): except OSError: return None - @asyncio.coroutine - def write(self, writer): + async def write(self, writer): try: chunk = self._value.read(DEFAULT_LIMIT) while chunk: - yield from writer.write(chunk.encode(self._encoding)) + await writer.write(chunk.encode(self._encoding)) chunk = self._value.read(DEFAULT_LIMIT) finally: self._value.close() @@ -269,24 +267,22 @@ def size(self): class StreamReaderPayload(Payload): - @asyncio.coroutine - def write(self, writer): - chunk = yield from self._value.read(DEFAULT_LIMIT) + async def write(self, writer): + chunk = await self._value.read(DEFAULT_LIMIT) while chunk: - yield from writer.write(chunk) - chunk = yield from self._value.read(DEFAULT_LIMIT) + await writer.write(chunk) + chunk = await self._value.read(DEFAULT_LIMIT) class DataQueuePayload(Payload): - @asyncio.coroutine - def write(self, writer): + async def write(self, writer): while True: try: - chunk = yield from self._value.read() + chunk = await self._value.read() if not chunk: break - yield from writer.write(chunk) + await writer.write(chunk) except EofStream: break