summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio/streams.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-01-25 14:32:06 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-01-25 14:32:06 (GMT)
commit8dffc456d74a3a4395ac7a8f3957ff74f7f66753 (patch)
treee6a0b0a8ceaea275bfba7276698842f3a0ab5d79 /Lib/asyncio/streams.py
parent75a5ec88ff41ad7d3909e54ce517754298b31404 (diff)
downloadcpython-8dffc456d74a3a4395ac7a8f3957ff74f7f66753.zip
cpython-8dffc456d74a3a4395ac7a8f3957ff74f7f66753.tar.gz
cpython-8dffc456d74a3a4395ac7a8f3957ff74f7f66753.tar.bz2
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
Diffstat (limited to 'Lib/asyncio/streams.py')
-rw-r--r--Lib/asyncio/streams.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index b53080e..10d3591 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -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)