summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-03-05 00:42:09 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-03-05 00:42:09 (GMT)
commit9363a65b2ceb1b9cb9b14a1711d7d2310673a0a0 (patch)
treea399a6f732273464722a00629b70ad5794d8ebb8 /Lib
parent03cfa7365d7fc7c1020aab3845e49356f961f767 (diff)
downloadcpython-9363a65b2ceb1b9cb9b14a1711d7d2310673a0a0.zip
cpython-9363a65b2ceb1b9cb9b14a1711d7d2310673a0a0.tar.gz
cpython-9363a65b2ceb1b9cb9b14a1711d7d2310673a0a0.tar.bz2
fix #4862 in _pyio: reset the decoder on seek(0)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/_pyio.py4
-rw-r--r--Lib/test/test_io.py2
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):