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

................
  r81461 | victor.stinner | 2010-05-22 04:16:27 +0200 (sam., 22 mai 2010) | 10 lines

  Merged revisions 81459 via svnmerge from
  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 f05c4f7e2db4c18c5b0db16654642586301b2316..9490602ad3c8520afb0b861f6989b8847b37933b 100644 (file)
@@ -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):
 
index 227e37513f5a0a3410b2171b04931ead6b4c6c39..13165723739480fe431f204814570c57b1710415 100644 (file)
@@ -1592,6 +1592,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,
@@ -1619,6 +1639,7 @@ def test_main():
         WithStmtTest,
         TypesTest,
         SurrogateEscapeTest,
+        BomTest,
     )
 
 
index 32f188c6cacc2dee378b76994a5cd3771c01d96f..54ebf596d7fcec1a467f755212dc1e529ea65d0b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -54,6 +54,9 @@ C-API
 Library
 -------
 
+- Issue #6268: Fix seek() method of codecs.open(), don't read the BOM twice
+  after seek(0)
+
 - Issue #8782: Add a trailing newline in linecache.updatecache to the last line
   of files without one.