summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-02-28 21:46:24 (GMT)
committerGuido van Rossum <guido@python.org>2001-02-28 21:46:24 (GMT)
commit2fd456508fe1f6e9d89e153f2d8e83a95b233504 (patch)
tree0c31c98dce5ba3fc07a128d831e2d2c13afe0a24 /Python
parent1bcb7e9327414d1e8675597b91e4f6e0441315fc (diff)
downloadcpython-2fd456508fe1f6e9d89e153f2d8e83a95b233504.zip
cpython-2fd456508fe1f6e9d89e153f2d8e83a95b233504.tar.gz
cpython-2fd456508fe1f6e9d89e153f2d8e83a95b233504.tar.bz2
Add PyErr_WarnExplicit(), which calls warnings.warn_explicit(), with
explicit filename, lineno etc. arguments.
Diffstat (limited to 'Python')
-rw-r--r--Python/errors.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 41050ce..7f30f7e 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -623,6 +623,48 @@ PyErr_Warn(PyObject *category, char *message)
}
}
+
+/* Warning with explicit origin */
+int
+PyErr_WarnExplicit(PyObject *category, char *message,
+ char *filename, int lineno,
+ char *module, PyObject *registry)
+{
+ PyObject *mod, *dict, *func = NULL;
+
+ mod = PyImport_ImportModule("warnings");
+ if (mod != NULL) {
+ dict = PyModule_GetDict(mod);
+ func = PyDict_GetItemString(dict, "warn_explicit");
+ Py_DECREF(mod);
+ }
+ if (func == NULL) {
+ PySys_WriteStderr("warning: %s\n", message);
+ return 0;
+ }
+ else {
+ PyObject *args, *res;
+
+ if (category == NULL)
+ category = PyExc_RuntimeWarning;
+ if (registry == NULL)
+ registry = Py_None;
+ args = Py_BuildValue("(sOsizO)", message, category,
+ filename, lineno, module, registry);
+ if (args == NULL)
+ return -1;
+ res = PyEval_CallObject(func, args);
+ Py_DECREF(args);
+ if (res == NULL)
+ return -1;
+ Py_DECREF(res);
+ return 0;
+ }
+}
+
+
+/* XXX There's a comment missing here */
+
void
PyErr_SyntaxLocation(char *filename, int lineno)
{