Index: Modules/posixmodule.c =================================================================== --- Modules/posixmodule.c (Revision 64203) +++ Modules/posixmodule.c (Arbeitskopie) @@ -1192,6 +1192,42 @@ 10 }; + +static PyObject * +stat_result_isdir(PyStructSequence *self, PyObject *unused) +{ + PyObject *mode = self->ob_item[0]; + if (!PyLong_Check(mode)) { + Py_RETURN_FALSE; + } + return PyBool_FromLong(S_ISDIR(PyLong_AS_LONG(mode))); +} + +static PyMethodDef stat_result_methods[] = { + {"isdir", (PyCFunction)stat_result_isdir, METH_NOARGS, NULL}, + {NULL, NULL} +}; + + +/* Adapted from typeobject.c, used to add methods to a struct sequence. */ +static int +add_methods_to_type(PyTypeObject *type, PyMethodDef *meth) +{ + PyObject *dict = type->tp_dict; + + for (; meth->ml_name != NULL; meth++) { + PyObject *descr; + descr = PyDescr_NewMethod(type, meth); + if (descr == NULL) + return -1; + if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0) + return -1; + Py_DECREF(descr); + } + return 0; +} + + PyDoc_STRVAR(statvfs_result__doc__, "statvfs_result: Result from statvfs or fstatvfs.\n\n\ This object may be accessed either as a tuple of\n\ @@ -7389,6 +7425,7 @@ PyStructSequence_InitType(&StatResultType, &stat_result_desc); structseq_new = StatResultType.tp_new; StatResultType.tp_new = statresult_new; + add_methods_to_type(&StatResultType, stat_result_methods); statvfs_result_desc.name = MODNAME ".statvfs_result"; PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);