summaryrefslogtreecommitdiff
path: root/Modules/_testcapimodule.c
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-12-28 08:34:58 +0000
committerGeorg Brandl <georg@python.org>2009-12-28 08:34:58 +0000
commit740cdc3a9f9593ee1fe86d751c70b8505d6a19c9 (patch)
tree4c34f7bec409dfb040cba93c2064b37bb71b2b95 /Modules/_testcapimodule.c
parent02e7dfde639498064b137be7cb850c4229f0c8fb (diff)
downloadcpython-git-740cdc3a9f9593ee1fe86d751c70b8505d6a19c9.tar.gz
#7033: add new API function PyErr_NewExceptionWithDoc, for easily giving new exceptions a docstring.
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r--Modules/_testcapimodule.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index c8f2087390..f0dd75e0a5 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -1198,6 +1198,26 @@ code_newempty(PyObject *self, PyObject *args)
return (PyObject *)PyCode_NewEmpty(filename, funcname, firstlineno);
}
+/* Test PyErr_NewExceptionWithDoc (also exercise PyErr_NewException).
+ Run via Lib/test/test_exceptions.py */
+static PyObject *
+make_exception_with_doc(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ char *name;
+ char *doc = NULL;
+ PyObject *base = NULL;
+ PyObject *dict = NULL;
+
+ static char *kwlist[] = {"name", "doc", "base", "dict", NULL};
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs,
+ "s|sOO:make_exception_with_doc", kwlist,
+ &name, &doc, &base, &dict))
+ return NULL;
+
+ return PyErr_NewExceptionWithDoc(name, doc, base, dict);
+}
+
static PyMethodDef TestMethods[] = {
{"raise_exception", raise_exception, METH_VARARGS},
{"test_config", (PyCFunction)test_config, METH_NOARGS},
@@ -1248,6 +1268,8 @@ static PyMethodDef TestMethods[] = {
#endif
{"traceback_print", traceback_print, METH_VARARGS},
{"code_newempty", code_newempty, METH_VARARGS},
+ {"make_exception_with_doc", (PyCFunction)make_exception_with_doc,
+ METH_VARARGS | METH_KEYWORDS},
{NULL, NULL} /* sentinel */
};