diff options
author | Eric Smith <eric@trueblade.com> | 2007-08-27 23:30:47 (GMT) |
---|---|---|
committer | Eric Smith <eric@trueblade.com> | 2007-08-27 23:30:47 (GMT) |
commit | 7a6dd290672a8add669e2637839366f7fe3a3870 (patch) | |
tree | 3811411d48bf141058b7ff1940ca1de9f798794d /Objects | |
parent | 7dcb844892bbcc7e06e8cde5d7d153bb7ea3fda5 (diff) | |
download | cpython-7a6dd290672a8add669e2637839366f7fe3a3870.zip cpython-7a6dd290672a8add669e2637839366f7fe3a3870.tar.gz cpython-7a6dd290672a8add669e2637839366f7fe3a3870.tar.bz2 |
Cleanup in anticipation of moving formatteriterator and fieldnameiterator into stringlib/string_format.h.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/stringlib/string_format.h | 30 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 4 |
2 files changed, 9 insertions, 25 deletions
diff --git a/Objects/stringlib/string_format.h b/Objects/stringlib/string_format.h index c2916fd..df6ca96 100644 --- a/Objects/stringlib/string_format.h +++ b/Objects/stringlib/string_format.h @@ -55,24 +55,6 @@ SubString_new_object(SubString *str) } /************************************************************************/ -/*********** Error handling and exception generation **************/ -/************************************************************************/ - -/* - Most of our errors are value errors, because to Python, the - format string is a "value". Also, it's convenient to return - a NULL when we are erroring out. - - XXX: need better error handling, per PEP 3101. -*/ -static void * -SetError(const char *s) -{ - /* PyErr_Format always returns NULL */ - return PyErr_Format(PyExc_ValueError, "%s in format string", s); -} - -/************************************************************************/ /*********** Output string management functions ****************/ /************************************************************************/ @@ -187,7 +169,7 @@ static PyObject * getattr(PyObject *obj, SubString *name) { PyObject *newobj; - PyObject *str = STRINGLIB_NEW(name->ptr, name->end - name->ptr); + PyObject *str = SubString_new_object(name); if (str == NULL) return NULL; newobj = PyObject_GetAttr(obj, str); @@ -220,7 +202,7 @@ static PyObject * getitem_str(PyObject *obj, SubString *name) { PyObject *newobj; - PyObject *str = STRINGLIB_NEW(name->ptr, name->end - name->ptr); + PyObject *str = SubString_new_object(name); if (str == NULL) return NULL; newobj = PyObject_GetItem(obj, str); @@ -407,7 +389,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs) if (index == -1) { /* look up in kwargs */ - PyObject *key = STRINGLIB_NEW(first.ptr, first.end - first.ptr); + PyObject *key = SubString_new_object(&first); if (key == NULL) goto error; if ((kwargs == NULL) || (obj = PyDict_GetItem(kwargs, key)) == NULL) { @@ -719,11 +701,13 @@ MarkupIterator_next(MarkupIterator *self, int *is_markup, SubString *literal, len = self->str.ptr - start; if ((c == '}') && (at_end || (c != *self->str.ptr))) { - SetError("Single } encountered"); + PyErr_SetString(PyExc_ValueError, "Single '}' encountered " + "in format string"); return 0; } if (at_end && c == '{') { - SetError("Single { encountered"); + PyErr_SetString(PyExc_ValueError, "Single '{' encountered " + "in format string"); return 0; } if (!at_end) { diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 5593ada..afe0e18 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -8209,7 +8209,7 @@ fieldnameiter_next(fieldnameiterobject *it) if (idx != -1) obj = PyInt_FromSsize_t(idx); else - obj = STRINGLIB_NEW(name.ptr, name.end - name.ptr); + obj = SubString_new_object(&name); if (obj == NULL) goto error; @@ -8301,7 +8301,7 @@ unicode_formatter_field_name_split(PyUnicodeObject *self) first_obj = PyInt_FromSsize_t(first_idx); else /* convert "first" into a string object */ - first_obj = STRINGLIB_NEW(first.ptr, first.end - first.ptr); + first_obj = SubString_new_object(&first); if (first_obj == NULL) goto error; |