summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-10-18 15:52:31 (GMT)
committerGitHub <noreply@github.com>2022-10-18 15:52:31 (GMT)
commitdb03c8066a6b12fa23618f9add0eb795936726b4 (patch)
tree71d35cac37736188bbe8b046aab657b0892be1de /Modules/posixmodule.c
parent9da5215000920870eeddd78af92da4c98099706c (diff)
downloadcpython-db03c8066a6b12fa23618f9add0eb795936726b4.zip
cpython-db03c8066a6b12fa23618f9add0eb795936726b4.tar.gz
cpython-db03c8066a6b12fa23618f9add0eb795936726b4.tar.bz2
gh-98393: os module reject bytes-like, only accept bytes (#98394)
The os module and the PyUnicode_FSDecoder() function no longer accept bytes-like paths, like bytearray and memoryview types: only the exact bytes type is accepted for bytes strings.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c32
1 files changed, 5 insertions, 27 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 1e556fc..39198cb 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1120,7 +1120,7 @@ path_converter(PyObject *o, void *p)
path_t *path = (path_t *)p;
PyObject *bytes = NULL;
Py_ssize_t length = 0;
- int is_index, is_buffer, is_bytes, is_unicode;
+ int is_index, is_bytes, is_unicode;
const char *narrow;
#ifdef MS_WINDOWS
PyObject *wo = NULL;
@@ -1158,11 +1158,10 @@ path_converter(PyObject *o, void *p)
/* Only call this here so that we don't treat the return value of
os.fspath() as an fd or buffer. */
is_index = path->allow_fd && PyIndex_Check(o);
- is_buffer = PyObject_CheckBuffer(o);
is_bytes = PyBytes_Check(o);
is_unicode = PyUnicode_Check(o);
- if (!is_index && !is_buffer && !is_unicode && !is_bytes) {
+ if (!is_index && !is_unicode && !is_bytes) {
/* Inline PyOS_FSPath() for better error messages. */
PyObject *func, *res;
@@ -1225,27 +1224,6 @@ path_converter(PyObject *o, void *p)
bytes = o;
Py_INCREF(bytes);
}
- else if (is_buffer) {
- /* XXX Replace PyObject_CheckBuffer with PyBytes_Check in other code
- after removing support 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 : "",
- path->function_name ? ": " : "",
- path->argument_name ? path->argument_name : "path",
- path->allow_fd && path->nullable ? "string, bytes, os.PathLike, "
- "integer or None" :
- path->allow_fd ? "string, bytes, os.PathLike or integer" :
- path->nullable ? "string, bytes, os.PathLike or None" :
- "string, bytes or os.PathLike",
- _PyType_Name(Py_TYPE(o)))) {
- goto error_exit;
- }
- bytes = PyBytes_FromObject(o);
- if (!bytes) {
- goto error_exit;
- }
- }
else if (is_index) {
if (!_fd_converter(o, &path->fd)) {
goto error_exit;
@@ -4126,8 +4104,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-like object */
- return_str = !PyObject_CheckBuffer(path->object);
+ /* only return bytes if they specified a bytes object */
+ return_str = !PyBytes_Check(path->object);
}
else {
name = ".";
@@ -14049,7 +14027,7 @@ DirEntry_from_posix_info(PyObject *module, path_t *path, const char *name,
goto error;
}
- if (!path->narrow || !PyObject_CheckBuffer(path->object)) {
+ if (!path->narrow || !PyBytes_Check(path->object)) {
entry->name = PyUnicode_DecodeFSDefaultAndSize(name, name_len);
if (joined_path)
entry->path = PyUnicode_DecodeFSDefault(joined_path);