comparison 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
comparison
equal deleted inserted replaced
60930:e4c1ebcb4604 60931:79128efe8a99
1605 retval = vgetargskeywords(args, keywords, format, 1605 retval = vgetargskeywords(args, keywords, format,
1606 kwlist, &lva, FLAG_SIZE_T); 1606 kwlist, &lva, FLAG_SIZE_T);
1607 return retval; 1607 return retval;
1608 } 1608 }
1609 1609
1610 int
1611 PyArg_ValidateKeywordArguments(PyObject *kwargs)
1612 {
1613 if (!PyDict_CheckExact(kwargs)) {
1614 PyErr_BadInternalCall();
1615 return 0;
1616 }
1617 if (!_PyDict_HasOnlyStringKeys(kwargs)) {
1618 PyErr_SetString(PyExc_TypeError,
1619 "keyword arguments must be strings");
1620 return 0;
1621 }
1622 return 1;
1623 }
1624
1610 #define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':') 1625 #define IS_END_OF_FORMAT(c) (c == '\0' || c == ';' || c == ':')
1611 1626
1612 static int 1627 static int
1613 vgetargskeywords(PyObject *args, PyObject *keywords, const char *format, 1628 vgetargskeywords(PyObject *args, PyObject *keywords, const char *format,
1614 char **kwlist, va_list *p_va, int flags) 1629 char **kwlist, va_list *p_va, int flags)