summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/codecs.py4
-rw-r--r--Lib/test/test_codecs.py21
-rw-r--r--Misc/NEWS3
3 files changed, 28 insertions, 0 deletions
diff --git a/Lib/codecs.py b/Lib/codecs.py
index f05c4f7..9490602 100644
--- a/Lib/codecs.py
+++ b/Lib/codecs.py
@@ -699,6 +699,10 @@ class StreamReaderWriter:
self.reader.reset()
self.writer.reset()
+ def seek(self, offset, whence=0):
+ self.reader.seek(offset, whence)
+ self.writer.seek(offset, whence)
+
def __getattr__(self, name,
getattr=getattr):
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index b17cded..6e7afc4 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -1594,6 +1594,26 @@ class SurrogateEscapeTest(unittest.TestCase):
b"\xe4\xeb\xef\xf6\xfc")
+class BomTest(unittest.TestCase):
+ def test_seek0(self):
+ data = "1234567890"
+ tests = ("utf-16",
+ "utf-16-le",
+ "utf-16-be",
+ "utf-32",
+ "utf-32-le",
+ "utf-32-be")
+ for encoding in tests:
+ with codecs.open('foo', 'w+', encoding=encoding) as f:
+ # Check if the BOM is written only once
+ f.write(data)
+ f.write(data)
+ f.seek(0)
+ self.assertEquals(f.read(), data * 2)
+ f.seek(0)
+ self.assertEquals(f.read(), data * 2)
+
+
def test_main():
support.run_unittest(
UTF32Test,
@@ -1621,6 +1641,7 @@ def test_main():
WithStmtTest,
TypesTest,
SurrogateEscapeTest,
+ BomTest,
)
diff --git a/Misc/NEWS b/Misc/NEWS
index 7c2cc5d..58c2785 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -393,6 +393,9 @@ C-API
Library
-------
+- Issue #6268: Fix seek() method of codecs.open(), don't read the BOM twice
+ after seek(0)
+
- Issue #3798: sys.exit(message) writes the message to sys.stderr file, instead
of the C file stderr, to use stderr encoding and error handler