mirror of https://github.com/python/cpython
Cleanup in anticipation of moving formatteriterator and fieldnameiterator into stringlib/string_format.h.
This commit is contained in:
parent
7dcb844892
commit
7a6dd29067
|
@ -54,24 +54,6 @@ SubString_new_object(SubString *str)
|
||||||
return STRINGLIB_NEW(str->ptr, str->end - str->ptr);
|
return STRINGLIB_NEW(str->ptr, str->end - str->ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
/*********** 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 ****************/
|
/*********** Output string management functions ****************/
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -187,7 +169,7 @@ static PyObject *
|
||||||
getattr(PyObject *obj, SubString *name)
|
getattr(PyObject *obj, SubString *name)
|
||||||
{
|
{
|
||||||
PyObject *newobj;
|
PyObject *newobj;
|
||||||
PyObject *str = STRINGLIB_NEW(name->ptr, name->end - name->ptr);
|
PyObject *str = SubString_new_object(name);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
newobj = PyObject_GetAttr(obj, str);
|
newobj = PyObject_GetAttr(obj, str);
|
||||||
|
@ -220,7 +202,7 @@ static PyObject *
|
||||||
getitem_str(PyObject *obj, SubString *name)
|
getitem_str(PyObject *obj, SubString *name)
|
||||||
{
|
{
|
||||||
PyObject *newobj;
|
PyObject *newobj;
|
||||||
PyObject *str = STRINGLIB_NEW(name->ptr, name->end - name->ptr);
|
PyObject *str = SubString_new_object(name);
|
||||||
if (str == NULL)
|
if (str == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
newobj = PyObject_GetItem(obj, str);
|
newobj = PyObject_GetItem(obj, str);
|
||||||
|
@ -407,7 +389,7 @@ get_field_object(SubString *input, PyObject *args, PyObject *kwargs)
|
||||||
|
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
/* look up in kwargs */
|
/* look up in kwargs */
|
||||||
PyObject *key = STRINGLIB_NEW(first.ptr, first.end - first.ptr);
|
PyObject *key = SubString_new_object(&first);
|
||||||
if (key == NULL)
|
if (key == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
if ((kwargs == NULL) || (obj = PyDict_GetItem(kwargs, key)) == NULL) {
|
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;
|
len = self->str.ptr - start;
|
||||||
|
|
||||||
if ((c == '}') && (at_end || (c != *self->str.ptr))) {
|
if ((c == '}') && (at_end || (c != *self->str.ptr))) {
|
||||||
SetError("Single } encountered");
|
PyErr_SetString(PyExc_ValueError, "Single '}' encountered "
|
||||||
|
"in format string");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (at_end && c == '{') {
|
if (at_end && c == '{') {
|
||||||
SetError("Single { encountered");
|
PyErr_SetString(PyExc_ValueError, "Single '{' encountered "
|
||||||
|
"in format string");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!at_end) {
|
if (!at_end) {
|
||||||
|
|
|
@ -8209,7 +8209,7 @@ fieldnameiter_next(fieldnameiterobject *it)
|
||||||
if (idx != -1)
|
if (idx != -1)
|
||||||
obj = PyInt_FromSsize_t(idx);
|
obj = PyInt_FromSsize_t(idx);
|
||||||
else
|
else
|
||||||
obj = STRINGLIB_NEW(name.ptr, name.end - name.ptr);
|
obj = SubString_new_object(&name);
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
@ -8301,7 +8301,7 @@ unicode_formatter_field_name_split(PyUnicodeObject *self)
|
||||||
first_obj = PyInt_FromSsize_t(first_idx);
|
first_obj = PyInt_FromSsize_t(first_idx);
|
||||||
else
|
else
|
||||||
/* convert "first" into a string object */
|
/* 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)
|
if (first_obj == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue