diff options
author | Just van Rossum <just@letterror.com> | 2003-02-25 21:42:15 (GMT) |
---|---|---|
committer | Just van Rossum <just@letterror.com> | 2003-02-25 21:42:15 (GMT) |
commit | 46c9784f68a8dbb4f13fa86ac780c45a4363b8a8 (patch) | |
tree | c52f1d1b5b66057eb089165f4639dc0038ac17a0 /Modules | |
parent | 49833313855e1c7aec9c6654e81c416329298a49 (diff) | |
download | cpython-46c9784f68a8dbb4f13fa86ac780c45a4363b8a8.zip cpython-46c9784f68a8dbb4f13fa86ac780c45a4363b8a8.tar.gz cpython-46c9784f68a8dbb4f13fa86ac780c45a4363b8a8.tar.bz2 |
Patch #683592: unicode support for os.listdir()
os.listdir() may now return unicode strings on platforms that set
Py_FileSystemDefaultEncoding.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/posixmodule.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d203378..482bba9 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1795,6 +1795,30 @@ posix_listdir(PyObject *self, PyObject *args) d = NULL; break; } +#ifdef Py_USING_UNICODE + if (Py_FileSystemDefaultEncoding != NULL) { + PyObject *w; + + w = PyUnicode_FromEncodedObject(v, + Py_FileSystemDefaultEncoding, + "strict"); + Py_DECREF(v); + v = w; + if (v == NULL) { + Py_DECREF(d); + d = NULL; + break; + } + /* attempt to convert to ASCII */ + w = PyUnicode_AsASCIIString(v); + if (w != NULL) { + Py_DECREF(v); + v = w; + } + else + PyErr_Clear(); + } +#endif if (PyList_Append(d, v) != 0) { Py_DECREF(v); Py_DECREF(d); |