diff Objects/stringlib/string_format.h @ 43241:e946073dee38

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.
author Eric Smith <eric@trueblade.com>
date Tue, 04 Sep 2007 23:04:22 +0000
parents f4fb74f63806
children 79080c4889bc
line wrap: on
line diff
--- a/Objects/stringlib/string_format.h	Tue Sep 04 19:43:19 2007 +0000
+++ b/Objects/stringlib/string_format.h	Tue Sep 04 23:04:22 2007 +0000
@@ -414,8 +414,7 @@
         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 @@
     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 */