summaryrefslogtreecommitdiff
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-09-18 11:28:51 +0300
committerGitHub <noreply@github.com>2018-09-18 11:28:51 +0300
commit0185f34ddcf07b78feb6ac666fbfd4615d26b028 (patch)
treea27f02f0095d5a7fb1fcbd539114b3a74fb4fcc7 /Modules/posixmodule.c
parent7bdf28265aa371b39f82dfc6562635801aff15a5 (diff)
downloadcpython-git-0185f34ddcf07b78feb6ac666fbfd4615d26b028.tar.gz
bpo-33721: Make some os.path functions and pathlib.Path methods be tolerant to invalid paths. (#7695)
Such functions as os.path.exists(), os.path.lexists(), os.path.isdir(), os.path.isfile(), os.path.islink(), and os.path.ismount() now return False instead of raising ValueError or its subclasses UnicodeEncodeError and UnicodeDecodeError for paths that contain characters or bytes unrepresentative at the OS level.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 53d2ce2243..400ed97982 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -3821,22 +3821,32 @@ cleanup:
/*[clinic input]
os._isdir
- path: path_t
+ path as arg: object
/
Return true if the pathname refers to an existing directory.
[clinic start generated code]*/
static PyObject *
-os__isdir_impl(PyObject *module, path_t *path)
-/*[clinic end generated code: output=75f56f32720836cb input=5e0800149c0ad95f]*/
+os__isdir(PyObject *module, PyObject *arg)
+/*[clinic end generated code: output=404f334d85d4bf25 input=36cb6785874d479e]*/
{
DWORD attributes;
+ path_t path = PATH_T_INITIALIZE("_isdir", "path", 0, 0);
+
+ if (!path_converter(arg, &path)) {
+ if (PyErr_ExceptionMatches(PyExc_ValueError)) {
+ PyErr_Clear();
+ Py_RETURN_FALSE;
+ }
+ return NULL;
+ }
Py_BEGIN_ALLOW_THREADS
- attributes = GetFileAttributesW(path->wide);
+ attributes = GetFileAttributesW(path.wide);
Py_END_ALLOW_THREADS
+ path_cleanup(&path);
if (attributes == INVALID_FILE_ATTRIBUTES)
Py_RETURN_FALSE;