From abe4a7e6480e0d2860f10930d563e4577d2d801a Mon Sep 17 00:00:00 2001 From: Sven Trenkel Date: Fri, 1 Jan 2010 22:16:51 +0100 Subject: [PATCH] python: Added notification repr. Python3 support completed. --- src/pyvalues.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/src/pyvalues.c b/src/pyvalues.c index c6b40321..3fb68cf2 100644 --- a/src/pyvalues.c +++ b/src/pyvalues.c @@ -826,19 +826,41 @@ static int Notification_setstring(PyObject *self, PyObject *value, void *data) { return 0; } -/*static PyObject *Notification_repr(PyObject *s) { - PyObject *ret; +static PyObject *Notification_repr(PyObject *s) { + PyObject *ret, *tmp; + static PyObject *l_severity = NULL, *l_message = NULL, *l_closing = NULL; Notification *self = (Notification *) s; - ret = PyString_FromFormat("collectd.Values(type='%s%s%s%s%s%s%s%s%s%s%s',time=%lu,interval=%i)", self->data.type, - *self->data.type_instance ? "',type_instance='" : "", self->data.type_instance, - *self->data.plugin ? "',plugin='" : "", self->data.plugin, - *self->data.plugin_instance ? "',plugin_instance='" : "", self->data.plugin_instance, - *self->data.host ? "',host='" : "", self->data.host, - *self->message ? "',message='" : "", self->message, - (long unsigned) self->data.time, self->severity); + if (l_severity == NULL) + l_severity = cpy_string_to_unicode_or_bytes(",severity="); + if (l_message == NULL) + l_message = cpy_string_to_unicode_or_bytes(",message="); + if (l_closing == NULL) + l_closing = cpy_string_to_unicode_or_bytes(")"); + + if (l_severity == NULL || l_message == NULL || l_closing == NULL) + return NULL; + + ret = cpy_common_repr(s); + if (self->severity != 0) { + CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_severity); + tmp = PyInt_FromLong(self->severity); + CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp); + if (tmp) + CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp); + Py_XDECREF(tmp); + } + if (self->message[0] != 0) { + CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_message); + tmp = cpy_string_to_unicode_or_bytes(self->message); + CPY_SUBSTITUTE(PyObject_Repr, tmp, tmp); + if (tmp) + CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, tmp); + Py_XDECREF(tmp); + } + CPY_SUBSTITUTE(CPY_STRCAT, ret, ret, l_closing); return ret; -}*/ +} static PyMethodDef Notification_methods[] = { {"dispatch", (PyCFunction) Notification_dispatch, METH_VARARGS | METH_KEYWORDS, dispatch_doc}, @@ -865,7 +887,7 @@ PyTypeObject NotificationType = { 0, /* tp_getattr */ 0, /* tp_setattr */ 0, /* tp_compare */ - 0/*Notification_repr*/, /* tp_repr */ + Notification_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ 0, /* tp_as_mapping */ -- 2.11.0