diff options
author | Eric Smith <eric@trueblade.com> | 2007-09-04 23:04:22 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2007-09-04 23:04:22 (GMT) |
commit | 11529195cae2438a3ac003babcb1b11af67c4037 (patch) | |
tree | 2bf0ac780377e409f87ad51aca8d8bc7c882f015 /Objects | |
parent | 0af17617c51d6cae4c0b7ff225751e07183b96f2 (diff) | |
download | cpython-11529195cae2438a3ac003babcb1b11af67c4037.zip cpython-11529195cae2438a3ac003babcb1b11af67c4037.tar.gz cpython-11529195cae2438a3ac003babcb1b11af67c4037.tar.bz2 |
Changed some ValueError's to KeyError and IndexError.
Corrected code for invalid conversion specifier.
Added tests to verify.
Modified string.Formatter to correctly expand format_spec's,
and added a limit to recursion depth. Added _vformat()
method to support both of these.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringlib/string_format.h | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h index de700f6..ea8b0e7 100644 --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -414,8 +414,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs) if (key == NULL) goto error; if ((kwargs == NULL) || (obj = PyDict_GetItem(kwargs, key)) == NULL) { - PyErr_SetString(PyExc_ValueError, "Keyword argument not found " - "in format string"); + PyErr_SetObject(PyExc_KeyError, key); Py_DECREF(key); goto error; } @@ -425,12 +424,8 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs) else { /* look up in args */ obj = PySequence_GetItem(args, index); - if (obj == NULL) { - /* translate IndexError to a ValueError */ - PyErr_SetString(PyExc_ValueError, "Not enough positional arguments " - "in format string"); + if (obj == NULL) goto error; - } } /* iterate over the rest of the field_name */ |