Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
33c6b569
Commit
33c6b569
authored
May 13, 2015
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 24179: Support 'async for' for asyncio.StreamReader.
parent
d4be6914
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
Lib/asyncio/streams.py
Lib/asyncio/streams.py
+14
-0
Lib/test/test_asyncio/test_pep492.py
Lib/test/test_asyncio/test_pep492.py
+19
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/asyncio/streams.py
View file @
33c6b569
...
...
@@ -6,6 +6,7 @@ __all__ = ['StreamReader', 'StreamWriter', 'StreamReaderProtocol',
]
import
socket
import
sys
if
hasattr
(
socket
,
'AF_UNIX'
):
__all__
.
extend
([
'open_unix_connection'
,
'start_unix_server'
])
...
...
@@ -19,6 +20,7 @@ from .log import logger
_DEFAULT_LIMIT
=
2
**
16
_PY35
=
sys
.
version_info
>=
(
3
,
5
)
class
IncompleteReadError
(
EOFError
):
...
...
@@ -485,3 +487,15 @@ class StreamReader:
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
Lib/test/test_asyncio/test_pep492.py
View file @
33c6b569
...
...
@@ -64,5 +64,24 @@ class LockTests(BaseTest):
self
.
assertFalse
(
primitive
.
locked
())
class
StreamReaderTests
(
BaseTest
):
def
test_readline
(
self
):
DATA
=
b'line1
\
n
line2
\
n
line3'
stream
=
asyncio
.
StreamReader
(
loop
=
self
.
loop
)
stream
.
feed_data
(
DATA
)
stream
.
feed_eof
()
async
def
reader
():
data
=
[]
async
for
line
in
stream
:
data
.
append
(
line
)
return
data
data
=
self
.
loop
.
run_until_complete
(
reader
())
self
.
assertEqual
(
data
,
[
b'line1
\
n
'
,
b'line2
\
n
'
,
b'line3'
])
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
View file @
33c6b569
...
...
@@ -119,6 +119,9 @@ Library
-
Issue
24178
:
asyncio
.
Lock
,
Condition
,
Semaphore
,
and
BoundedSemaphore
support
new
'async with'
syntax
.
Contributed
by
Yury
Selivanov
.
-
Issue
24179
:
Support
'async for'
for
asyncio
.
StreamReader
.
Contributed
by
Yury
Selivanov
.
Tests
-----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment