mirror of
https://github.com/python/cpython.git
synced 2025-07-16 15:55:18 +00:00
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.
This commit is contained in:
parent
b962171414
commit
fb88636199
7 changed files with 57 additions and 2 deletions
|
@ -1607,6 +1607,21 @@ _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *args,
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue