[Python-checkins] cpython (3.2): Issue #9644: Fix the encoding used by os.statvfs(): use the filesystem encoding
victor.stinner
python-checkins at python.org
Tue Jan 1 23:13:17 CET 2013
http://hg.python.org/cpython/rev/479fca0adbf6
changeset: 81207:479fca0adbf6
branch: 3.2
parent: 81202:99a06886b258
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jan 01 23:05:55 2013 +0100
summary:
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.
files:
Lib/test/test_os.py | 9 +++++++++
Misc/NEWS | 4 ++++
Modules/posixmodule.c | 14 +++++++++-----
3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -1057,6 +1057,15 @@
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))
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -189,6 +189,10 @@
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.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6463,18 +6463,22 @@
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))
- return NULL;
+ 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 _pystatvfs_fromstructstatvfs(st);
+ return posix_error_with_allocated_filename(opath);
+
+ result = _pystatvfs_fromstructstatvfs(st);
+ Py_DECREF(opath);
+ return result;
}
#endif /* HAVE_STATVFS */
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list