summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-05-18 17:15:44 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-05-18 17:15:44 (GMT)
commit1ab833082738ced53318aca05901e596d5ede683 (patch)
tree0ff2b4c1fcbab3233e012f04bce801cadfd6d7f9 /Modules/_collectionsmodule.c
parent14176a56d3fe36388115688d0b5acae0c759c044 (diff)
downloadcpython-1ab833082738ced53318aca05901e596d5ede683.zip
cpython-1ab833082738ced53318aca05901e596d5ede683.tar.gz
cpython-1ab833082738ced53318aca05901e596d5ede683.tar.bz2
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.
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 2960665..1311d4d 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -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;
}