diff options
author | Guido van Rossum <guido@python.org> | 2000-12-15 21:58:52 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2000-12-15 21:58:52 (GMT) |
commit | cfd42b556bfa6282362dc53edcfabd5fa95fd9c0 (patch) | |
tree | 0277fcef023181cb6b11941df10f1b222e7efce4 /Python/errors.c | |
parent | d0977cd6707735e7918d185f30f6aa1253be9459 (diff) | |
download | cpython-cfd42b556bfa6282362dc53edcfabd5fa95fd9c0.zip cpython-cfd42b556bfa6282362dc53edcfabd5fa95fd9c0.tar.gz cpython-cfd42b556bfa6282362dc53edcfabd5fa95fd9c0.tar.bz2 |
Add PyErr_Warn().
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c index 3053e00..908c0c1 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -588,3 +588,37 @@ PyErr_WriteUnraisable(PyObject *obj) Py_XDECREF(v); Py_XDECREF(tb); } + + +/* Function to issue a warning message; may raise an exception. */ +int +PyErr_Warn(PyObject *category, char *message) +{ + PyObject *mod, *dict, *func = NULL; + + mod = PyImport_ImportModule("warnings"); + if (mod != NULL) { + dict = PyModule_GetDict(mod); + func = PyDict_GetItemString(dict, "warn"); + Py_DECREF(mod); + } + if (func == NULL) { + PySys_WriteStderr("warning: %s\n", message); + return 0; + } + else { + PyObject *args, *res; + + if (category == NULL) + category = PyExc_RuntimeWarning; + args = Py_BuildValue("(sO)", message, category); + if (args == NULL) + return -1; + res = PyEval_CallObject(func, args); + Py_DECREF(args); + if (res == NULL) + return -1; + Py_DECREF(res); + return 0; + } +} |