mirror of
https://github.com/python/cpython.git
synced 2025-10-29 20:51:26 +00:00
Issue 24179: Support 'async for' for asyncio.StreamReader.
This commit is contained in:
parent
d4be691494
commit
33c6b569b7
3 changed files with 36 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue