mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-80109: Fix io.TextIOWrapper dropping the internal buffer during write() (GH-22535)
io.TextIOWrapper was dropping the internal decoding buffer during read() and write() calls.
This commit is contained in:
parent
e5d0316f35
commit
73c9326563
4 changed files with 24 additions and 8 deletions
10
Lib/_pyio.py
10
Lib/_pyio.py
|
@ -2198,8 +2198,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
|
||||
|
@ -2513,8 +2514,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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue