mirror of
https://github.com/python/cpython.git
synced 2025-07-27 21:24:32 +00:00
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.
This commit is contained in:
parent
714d7ffd0d
commit
8003850e22
3 changed files with 44 additions and 9 deletions
|
@ -463,15 +463,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()
|
||||
|
@ -479,6 +476,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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue