mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
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:
parent
14176a56d3
commit
1ab8330827
49 changed files with 385 additions and 255 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue