mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Update asyncio from the Tulip project
Major changes: - StreamReader.readexactly() now raises an IncompleteReadError if the end of stream is reached before we received enough bytes, instead of returning less bytes than requested. - Unit tests use the main asyncio module instead of submodules like events - _UnixWritePipeTransport now also supports character devices, as _UnixReadPipeTransport. Patch written by Jonathan Slenders. - Export more symbols: BaseEventLoop, BaseProactorEventLoop, BaseSelectorEventLoop, Queue and Queue sublasses, Empty, Full
This commit is contained in:
parent
75a5ec88ff
commit
8dffc456d7
17 changed files with 931 additions and 887 deletions
|
@ -1,7 +1,7 @@
|
|||
"""Stream-related things."""
|
||||
|
||||
__all__ = ['StreamReader', 'StreamWriter', 'StreamReaderProtocol',
|
||||
'open_connection', 'start_server',
|
||||
'open_connection', 'start_server', 'IncompleteReadError',
|
||||
]
|
||||
|
||||
import collections
|
||||
|
@ -14,6 +14,19 @@ from . import tasks
|
|||
|
||||
_DEFAULT_LIMIT = 2**16
|
||||
|
||||
class IncompleteReadError(EOFError):
|
||||
"""
|
||||
Incomplete read error. Attributes:
|
||||
|
||||
- partial: read bytes string before the end of stream was reached
|
||||
- expected: total number of expected bytes
|
||||
"""
|
||||
def __init__(self, partial, expected):
|
||||
EOFError.__init__(self, "%s bytes read on a total of %s expected bytes"
|
||||
% (len(partial), expected))
|
||||
self.partial = partial
|
||||
self.expected = expected
|
||||
|
||||
|
||||
@tasks.coroutine
|
||||
def open_connection(host=None, port=None, *,
|
||||
|
@ -403,12 +416,9 @@ class StreamReader:
|
|||
while n > 0:
|
||||
block = yield from self.read(n)
|
||||
if not block:
|
||||
break
|
||||
partial = b''.join(blocks)
|
||||
raise IncompleteReadError(partial, len(partial) + n)
|
||||
blocks.append(block)
|
||||
n -= len(block)
|
||||
|
||||
# TODO: Raise EOFError if we break before n == 0? (That would
|
||||
# be a change in specification, but I've always had to add an
|
||||
# explicit size check to the caller.)
|
||||
|
||||
return b''.join(blocks)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue