]> granicus.if.org Git - python/commitdiff
Merged revisions 81459 via svnmerge from
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 22 May 2010 02:12:28 +0000 (02:12 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 22 May 2010 02:12:28 +0000 (02:12 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81459 | victor.stinner | 2010-05-22 04:11:07 +0200 (sam., 22 mai 2010) | 3 lines

  Issue #6268: Fix seek() method of codecs.open(), don't read the BOM twice
  after seek(0)
........

Lib/codecs.py
Lib/test/test_codecs.py
Misc/NEWS

index a67240a20fa632ff361b9db84088d1e64be5d84b..e903f2e9148b7f6a2595340216a99e0460d287e3 100644 (file)
@@ -694,6 +694,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):
 
index 7c3a30b9f44b811f3c5da841e3078388107ed42a..47b80f7f772a17f1d1d3affbb0aa0a823b45046e 100644 (file)
@@ -1488,6 +1488,26 @@ class WithStmtTest(unittest.TestCase):
             self.assertEquals(srw.read(), u"\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', 'wt+', 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():
     test_support.run_unittest(
         UTF32Test,
@@ -1516,6 +1536,7 @@ def test_main():
         BasicStrTest,
         CharmapTest,
         WithStmtTest,
+        BomTest,
     )
 
 
index a4279941242d634909e7e28e7b9780b98cfb4a49..845a41d189871f4f011bbc8e9c3a4243591cee7a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -55,6 +55,9 @@ C-API
 Library
 -------
 
+- Issue #6268: Fix seek() method of codecs.open(), don't read the BOM twice
+  after seek(0)
+
 - Issue #5640: Fix Shift-JIS incremental encoder for error handlers different
   than strict