summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-08-06 23:22:08 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-08-06 23:22:08 +0300
commitbb2540a70ca8864f8c62210872762fc7d0cc3a01 (patch)
treec0b562af15aa540c27c0db83f86f9d9b232681ee /Modules
parentcbf6e43aee1d51d829f24dc8793106bdcf534b3f (diff)
downloadcpython-bb2540a70ca8864f8c62210872762fc7d0cc3a01.tar.gz
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 6adc7f44db..52e465f1ff 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