summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-08-06 20:22:08 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-08-06 20:22:08 (GMT)
commitd73c31899e88aa5a1cc28f288cc70a35f2a196c2 (patch)
tree09d9688677f61aed77153f5fe93cccbf7975619b /Modules
parent43b586b951aa3232261869640d379f942d0873da (diff)
downloadcpython-d73c31899e88aa5a1cc28f288cc70a35f2a196c2.zip
cpython-d73c31899e88aa5a1cc28f288cc70a35f2a196c2.tar.gz
cpython-d73c31899e88aa5a1cc28f288cc70a35f2a196c2.tar.bz2
Issue #26800: Undocumented support of general bytes-like objects
as paths in os functions is now deprecated.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 6adc7f4..52e465f 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -891,7 +891,28 @@ path_converter(PyObject *o, void *p)
}
#endif
}
+ else if (PyBytes_Check(o)) {
+#ifdef MS_WINDOWS
+ if (win32_warn_bytes_api()) {
+ return 0;
+ }
+#endif
+ bytes = o;
+ Py_INCREF(bytes);
+ }
else if (PyObject_CheckBuffer(o)) {
+ 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, integer or None" :
+ path->allow_fd ? "string, bytes or integer" :
+ path->nullable ? "string, bytes or None" :
+ "string or bytes",
+ Py_TYPE(o)->tp_name)) {
+ return 0;
+ }
#ifdef MS_WINDOWS
if (win32_warn_bytes_api()) {
return 0;
@@ -946,8 +967,14 @@ path_converter(PyObject *o, void *p)
path->length = length;
path->object = o;
path->fd = -1;
- path->cleanup = bytes;
- return Py_CLEANUP_SUPPORTED;
+ if (bytes == o) {
+ Py_DECREF(bytes);
+ return 1;
+ }
+ else {
+ path->cleanup = bytes;
+ return Py_CLEANUP_SUPPORTED;
+ }
}
static void