mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
bpo-32110: codecs.StreamReader.read(n) now returns not more than n (#4499)
characters/bytes for non-negative n. This makes it compatible with read() methods of other file-like objects.
This commit is contained in:
parent
23df2d1304
commit
219c2de5ad
3 changed files with 24 additions and 5 deletions
|
@ -480,15 +480,17 @@ class StreamReader(Codec):
|
|||
self.charbuffer = self._empty_charbuffer.join(self.linebuffer)
|
||||
self.linebuffer = None
|
||||
|
||||
if chars < 0:
|
||||
# For compatibility with other read() methods that take a
|
||||
# single argument
|
||||
chars = size
|
||||
|
||||
# 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 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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue