diff Python/getargs.c @ 60931:79128efe8a99

prevent the dict constructor from accepting non-string keyword args #8419 This adds PyArg_ValidateKeywordArguments, which checks that keyword arguments are all strings, using an optimized method if possible.
author Benjamin Peterson <benjamin@python.org>
date Sat, 24 Apr 2010 18:21:17 +0000
parents c67339e371a9
children cab14be0ada1
line wrap: on
line diff
--- a/Python/getargs.c	Sat Apr 24 17:59:49 2010 +0000
+++ b/Python/getargs.c	Sat Apr 24 18:21:17 2010 +0000
@@ -1607,6 +1607,21 @@
 	return retval;
 }
 
+int
+PyArg_ValidateKeywordArguments(PyObject *kwargs)
+{
+	if (!PyDict_CheckExact(kwargs)) {
+		PyErr_BadInternalCall();
+		return 0;
+	}
+	if (!_PyDict_HasOnlyStringKeys(kwargs)) {
+		PyErr_SetString(PyExc_TypeError,
+				"keyword arguments must be strings");
+		return 0;
+	}
+	return 1;
+}
+
 #define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':')
 
 static int