mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +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
|
|
@ -611,14 +611,14 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
|||
static PyObject *
|
||||
deque_repr(PyObject *deque)
|
||||
{
|
||||
PyObject *aslist, *result, *fmt;
|
||||
PyObject *aslist, *result;
|
||||
int i;
|
||||
|
||||
i = Py_ReprEnter(deque);
|
||||
if (i != 0) {
|
||||
if (i < 0)
|
||||
return NULL;
|
||||
return PyString_FromString("[...]");
|
||||
return PyUnicode_FromString("[...]");
|
||||
}
|
||||
|
||||
aslist = PySequence_List(deque);
|
||||
|
|
@ -627,14 +627,14 @@ deque_repr(PyObject *deque)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
fmt = PyString_FromString("deque(%r)");
|
||||
if (fmt == NULL) {
|
||||
result = PyUnicode_FromString("deque(");
|
||||
if (result == NULL) {
|
||||
Py_DECREF(aslist);
|
||||
Py_ReprLeave(deque);
|
||||
return NULL;
|
||||
}
|
||||
result = PyString_Format(fmt, aslist);
|
||||
Py_DECREF(fmt);
|
||||
PyUnicode_AppendAndDel(&result, PyObject_Repr(aslist));
|
||||
PyUnicode_AppendAndDel(&result, PyUnicode_FromString(")"));
|
||||
Py_DECREF(aslist);
|
||||
Py_ReprLeave(deque);
|
||||
return result;
|
||||
|
|
@ -1215,18 +1215,18 @@ defdict_repr(defdictobject *dd)
|
|||
if (baserepr == NULL)
|
||||
return NULL;
|
||||
if (dd->default_factory == NULL)
|
||||
defrepr = PyString_FromString("None");
|
||||
defrepr = PyUnicode_FromString("None");
|
||||
else
|
||||
defrepr = PyObject_Repr(dd->default_factory);
|
||||
if (defrepr == NULL) {
|
||||
Py_DECREF(baserepr);
|
||||
return NULL;
|
||||
}
|
||||
result = PyString_FromFormat("defaultdict(%s, %s)",
|
||||
PyString_AS_STRING(defrepr),
|
||||
PyString_AS_STRING(baserepr));
|
||||
Py_DECREF(defrepr);
|
||||
Py_DECREF(baserepr);
|
||||
result = PyUnicode_FromString("defaultdict(");
|
||||
PyUnicode_AppendAndDel(&result, defrepr);
|
||||
PyUnicode_AppendAndDel(&result, PyUnicode_FromString(", "));
|
||||
PyUnicode_AppendAndDel(&result, baserepr);
|
||||
PyUnicode_AppendAndDel(&result, PyUnicode_FromString(")"));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue