Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror

PyString_Concat() and PyString_ConcatAndDel() (the name PyUnicode_Concat()
was already taken).

Change PyObject_Repr() to always return a unicode object.

Update all repr implementations to return unicode objects.

Add a function PyObject_ReprStr8() that calls PyObject_Repr() and converts
the result to an 8bit string.

Use PyObject_ReprStr8() where using PyObject_Repr() can't be done
straightforward.
This commit is contained in:
Walter Dörwald 2007-05-18 17:15:44 +00:00
parent 14176a56d3
commit 1ab8330827
49 changed files with 385 additions and 255 deletions

View file

@ -111,13 +111,13 @@ BaseException_repr(PyBaseExceptionObject *self)
dot = strrchr(name, '.');
if (dot != NULL) name = dot+1;
repr = PyString_FromString(name);
repr = PyUnicode_FromString(name);
if (!repr) {
Py_DECREF(repr_suffix);
return NULL;
}
PyString_ConcatAndDel(&repr, repr_suffix);
PyUnicode_AppendAndDel(&repr, repr_suffix);
return repr;
}
@ -529,7 +529,7 @@ EnvironmentError_str(PyEnvironmentErrorObject *self)
if (!fmt)
return NULL;
repr = PyObject_Repr(self->filename);
repr = PyObject_ReprStr8(self->filename);
if (!repr) {
Py_DECREF(fmt);
return NULL;
@ -760,7 +760,7 @@ WindowsError_str(PyWindowsErrorObject *self)
if (!fmt)
return NULL;
repr = PyObject_Repr(self->filename);
repr = PyObject_ReprStr8(self->filename);
if (!repr) {
Py_DECREF(fmt);
return NULL;
@ -1134,7 +1134,7 @@ KeyError_str(PyBaseExceptionObject *self)
If args is anything else, use the default BaseException__str__().
*/
if (PyTuple_GET_SIZE(self->args) == 1) {
return PyObject_Repr(PyTuple_GET_ITEM(self->args, 0));
return PyObject_ReprStr8(PyTuple_GET_ITEM(self->args, 0));
}
return BaseException_str(self);
}