summaryrefslogtreecommitdiffstats
path: root/Lib/codecs.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-26 17:27:56 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-26 17:27:56 (GMT)
commitdbe0982bc515cb1a881d4bf7728d265e58803bf0 (patch)
treeb2d664e02a4fe763adc7b4d808ed18169551db69 /Lib/codecs.py
parent0742cae3357fcd7c41498b21060050e7cca788b1 (diff)
downloadcpython-dbe0982bc515cb1a881d4bf7728d265e58803bf0.zip
cpython-dbe0982bc515cb1a881d4bf7728d265e58803bf0.tar.gz
cpython-dbe0982bc515cb1a881d4bf7728d265e58803bf0.tar.bz2
Issue #8260: The read(), readline() and readlines() methods of
codecs.StreamReader returned incomplete data when were called after readline() or read(size). Based on patch by Amaury Forgeot d'Arc.
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r--Lib/codecs.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index 2e2e755..c2065da 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -475,15 +475,12 @@ class StreamReader(Codec):
# read until we get the required number of characters (if available)
while True:
# can the request be satisfied from the character buffer?
- if chars < 0:
- if size < 0:
- if self.charbuffer:
- break
- elif len(self.charbuffer) >= size:
- break
- else:
+ if chars >= 0:
if len(self.charbuffer) >= chars:
break
+ elif size >= 0:
+ if len(self.charbuffer) >= size:
+ break
# we need more data
if size < 0:
newdata = self.stream.read()
@@ -491,6 +488,8 @@ class StreamReader(Codec):
newdata = self.stream.read(size)
# decode bytes (those remaining from the last call included)
data = self.bytebuffer + newdata
+ if not data:
+ break
try:
newchars, decodedbytes = self.decode(data, self.errors)
except UnicodeDecodeError as exc: