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.
diff --git a/Lib/codecs.py b/Lib/codecs.py
index 44618cb..a70ed20 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -480,15 +480,17 @@
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()