Issue #6268: More bugfixes about BOM, UTF-16 and UTF-32
* Fix seek() method of codecs.open(), don't write the BOM twice after seek(0)
* Fix reset() method of codecs, UTF-16, UTF-32 and StreamWriter classes
* test_codecs: use "w+" mode instead of "wt+". "t" mode is not supported by
Solaris or Windows, but does it really exist? I found it the in the issue.
diff --git a/Lib/codecs.py b/Lib/codecs.py
index e903f2e..f4cd60a 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -370,6 +370,11 @@
"""
pass
+ def seek(self, offset, whence=0):
+ self.stream.seek(offset, whence)
+ if whence == 0 and offset == 0:
+ self.reset()
+
def __getattr__(self, name,
getattr=getattr):
@@ -601,8 +606,8 @@
Resets the codec buffers used for keeping state.
"""
- self.reset()
self.stream.seek(offset, whence)
+ self.reset()
def next(self):
@@ -695,8 +700,10 @@
self.writer.reset()
def seek(self, offset, whence=0):
- self.reader.seek(offset, whence)
- self.writer.seek(offset, whence)
+ self.stream.seek(offset, whence)
+ self.reader.reset()
+ if whence == 0 and offset == 0:
+ self.writer.reset()
def __getattr__(self, name,
getattr=getattr):