]> granicus.if.org Git - python/commitdiff
Issue #9644: Fix the encoding used by os.statvfs(): use the filesystem encoding
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 1 Jan 2013 22:05:55 +0000 (23:05 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 1 Jan 2013 22:05:55 +0000 (23:05 +0100)
with the surrogateescape error handler, instead of UTF-8 in strict mode.

Lib/test/test_os.py
Misc/NEWS
Modules/posixmodule.c

index 5b67da17baa8b1e38ad0033c85fe700c6fb6be1b..bd799b2040d8540ee83408c98d351544aac808f1 100644 (file)
@@ -1057,6 +1057,15 @@ if sys.platform != 'win32':
                 f = open(os.path.join(self.dir, fn), 'rb')
                 f.close()
 
+        @unittest.skipUnless(hasattr(os, 'statvfs'),
+                             "need os.statvfs()")
+        def test_statvfs(self):
+            # issue #9645
+            for fn in self.unicodefn:
+                # should not fail with file not found error
+                fullname = os.path.join(self.dir, fn)
+                os.statvfs(fullname)
+
         def test_stat(self):
             for fn in self.unicodefn:
                 os.stat(os.path.join(self.dir, fn))
index b9b14a79ba63077fd92c5aa04d0f37102f964995..45c2e32125674d1de55dc18f58567c1c1bded74c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -189,6 +189,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #9644: Fix the encoding used by os.statvfs(): use the filesystem
+  encoding with the surrogateescape error handler, instead of UTF-8 in strict
+  mode.
+
 - Issue #16819: IDLE method completion now correctly works for bytes literals.
 
 - Issue #9586: Redefine SEM_FAILED on MacOSX to keep compiler happy.
index 0d2919b84e0e2db025f53019e1a5df2c6aa07fd6..e7e530589cffd54ff82d623c16265347050c8ea3 100644 (file)
@@ -6463,18 +6463,22 @@ Perform a statvfs system call on the given path.");
 static PyObject *
 posix_statvfs(PyObject *self, PyObject *args)
 {
+    PyObject *opath, *result = NULL;
     char *path;
     int res;
     struct statvfs st;
-    if (!PyArg_ParseTuple(args, "s:statvfs", &path))
+    if (!PyArg_ParseTuple(args, "O&:statvfs", PyUnicode_FSConverter, &opath))
         return NULL;
+    path = PyBytes_AS_STRING(opath);
     Py_BEGIN_ALLOW_THREADS
     res = statvfs(path, &st);
     Py_END_ALLOW_THREADS
     if (res != 0)
-        return posix_error_with_filename(path);
+        return posix_error_with_allocated_filename(opath);
 
-    return _pystatvfs_fromstructstatvfs(st);
+    result = _pystatvfs_fromstructstatvfs(st);
+    Py_DECREF(opath);
+    return result;
 }
 #endif /* HAVE_STATVFS */