summaryrefslogtreecommitdiff
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2013-07-01 23:00:22 +0200
committerChristian Heimes <christian@cheimes.de>2013-07-01 23:00:22 +0200
commit9dc893c954b626685fc5bb12a040e22a41a8958d (patch)
treec42918d40b287e76ae260b4c402ce62ed813087d /Python/_warnings.c
parentd71dc179c59f0a6e74087ecea134164f0e184ee8 (diff)
parent691afb4d9f2a095f89c6e4011807a185fa661bb7 (diff)
downloadcpython-9dc893c954b626685fc5bb12a040e22a41a8958d.tar.gz
Issue #18339: use with self.assertRaises() to make test case more readable
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index f33e477ad7..03e0c4545a 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -800,8 +800,8 @@ PyErr_WarnExplicit(PyObject *category, const char *text,
goto exit;
if (module_str != NULL) {
module = PyUnicode_FromString(module_str);
- if (module == NULL)
- goto exit;
+ if (module == NULL)
+ goto exit;
}
if (category == NULL)
@@ -820,6 +820,49 @@ PyErr_WarnExplicit(PyObject *category, const char *text,
return ret;
}
+int
+PyErr_WarnExplicitFormat(PyObject *category,
+ const char *filename_str, int lineno,
+ const char *module_str, PyObject *registry,
+ const char *format, ...)
+{
+ PyObject *message;
+ PyObject *module = NULL;
+ PyObject *filename = PyUnicode_DecodeFSDefault(filename_str);
+ int ret = -1;
+ va_list vargs;
+
+ if (filename == NULL)
+ goto exit;
+ if (module_str != NULL) {
+ module = PyUnicode_FromString(module_str);
+ if (module == NULL)
+ goto exit;
+ }
+
+#ifdef HAVE_STDARG_PROTOTYPES
+ va_start(vargs, format);
+#else
+ va_start(vargs);
+#endif
+ message = PyUnicode_FromFormatV(format, vargs);
+ if (message != NULL) {
+ PyObject *res;
+ res = warn_explicit(category, message, filename, lineno,
+ module, registry, NULL);
+ Py_DECREF(message);
+ if (res != NULL) {
+ Py_DECREF(res);
+ ret = 0;
+ }
+ }
+ va_end(vargs);
+exit:
+ Py_XDECREF(module);
+ Py_XDECREF(filename);
+ return ret;
+}
+
PyDoc_STRVAR(warn_doc,
"Issue a warning, or maybe ignore it or raise an exception.");