Skip to content

Commit

Permalink
payload.py now uses async/await syntax (#2452)
Browse files Browse the repository at this point in the history
  • Loading branch information
eteamin authored and asvetlov committed Oct 31, 2017
1 parent fab1f23 commit 4f7c91b
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions aiohttp/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 4f7c91b

Please sign in to comment.