directory.
Availability: Macintosh, \UNIX, Windows.
-\versionadded[On Windows NT/2k/XP, if \var{path} is a Unicode object,
-the result will be a list of Unicode objects.]{2.3}
+\versionadded[On Windows NT/2k/XP and Unix, if \var{path} is a Unicode
+object, the result will be a list of Unicode objects.]{2.3}
\end{funcdesc}
\begin{funcdesc}{lstat}{path}
about the rationale is in the NEWS entry for that. See also SF bug
report <http://www.python.org/sf/693121>.
-- os.listdir() now returns Unicode strings on platforms that set
- Py_FileSystemDefaultEncoding, for file names that are not representable
- in ASCII. (This currently only affects MacOS X; on Windows versions
- with wide file name support os.listdir() already returned Unicode
- strings.)
+- On Unix platforms, if os.listdir() is called with a Unicode argument,
+ it now returns Unicode strings. (This behavior was added earlier
+ to the Windows NT/2k/XP version of os.listdir().)
- Distutils: both 'py_modules' and 'packages' keywords can now be specified
in core.setup(). Previously you could supply one or the other, but
Mac
---
-- os.listdir() now may return Unicode strings on MacOS X. See the general
- news item under "Library".
+- os.listdir() now returns Unicode strings on MacOS X when called with
+ a Unicode argument. See the general news item under "Library".
- A new method MacOS.WMAvailable() returns true if it is safe to access
the window manager, false otherwise.
PyObject *d, *v;
DIR *dirp;
struct dirent *ep;
- if (!PyArg_ParseTuple(args, "s:listdir", &name))
+ int arg_is_unicode = 1;
+
+ if (!PyArg_ParseTuple(args, "U:listdir", &v)) {
+ arg_is_unicode = 0;
+ PyErr_Clear();
+ }
+ if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name))
return NULL;
if ((dirp = opendir(name)) == NULL) {
return posix_error_with_filename(name);
break;
}
#ifdef Py_USING_UNICODE
- if (Py_FileSystemDefaultEncoding != NULL) {
+ if (arg_is_unicode) {
PyObject *w;
w = PyUnicode_FromEncodedObject(v,
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) {