fix #4862 in _pyio: reset the decoder on seek(0)

This commit is contained in:
Benjamin Peterson 2009-03-05 00:42:09 +00:00
parent 03cfa7365d
commit 9363a65b2c
2 changed files with 5 additions and 1 deletions

View File

@ -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'')

View File

@ -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):