bpo-30879: os.listdir() and os.scandir() now emit bytes names when (#2634)

called with bytes-like argument.
This commit is contained in:
Serhiy Storchaka 2017-07-11 06:36:46 +03:00 committed by GitHub
parent 4f9a446f3f
commit 1180e5a518
4 changed files with 35 additions and 6 deletions

View file

@ -1037,6 +1037,8 @@ path_converter(PyObject *o, void *p)
Py_INCREF(bytes);
}
else if (is_buffer) {
/* XXX Replace PyObject_CheckBuffer with PyBytes_Check in other code
after removing suport of non-bytes buffer objects. */
if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
"%s%s%s should be %s, not %.200s",
path->function_name ? path->function_name : "",
@ -3588,8 +3590,8 @@ _posix_listdir(path_t *path, PyObject *list)
const char *name;
if (path->narrow) {
name = path->narrow;
/* only return bytes if they specified a bytes object */
return_str = !(PyBytes_Check(path->object));
/* only return bytes if they specified a bytes-like object */
return_str = !PyObject_CheckBuffer(path->object);
}
else {
name = ".";
@ -11842,7 +11844,7 @@ DirEntry_from_posix_info(path_t *path, const char *name, Py_ssize_t name_len,
goto error;
}
if (!path->narrow || !PyBytes_Check(path->object)) {
if (!path->narrow || !PyObject_CheckBuffer(path->object)) {
entry->name = PyUnicode_DecodeFSDefaultAndSize(name, name_len);
if (joined_path)
entry->path = PyUnicode_DecodeFSDefault(joined_path);