diff options
-rw-r--r-- | Lib/_pyio.py | 4 | ||||
-rw-r--r-- | Lib/test/test_io.py | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 5f2e400..a2ee952 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -1667,7 +1667,9 @@ class TextIOWrapper(TextIOBase): self._snapshot = None # Restore the decoder to its state from the safe start point. - if self._decoder or dec_flags or chars_to_skip: + if cookie == 0 and self._decoder: + self._decoder.reset() + elif self._decoder or dec_flags or chars_to_skip: self._decoder = self._decoder or self._get_decoder() self._decoder.setstate((b'', dec_flags)) self._snapshot = (dec_flags, b'') diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 58f33a2..1c7d1f1 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -1706,6 +1706,8 @@ class TextIOWrapperTest(unittest.TestCase): f.write(data) f.seek(0) self.assertEquals(f.read(), data * 2) + f.seek(0) + self.assertEquals(f.read(), data * 2) self.assertEquals(buf.getvalue(), (data * 2).encode(encoding)) def test_read_one_by_one(self): |