summaryrefslogtreecommitdiffstats
path: root/Lib/asyncio
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2016-10-05 22:04:35 (GMT)
committerYury Selivanov <yury@magic.io>2016-10-05 22:04:35 (GMT)
commit139914a0589154aaf0f47ad6725f71e8baf2a6cf (patch)
tree2c271eb45a06ceb761e34a50f93507e189671375 /Lib/asyncio
parentbb8eb92f46f6efbdfd736ff0b6f7ab9391c90e12 (diff)
parent3e56ff0d08a65ea1e0fe361ae22d855acc9d65bb (diff)
downloadcpython-139914a0589154aaf0f47ad6725f71e8baf2a6cf.zip
cpython-139914a0589154aaf0f47ad6725f71e8baf2a6cf.tar.gz
cpython-139914a0589154aaf0f47ad6725f71e8baf2a6cf.tar.bz2
Merge 3.5 (issue #28370)
Diffstat (limited to 'Lib/asyncio')
-rw-r--r--Lib/asyncio/streams.py36
1 files changed, 17 insertions, 19 deletions
diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py
index b4adc7d..a82cc79 100644
--- a/Lib/asyncio/streams.py
+++ b/Lib/asyncio/streams.py
@@ -448,6 +448,7 @@ class StreamReader:
assert not self._eof, '_wait_for_data after EOF'
# Waiting for data while paused will make deadlock, so prevent it.
+ # This is essential for readexactly(n) for case when n > self._limit.
if self._paused:
self._paused = False
self._transport.resume_reading()
@@ -658,25 +659,22 @@ class StreamReader:
if n == 0:
return b''
- # There used to be "optimized" code here. It created its own
- # Future and waited until self._buffer had at least the n
- # bytes, then called read(n). Unfortunately, this could pause
- # the transport if the argument was larger than the pause
- # limit (which is twice self._limit). So now we just read()
- # into a local buffer.
-
- blocks = []
- while n > 0:
- block = yield from self.read(n)
- if not block:
- partial = b''.join(blocks)
- raise IncompleteReadError(partial, len(partial) + n)
- blocks.append(block)
- n -= len(block)
-
- assert n == 0
-
- return b''.join(blocks)
+ while len(self._buffer) < n:
+ if self._eof:
+ incomplete = bytes(self._buffer)
+ self._buffer.clear()
+ raise IncompleteReadError(incomplete, n)
+
+ yield from self._wait_for_data('readexactly')
+
+ if len(self._buffer) == n:
+ data = bytes(self._buffer)
+ self._buffer.clear()
+ else:
+ data = bytes(self._buffer[:n])
+ del self._buffer[:n]
+ self._maybe_resume_transport()
+ return data
if compat.PY35:
@coroutine