mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +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
|
@ -385,13 +385,13 @@ type_repr(PyTypeObject *type)
|
|||
kind = "type";
|
||||
|
||||
if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) {
|
||||
rtn = PyString_FromFormat("<%s '%s.%s'>",
|
||||
rtn = PyUnicode_FromFormat("<%s '%s.%s'>",
|
||||
kind,
|
||||
PyString_AS_STRING(mod),
|
||||
PyString_AS_STRING(name));
|
||||
}
|
||||
else
|
||||
rtn = PyString_FromFormat("<%s '%s'>", kind, type->tp_name);
|
||||
rtn = PyUnicode_FromFormat("<%s '%s'>", kind, type->tp_name);
|
||||
|
||||
Py_XDECREF(mod);
|
||||
Py_DECREF(name);
|
||||
|
@ -1006,7 +1006,7 @@ class_name(PyObject *cls)
|
|||
if (name == NULL) {
|
||||
PyErr_Clear();
|
||||
Py_XDECREF(name);
|
||||
name = PyObject_Repr(cls);
|
||||
name = PyObject_ReprStr8(cls);
|
||||
}
|
||||
if (name == NULL)
|
||||
return NULL;
|
||||
|
@ -2481,12 +2481,12 @@ object_repr(PyObject *self)
|
|||
if (name == NULL)
|
||||
return NULL;
|
||||
if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__"))
|
||||
rtn = PyString_FromFormat("<%s.%s object at %p>",
|
||||
rtn = PyUnicode_FromFormat("<%s.%s object at %p>",
|
||||
PyString_AS_STRING(mod),
|
||||
PyString_AS_STRING(name),
|
||||
self);
|
||||
else
|
||||
rtn = PyString_FromFormat("<%s object at %p>",
|
||||
rtn = PyUnicode_FromFormat("<%s object at %p>",
|
||||
type->tp_name, self);
|
||||
Py_XDECREF(mod);
|
||||
Py_DECREF(name);
|
||||
|
@ -4645,7 +4645,7 @@ slot_tp_repr(PyObject *self)
|
|||
return res;
|
||||
}
|
||||
PyErr_Clear();
|
||||
return PyString_FromFormat("<%s object at %p>",
|
||||
return PyUnicode_FromFormat("<%s object at %p>",
|
||||
self->ob_type->tp_name, self);
|
||||
}
|
||||
|
||||
|
@ -4662,8 +4662,14 @@ slot_tp_str(PyObject *self)
|
|||
return res;
|
||||
}
|
||||
else {
|
||||
PyObject *ress;
|
||||
PyErr_Clear();
|
||||
return slot_tp_repr(self);
|
||||
res = slot_tp_repr(self);
|
||||
if (!res)
|
||||
return NULL;
|
||||
ress = _PyUnicode_AsDefaultEncodedString(res, NULL);
|
||||
Py_DECREF(res);
|
||||
return ress;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5692,12 +5698,12 @@ super_repr(PyObject *self)
|
|||
superobject *su = (superobject *)self;
|
||||
|
||||
if (su->obj_type)
|
||||
return PyString_FromFormat(
|
||||
return PyUnicode_FromFormat(
|
||||
"<super: <class '%s'>, <%s object>>",
|
||||
su->type ? su->type->tp_name : "NULL",
|
||||
su->obj_type->tp_name);
|
||||
else
|
||||
return PyString_FromFormat(
|
||||
return PyUnicode_FromFormat(
|
||||
"<super: <class '%s'>, NULL>",
|
||||
su->type ? su->type->tp_name : "NULL");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue