diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-01-08 10:47:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-08 10:47:50 (GMT) |
commit | 4db8d3be49b3a229932a24f6271d3f062843d08f (patch) | |
tree | 84979a161808c217c0622fe1076a7788f23f0242 /Lib/_pyio.py | |
parent | 320c160b1ace14be54f63b580af7adabe6b34a97 (diff) | |
download | cpython-4db8d3be49b3a229932a24f6271d3f062843d08f.zip cpython-4db8d3be49b3a229932a24f6271d3f062843d08f.tar.gz cpython-4db8d3be49b3a229932a24f6271d3f062843d08f.tar.bz2 |
[3.11] gh-80109: Fix io.TextIOWrapper dropping the internal buffer during write() (GH-22535) (GH-113809)
io.TextIOWrapper was dropping the internal decoding buffer
during read() and write() calls.
(cherry picked from commit 73c93265634257b1488262097e024c1727260cfd)
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 0bfdeaa..16d025b 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -2224,8 +2224,9 @@ class TextIOWrapper(TextIOBase): self.buffer.write(b) if self._line_buffering and (haslf or "\r" in s): self.flush() - self._set_decoded_chars('') - self._snapshot = None + if self._snapshot is not None: + self._set_decoded_chars('') + self._snapshot = None if self._decoder: self._decoder.reset() return length @@ -2539,8 +2540,9 @@ class TextIOWrapper(TextIOBase): # Read everything. result = (self._get_decoded_chars() + decoder.decode(self.buffer.read(), final=True)) - self._set_decoded_chars('') - self._snapshot = None + if self._snapshot is not None: + self._set_decoded_chars('') + self._snapshot = None return result else: # Keep reading chunks until we have size characters to return. |