changeset 1454:33aa72138a5e

cdefer: Added representation function for Deferreds.
author Marcel Keller <mkeller@cs.au.dk>
date Tue, 20 Jul 2010 16:37:17 +0200
parents 2d537c1b8dbe
children e95a28d7df81
files viff/cdefer.c
diffstat 1 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/viff/cdefer.c	Tue Jul 20 15:48:49 2010 +0200
+++ b/viff/cdefer.c	Tue Jul 20 16:37:17 2010 +0200
@@ -273,6 +273,25 @@
     return 0;
 }
 
+static PyObject* cdefer_Deferred___str__(cdefer_Deferred *self) {
+    PyObject *result, *tmp;
+    char* cname = Py_TYPE(self)->tp_name;
+
+    if (self->result) {
+	tmp = PyObject_Repr(self->result);
+
+	if (!tmp)
+	    return NULL;
+
+	result = PyString_FromFormat("<%s at %p  current result: %s>",
+				     cname, self, PyString_AsString(tmp));
+	Py_DECREF(tmp);
+	return result;
+    }
+
+    return PyString_FromFormat("<%s at %p>", cname, self);
+}
+
 static PyObject *cdefer_Deferred__addCallbacks(cdefer_Deferred *self,
         PyObject *callback, PyObject *errback, PyObject *callbackArgs,
         PyObject *callbackKeywords, PyObject *errbackArgs,
@@ -833,13 +852,13 @@
     0,                          /*tp_getattr*/
     0,                          /*tp_setattr*/
     0,                          /*tp_compare*/
-    0,                          /*tp_repr*/
+    (reprfunc)cdefer_Deferred___str__,    /*tp_repr*/
     0,                          /*tp_as_number*/
     0,                          /*tp_as_sequence*/
     0,                          /*tp_as_mapping*/
     0,                          /*tp_hash */
     0,                          /*tp_call*/
-    0,                          /*tp_str*/
+    (reprfunc)cdefer_Deferred___str__,    /*tp_str*/
     0,                          /*tp_getattro*/
     0,                          /*tp_setattro*/
     0,                          /*tp_as_buffer*/