summaryrefslogtreecommitdiff
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorBrian Curtin <brian@python.org>2011-06-13 16:10:32 -0500
committerBrian Curtin <brian@python.org>2011-06-13 16:10:32 -0500
commita87d586fd6c4a5dfe4ea89fda288ae8eb66b0134 (patch)
tree420fe483c679d2225cc8bd82eefaecf783999268 /Modules/posixmodule.c
parentd25aef55c8b0025dd2ee7de11b526f34ceed6b66 (diff)
parentcdc751720ee7a13ac163da1eedf3a513386c98d4 (diff)
downloadcpython-git-a87d586fd6c4a5dfe4ea89fda288ae8eb66b0134.tar.gz
branch merge?
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 674eeb2920..b6f49b81e6 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2866,6 +2866,45 @@ posix__getfileinformation(PyObject *self, PyObject *args)
info.nFileIndexHigh,
info.nFileIndexLow);
}
+
+PyDoc_STRVAR(posix__isdir__doc__,
+"Return true if the pathname refers to an existing directory.");
+
+static PyObject *
+posix__isdir(PyObject *self, PyObject *args)
+{
+ PyObject *opath;
+ char *path;
+ PyUnicodeObject *po;
+ DWORD attributes;
+
+ if (PyArg_ParseTuple(args, "U|:_isdir", &po)) {
+ Py_UNICODE *wpath = PyUnicode_AS_UNICODE(po);
+
+ attributes = GetFileAttributesW(wpath);
+ if (attributes == INVALID_FILE_ATTRIBUTES)
+ Py_RETURN_FALSE;
+ goto check;
+ }
+ /* Drop the argument parsing error as narrow strings
+ are also valid. */
+ PyErr_Clear();
+
+ if (!PyArg_ParseTuple(args, "O&:_isdir",
+ PyUnicode_FSConverter, &opath))
+ return NULL;
+
+ path = PyBytes_AsString(opath);
+ attributes = GetFileAttributesA(path);
+ if (attributes == INVALID_FILE_ATTRIBUTES)
+ Py_RETURN_FALSE;
+
+check:
+ if (attributes & FILE_ATTRIBUTE_DIRECTORY)
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
#endif /* MS_WINDOWS */
PyDoc_STRVAR(posix_mkdir__doc__,
@@ -8102,6 +8141,7 @@ static PyMethodDef posix_methods[] = {
{"_getfullpathname", posix__getfullpathname, METH_VARARGS, NULL},
{"_getfinalpathname", posix__getfinalpathname, METH_VARARGS, NULL},
{"_getfileinformation", posix__getfileinformation, METH_VARARGS, NULL},
+ {"_isdir", posix__isdir, METH_VARARGS, posix__isdir__doc__},
#endif
#ifdef HAVE_GETLOADAVG
{"getloadavg", posix_getloadavg, METH_NOARGS, posix_getloadavg__doc__},