diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-11-29 00:06:53 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-11-29 00:06:53 (GMT) |
commit | 230ffeae0a3961b1769806bd722c26227c84e8da (patch) | |
tree | 3e6abd02148b0409eabc4dfe50b9ee2ddb03e070 /Lib/codecs.py | |
parent | 6979fcdc91114b1ccb16345e26734d6df4cccbc3 (diff) | |
download | cpython-230ffeae0a3961b1769806bd722c26227c84e8da.zip cpython-230ffeae0a3961b1769806bd722c26227c84e8da.tar.gz cpython-230ffeae0a3961b1769806bd722c26227c84e8da.tar.bz2 |
bpo-32110: codecs.StreamReader.read(n) now returns not more than n (GH-4499) (#4622)
characters/bytes for non-negative n. This makes it compatible with
read() methods of other file-like objects.
(cherry picked from commit 219c2de5ad0fdac825298bed1bb251f16956c04a)
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 39ec845..fd6c6f5 100644 --- a/Lib/codecs.py +++ b/Lib/codecs.py @@ -479,15 +479,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() |