2 #include <structmember.h>
9 static PyObject *Config_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
12 self = (Config *) type->tp_alloc(type, 0);
19 self->children = NULL;
20 return (PyObject *) self;
23 static int Config_init(PyObject *s, PyObject *args, PyObject *kwds) {
24 PyObject *key = NULL, *parent = NULL, *values = NULL, *children = NULL, *tmp;
25 Config *self = (Config *) s;
26 static char *kwlist[] = {"key", "parent", "values", "children", NULL};
28 if (!PyArg_ParseTupleAndKeywords(args, kwds, "S|OOO", kwlist,
29 &key, &parent, &values, &children))
33 values = PyTuple_New(0);
36 if (children == NULL) {
37 children = PyTuple_New(0);
47 self->parent = parent;
53 self->values = values;
56 if (children != NULL) {
59 self->children = children;
65 static PyObject *Config_repr(PyObject *s) {
66 Config *self = (Config *) s;
68 return PyString_FromFormat("<collectd.Config %snode %s>", self->parent == Py_None ? "root " : "", PyString_AsString(PyObject_Str(self->key)));
71 static int Config_traverse(PyObject *self, visitproc visit, void *arg) {
72 Config *c = (Config *) self;
76 Py_VISIT(c->children);
80 static int Config_clear(PyObject *self) {
81 Config *c = (Config *) self;
85 Py_CLEAR(c->children);
89 static void Config_dealloc(PyObject *self) {
91 self->ob_type->tp_free(self);
94 static PyMemberDef Config_members[] = {
95 {"Parent", T_OBJECT, offsetof(Config, parent), 0, "Parent node"},
96 {"Key", T_OBJECT_EX, offsetof(Config, key), 0, "Keyword of this node"},
97 {"Values", T_OBJECT_EX, offsetof(Config, values), 0, "Values after the key"},
98 {"Children", T_OBJECT_EX, offsetof(Config, children), 0, "Childnodes of this node"},
102 PyTypeObject ConfigType = {
103 PyObject_HEAD_INIT(NULL)
105 "collectd.Config", /* tp_name */
106 sizeof(Config), /* tp_basicsize */
107 0, /* Will be filled in later */
108 Config_dealloc, /* tp_dealloc */
113 Config_repr, /* tp_repr */
114 0, /* tp_as_number */
115 0, /* tp_as_sequence */
116 0, /* tp_as_mapping */
122 0, /* tp_as_buffer */
123 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
124 "Cool help text later", /* tp_doc */
125 Config_traverse, /* tp_traverse */
126 Config_clear, /* tp_clear */
127 0, /* tp_richcompare */
128 0, /* tp_weaklistoffset */
132 Config_members, /* tp_members */
136 0, /* tp_descr_get */
137 0, /* tp_descr_set */
138 0, /* tp_dictoffset */
139 Config_init, /* tp_init */
141 Config_new /* tp_new */