Issue 24179: Support 'async for' for asyncio.StreamReader.

This commit is contained in:
Yury Selivanov 2015-05-13 14:23:29 -04:00
parent d4be691494
commit 33c6b569b7
3 changed files with 36 additions and 0 deletions

View file

@ -6,6 +6,7 @@
]
import socket
import sys
if hasattr(socket, 'AF_UNIX'):
__all__.extend(['open_unix_connection', 'start_unix_server'])
@ -19,6 +20,7 @@
_DEFAULT_LIMIT = 2**16
_PY35 = sys.version_info >= (3, 5)
class IncompleteReadError(EOFError):
@ -485,3 +487,15 @@ def readexactly(self, n):
n -= len(block)
return b''.join(blocks)
if _PY35:
@coroutine
def __aiter__(self):
return self
@coroutine
def __anext__(self):
val = yield from self.readline()
if val == b'':
raise StopAsyncIteration
return val