From: Sven Trenkel Date: Fri, 1 Jan 2010 21:16:51 +0000 (+0100) Subject: python: Added notification repr. Python3 support completed. X-Git-Tag: collectd-4.10.0~76^2~2 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=abe4a7e6480e0d2860f10930d563e4577d2d801a;p=collectd.git python: Added notification repr. Python3 support completed. --- 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 */