mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Patch #683592: unicode support for os.listdir()
os.listdir() may now return unicode strings on platforms that set Py_FileSystemDefaultEncoding.
This commit is contained in:
parent
4983331385
commit
46c9784f68
2 changed files with 32 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue