Author: guido.van.rossum
Date: Wed Aug  8 01:29:20 2007
New Revision: 56814

Modified:
   python/branches/py3k-struni/Lib/test/test_bz2.py
   python/branches/py3k-struni/Modules/bz2module.c
Log:
BZ2File.read(0) should return b"" rather than raising ValueError.
This fixes test_tarfile.py.
I've added a unit test for the correct bz2 behavior.


Modified: python/branches/py3k-struni/Lib/test/test_bz2.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_bz2.py    (original)
+++ python/branches/py3k-struni/Lib/test/test_bz2.py    Wed Aug  8 01:29:20 2007
@@ -65,6 +65,14 @@
         self.assertEqual(bz2f.read(), self.TEXT)
         bz2f.close()
 
+    def testRead0(self):
+        # Test BBZ2File.read(0)"
+        self.createTempFile()
+        bz2f = BZ2File(self.filename)
+        self.assertRaises(TypeError, bz2f.read, None)
+        self.assertEqual(bz2f.read(0), b"")
+        bz2f.close()
+
     def testReadChunk10(self):
         # "Test BZ2File.read() in chunks of 10 bytes"
         self.createTempFile()

Modified: python/branches/py3k-struni/Modules/bz2module.c
==============================================================================
--- python/branches/py3k-struni/Modules/bz2module.c     (original)
+++ python/branches/py3k-struni/Modules/bz2module.c     Wed Aug  8 01:29:20 2007
@@ -431,7 +431,7 @@
                goto cleanup;
        }
        ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
-       if (ret == NULL)
+       if (ret == NULL || buffersize == 0)
                goto cleanup;
        bytesread = 0;
 
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to