diff Objects/methodobject.c @ 48415:bd2334120a30

Oops, forgot that there are modules outside the win32 world.
author Amaury Forgeot d'Arc <amauryfa@gmail.com>
date Wed, 02 Jul 2008 21:47:18 +0000
parents 4025f638911f
children aa1fbe321acf
line wrap: on
line diff
--- a/Objects/methodobject.c	Wed Jul 02 21:41:01 2008 +0000
+++ b/Objects/methodobject.c	Wed Jul 02 21:47:18 2008 +0000
@@ -280,6 +280,43 @@
 	0,					/* tp_dict */
 };
 
+/* Find a method in a method chain */
+
+PyObject *
+Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name)
+{
+	if (name[0] == '_' && name[1] == '_') {
+		if (strcmp(name, "__doc__") == 0) {
+			const char *doc = self->ob_type->tp_doc;
+			if (doc != NULL)
+				return PyUnicode_FromString(doc);
+		}
+	}
+	while (chain != NULL) {
+		PyMethodDef *ml = chain->methods;
+		for (; ml->ml_name != NULL; ml++) {
+			if (name[0] == ml->ml_name[0] &&
+			    strcmp(name+1, ml->ml_name+1) == 0)
+				/* XXX */
+				return PyCFunction_New(ml, self);
+		}
+		chain = chain->link;
+	}
+	PyErr_SetString(PyExc_AttributeError, name);
+	return NULL;
+}
+
+/* Find a method in a single method list */
+
+PyObject *
+Py_FindMethod(PyMethodDef *methods, PyObject *self, const char *name)
+{
+	PyMethodChain chain;
+	chain.methods = methods;
+	chain.link = NULL;
+	return Py_FindMethodInChain(&chain, self, name);
+}
+
 /* Clear out the free list */
 
 int