[Python-checkins] r81460 - in python/branches/release26-maint: Lib/codecs.py Lib/test/test_codecs.py Misc/NEWS

victor.stinner python-checkins at python.org
Sat May 22 04:12:29 CEST 2010


Author: victor.stinner
Date: Sat May 22 04:12:28 2010
New Revision: 81460

Log:
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)
........


Modified:
   python/branches/release26-maint/   (props changed)
   python/branches/release26-maint/Lib/codecs.py
   python/branches/release26-maint/Lib/test/test_codecs.py
   python/branches/release26-maint/Misc/NEWS

Modified: python/branches/release26-maint/Lib/codecs.py
==============================================================================
--- python/branches/release26-maint/Lib/codecs.py	(original)
+++ python/branches/release26-maint/Lib/codecs.py	Sat May 22 04:12:28 2010
@@ -694,6 +694,10 @@
         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):
 

Modified: python/branches/release26-maint/Lib/test/test_codecs.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_codecs.py	(original)
+++ python/branches/release26-maint/Lib/test/test_codecs.py	Sat May 22 04:12:28 2010
@@ -1488,6 +1488,26 @@
             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 @@
         BasicStrTest,
         CharmapTest,
         WithStmtTest,
+        BomTest,
     )
 
 

Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Sat May 22 04:12:28 2010
@@ -55,6 +55,9 @@
 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
 


More information about the Python-checkins mailing list