]> granicus.if.org Git - python/commitdiff
Bug #1194181: bz2.BZ2File didn't handle mode 'U' correctly.
authorGeorg Brandl <georg@python.org>
Fri, 3 Jun 2005 19:47:00 +0000 (19:47 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 3 Jun 2005 19:47:00 +0000 (19:47 +0000)
Lib/test/test_bz2.py
Misc/NEWS
Modules/bz2module.c

index 7d844d8e835888c9e2870e59a4640ea5e2e9459f..fc8213f55a6107ef7c89fb86922c4fe5c148c2ce 100644 (file)
@@ -235,6 +235,16 @@ class BZ2FileTest(BaseTest):
         # "Test opening a nonexistent file"
         self.assertRaises(IOError, BZ2File, "/non/existent")
 
+    def testModeU(self):
+        # Bug #1194181: bz2.BZ2File opened for write with mode "U"
+        self.createTempFile()
+        bz2f = BZ2File(self.filename, "U")
+        bz2f.close()
+        f = file(self.filename)
+        f.seek(0, 2)
+        self.assertEqual(f.tell(), len(self.DATA))
+        f.close()
+
 class BZ2CompressorTest(BaseTest):
     def testCompress(self):
         # "Test BZ2Compressor.compress()/flush()"
index 67ccb426370b65a2b37bc5c87ac00dbbdd5ffc8a..637ca2eb130ae91a8d1040a7ac731387b7521a62 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -91,6 +91,8 @@ Core and builtins
 Extension Modules
 -----------------
 
+- Bug #1194181: bz2.BZ2File didn't handle mode 'U' correctly.
+
 - Patch #1212117: os.stat().st_flags is now accessible as a attribute
   if available on the platform.
 
index 8a93cd9547bc047abde0e920da068faf7587eb50..b9874eb07e8949c0ef5e8c4db2b3be8e25d1c7c8 100644 (file)
@@ -1308,6 +1308,10 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
                        break;
        }
 
+       if (mode_char == 0) {
+               mode_char = 'r';
+       }
+
        mode = (mode_char == 'r') ? "rb" : "wb";
 
        self->file = PyObject_CallFunction((PyObject*)&PyFile_Type, "(Osi)",