[Python-checkins] r69646 - in python/branches/io-c: Lib/test/test_fileio.py Modules/_fileio.c

antoine.pitrou python-checkins at python.org
Sun Feb 15 20:14:42 CET 2009


Author: antoine.pitrou
Date: Sun Feb 15 20:14:42 2009
New Revision: 69646

Log:
Fix opening of 8-bit filenames with FileIO



Modified:
   python/branches/io-c/Lib/test/test_fileio.py
   python/branches/io-c/Modules/_fileio.c

Modified: python/branches/io-c/Lib/test/test_fileio.py
==============================================================================
--- python/branches/io-c/Lib/test/test_fileio.py	(original)
+++ python/branches/io-c/Lib/test/test_fileio.py	Sun Feb 15 20:14:42 2009
@@ -176,6 +176,22 @@
         f.close()
         os.unlink(TESTFN)
 
+    def testBytesOpen(self):
+        # Opening a bytes filename
+        try:
+            fn = TESTFN.encode("ascii")
+        except UnicodeEncodeError:
+            # Skip test
+            return
+        f = _FileIO(fn, "w")
+        try:
+            f.write(b"abc")
+            f.close()
+            with open(TESTFN, "rb") as f:
+                self.assertEquals(f.read(), b"abc")
+        finally:
+            os.unlink(TESTFN)
+
     def testInvalidFd(self):
         self.assertRaises(ValueError, _FileIO, -10)
         self.assertRaises(OSError, _FileIO, make_bad_fd())

Modified: python/branches/io-c/Modules/_fileio.c
==============================================================================
--- python/branches/io-c/Modules/_fileio.c	(original)
+++ python/branches/io-c/Modules/_fileio.c	Sun Feb 15 20:14:42 2009
@@ -228,7 +228,8 @@
 	if (fd < 0)
 	{
 		if (PyBytes_Check(nameobj) || PyByteArray_Check(nameobj)) {
-			if (PyObject_AsCharBuffer(nameobj, &name, NULL) < 0)
+			Py_ssize_t namelen;
+			if (PyObject_AsCharBuffer(nameobj, &name, &namelen) < 0)
 				return -1;
 		}
 		else {


More information about the Python-checkins mailing list