summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-08 10:47:50 (GMT)
committerGitHub <noreply@github.com>2024-01-08 10:47:50 (GMT)
commit4db8d3be49b3a229932a24f6271d3f062843d08f (patch)
tree84979a161808c217c0622fe1076a7788f23f0242 /Lib/_pyio.py
parent320c160b1ace14be54f63b580af7adabe6b34a97 (diff)
downloadcpython-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.py10
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.