diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-10-15 22:53:08 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-05 09:34:47 +0000 |
commit | 8db9c7085d28aad79fc707423e2919a2527bf78d (patch) | |
tree | 01dda28d6432ed3491633c1f7a0af2203b62e6d1 | |
parent | f435d15c956e5bc99d907af8f41f0985380ce591 (diff) | |
download | psycopg2-8db9c7085d28aad79fc707423e2919a2527bf78d.tar.gz |
Added repr method for Notify object.
-rw-r--r-- | psycopg/notify_type.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/psycopg/notify_type.c b/psycopg/notify_type.c index 3828822..9e772a9 100644 --- a/psycopg/notify_type.c +++ b/psycopg/notify_type.c @@ -103,6 +103,34 @@ notify_del(PyObject *self) PyObject_GC_Del(self); } +static PyObject* +notify_repr(NotifyObject *self) +{ + PyObject *rv = NULL; + PyObject *format = NULL; + PyObject *args = NULL; + + if (!(format = PyString_FromString("Notify(%r, %r, %r)"))) { + goto exit; + } + + if (!(args = PyTuple_New(3))) { goto exit; } + Py_INCREF(self->pid); + PyTuple_SET_ITEM(args, 0, self->pid); + Py_INCREF(self->channel); + PyTuple_SET_ITEM(args, 1, self->channel); + Py_INCREF(self->payload); + PyTuple_SET_ITEM(args, 2, self->payload); + + rv = PyString_Format(format, args); + +exit: + Py_XDECREF(args); + Py_XDECREF(format); + + return rv; +} + /* Notify can be accessed as a 2 items tuple for backward compatibility */ static Py_ssize_t @@ -161,7 +189,7 @@ PyTypeObject NotifyType = { 0, /*tp_compare*/ - 0, /*tp_repr*/ + (reprfunc)notify_repr, /*tp_repr*/ 0, /*tp_as_number*/ ¬ify_sequence, /*tp_as_sequence*/ 0, /*tp_as_mapping*/ |