diff Modules/_collectionsmodule.c @ 41769:b29d71d43c80

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.
author Walter Dörwald <walter@livinglogic.de>
date Fri, 18 May 2007 17:15:44 +0000
parents 06145fbc7ab9
children bee8d01ef42c
line wrap: on
line diff
--- a/Modules/_collectionsmodule.c	Fri May 18 17:04:42 2007 +0000
+++ b/Modules/_collectionsmodule.c	Fri May 18 17:15:44 2007 +0000
@@ -611,14 +611,14 @@
 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 @@
 		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 @@
 	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;
 }