diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-11-29 01:30:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-29 01:30:00 +0200 |
commit | 219c2de5ad0fdac825298bed1bb251f16956c04a (patch) | |
tree | 728e8ffcfecbf1bc12aefaff2dad81720058f775 /Lib/codecs.py | |
parent | 23df2d1304ece169d7e0dfc843dfb8026b413d9f (diff) | |
download | cpython-git-219c2de5ad0fdac825298bed1bb251f16956c04a.tar.gz |
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.
Diffstat (limited to 'Lib/codecs.py')
-rw-r--r-- | Lib/codecs.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py index 44618cbd2c..a70ed20f2b 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -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() |