From 9363a65b2ceb1b9cb9b14a1711d7d2310673a0a0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 5 Mar 2009 00:42:09 +0000 Subject: fix #4862 in _pyio: reset the decoder on seek(0) --- Lib/_pyio.py | 4 +++- Lib/test/test_io.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) 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): -- cgit v0.12