00001
00005 #include "system.h"
00006
00007 #include "structmember.h"
00008
00009 #include "rpmdebug-py.c"
00010
00011 #include <rpmcli.h>
00012
00013 #include "rpmrc-py.h"
00014
00015 #include "debug.h"
00016
00017
00018 static int _rc_debug = 0;
00019
00029
00032 PyObject * rpmrc_AddMacro( PyObject * self, PyObject * args)
00033 {
00034 char * name, * val;
00035
00036 if (!PyArg_ParseTuple(args, "ss:AddMacro", &name, &val))
00037 return NULL;
00038
00039 addMacro(NULL, name, NULL, val, -1);
00040
00041 Py_INCREF(Py_None);
00042 return Py_None;
00043 }
00044
00047 PyObject * rpmrc_DelMacro( PyObject * self, PyObject * args)
00048 {
00049 char * name;
00050
00051 if (!PyArg_ParseTuple(args, "s:DelMacro", &name))
00052 return NULL;
00053
00054 delMacro(NULL, name);
00055
00056 Py_INCREF(Py_None);
00057 return Py_None;
00058 }
00059
00060 #if Py_TPFLAGS_HAVE_ITER
00061
00063 static void rpmrc_dealloc(PyObject * s)
00064
00065 {
00066 if (_rc_debug)
00067 fprintf(stderr, "*** rpmrc_dealloc(%p[%s])\n", s, lbl(s));
00068 PyDict_Type.tp_dealloc(s);
00069 }
00070
00073 static int rpmrc_print(PyObject * s, FILE *fp, int flags)
00074
00075 {
00076
00077 if (_rc_debug)
00078 fprintf(stderr, "*** rpmrc_print(%p[%s],%p,%x)\n", s, lbl(s), fp, flags);
00079
00080 return PyDict_Type.tp_print(s, fp, flags);
00081 }
00082
00085 static int rpmrc_compare(PyObject * a, PyObject * b)
00086
00087 {
00088 if (_rc_debug)
00089 fprintf(stderr, "*** rpmrc_compare(%p[%s],%p[%s])\n", a, lbl(a), b, lbl(b));
00090 return PyDict_Type.tp_compare(a, b);
00091 }
00092
00095 static PyObject * rpmrc_repr(PyObject * s)
00096
00097 {
00098 if (_rc_debug)
00099 fprintf(stderr, "*** rpmrc_repr(%p[%s])\n", s, lbl(s));
00100 return PyDict_Type.tp_repr(s);
00101 }
00102
00105 static long rpmrc_hash(PyObject * s)
00106
00107 {
00108
00109 if (_rc_debug)
00110 fprintf(stderr, "*** rpmrc_hash(%p[%s])\n", s, lbl(s));
00111 return PyDict_Type.tp_hash(s);
00112 }
00113
00116 static int
00117 rpmrc_length(PyObject * s)
00118
00119 {
00120 if (_rc_debug)
00121 fprintf(stderr, "*** rpmrc_length(%p[%s])\n", s, lbl(s));
00122 return PyDict_Type.tp_as_mapping->mp_length(s);
00123 }
00124
00127 static PyObject *
00128 rpmrc_subscript(PyObject * s, PyObject * key)
00129
00130 {
00131 if (_rc_debug)
00132 fprintf(stderr, "*** rpmrc_subscript(%p[%s], %p[%s])\n", s, lbl(s), key, lbl(key));
00133 return PyDict_Type.tp_as_mapping->mp_subscript(s, key);
00134 }
00135
00138 static int
00139 rpmrc_ass_subscript(PyObject * s, PyObject * key, PyObject * value)
00140
00141 {
00142 if (_rc_debug)
00143 fprintf(stderr, "*** rpmrc_ass_subscript(%p[%s], %p[%s], %p[%s])\n", s, lbl(s), key, lbl(key), value, lbl(value));
00144 return PyDict_Type.tp_as_mapping->mp_ass_subscript(s, key, value);
00145 }
00146
00147
00148 static PyMappingMethods rpmrc_as_mapping = {
00149 rpmrc_length,
00150 rpmrc_subscript,
00151 rpmrc_ass_subscript,
00152 };
00153
00156 static PyObject * rpmrc_getattro (PyObject *s, PyObject *name)
00157
00158 {
00159 if (_rc_debug)
00160 fprintf(stderr, "*** rpmrc_getattro(%p[%s], \"%s\")\n", s, lbl(s), PyString_AS_STRING(name));
00161 return PyObject_GenericGetAttr(s, name);
00162 }
00163
00166 static int rpmrc_setattro (PyObject *s, PyObject *name, PyObject * value)
00167
00168 {
00169 if (_rc_debug)
00170 fprintf(stderr, "*** rpmrc_setattro(%p[%s], \"%s \", \"%s\")\n", s, lbl(s), PyString_AS_STRING(name), PyString_AS_STRING(value));
00171 return PyDict_Type.tp_setattro(s, name, value);
00172 }
00173
00176
00177 static char rpmrc_doc[] =
00178 "";
00179
00182 static int rpmrc_traverse(PyObject * s, visitproc visit, void *arg)
00183
00184 {
00185 if (_rc_debug)
00186 fprintf(stderr, "*** rpmrc_traverse(%p[%s],%p,%p)\n", s, lbl(s), visit, arg);
00187 return PyDict_Type.tp_traverse(s, visit, arg);
00188 }
00189
00192 static int rpmrc_clear(PyObject * s)
00193
00194 {
00195 if (_rc_debug)
00196 fprintf(stderr, "*** rpmrc_clear(%p[%s])\n", s, lbl(s));
00197 return PyDict_Type.tp_clear(s);
00198 }
00199
00202 static PyObject * rpmrc_richcompare(PyObject * v, PyObject * w, int op)
00203
00204 {
00205 if (_rc_debug)
00206 fprintf(stderr, "*** rpmrc_richcompare(%p[%s],%p[%s],%x)\n", v, lbl(v), w, lbl(w), op);
00207 return PyDict_Type.tp_richcompare(v, w, op);
00208 }
00209
00210 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 4
00211
00213 static PyObject * rpmrc_iter(PyObject * s)
00214
00215 {
00216 if (_rc_debug)
00217 fprintf(stderr, "*** rpmrc_iter(%p[%s])\n", s, lbl(s));
00218 if (s->ob_type == &PyDictIter_Type)
00219 return PyDictIter_Type.tp_iter(s);
00220 return PyDict_Type.tp_iter(s);
00221 }
00222
00225
00226 static PyObject * rpmrc_iternext(PyObject * s)
00227
00228 {
00229 if (_rc_debug)
00230 fprintf(stderr, "*** rpmrc_iternext(%p[%s])\n", s, lbl(s));
00231 if (s->ob_type == &PyDictIter_Type)
00232 return PyDictIter_Type.tp_iternext(s);
00233 return NULL;
00234 }
00235
00238
00239 static PyObject * rpmrc_next(PyObject * s, PyObject *args)
00240
00241 {
00242 if (_rc_debug)
00243 fprintf(stderr, "*** rpmrc_next(%p[%s],%p)\n", s, lbl(s), args);
00244 if (s->ob_type == &PyDictIter_Type)
00245 return PyDictIter_Type.tp_methods[0].ml_meth(s, args);
00246 return NULL;
00247 }
00248 #else
00249 #define rpmrc_iter 0
00250 #define rpmrc_iternext 0
00251 #endif
00252
00255 static int rpmrc_init(PyObject * s, PyObject *args, PyObject *kwds)
00256
00257 {
00258 if (_rc_debug)
00259 fprintf(stderr, "*** rpmrc_init(%p[%s],%p,%p)\n", s, lbl(s), args, kwds);
00260 if (PyDict_Type.tp_init(s, args, kwds) < 0)
00261 return -1;
00262 return 0;
00263 }
00264
00267 static void rpmrc_free(PyObject * s)
00268
00269 {
00270 if (_rc_debug)
00271 fprintf(stderr, "*** rpmrc_free(%p[%s])\n", s, lbl(s));
00272 _PyObject_GC_Del(s);
00273 }
00274
00277 static PyObject * rpmrc_alloc(PyTypeObject * subtype, int nitems)
00278
00279 {
00280 PyObject * ns = PyType_GenericAlloc(subtype, nitems);
00281
00282 if (_rc_debug)
00283 fprintf(stderr, "*** rpmrc_alloc(%p[%s},%d) ret %p[%s]\n", subtype, lbl(subtype), nitems, ns, lbl(ns));
00284 return (PyObject *) ns;
00285 }
00286
00289
00290 static PyObject * rpmrc_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
00291
00292 {
00293 PyObject * ns;
00294
00295
00296 ns = PyDict_Type.tp_new(&rpmrc_Type, args, kwds);
00297
00298
00299 if (rpmrc_init(ns, args, kwds) < 0) {
00300 rpmrc_free(ns);
00301 return NULL;
00302 }
00303
00304 if (_rc_debug)
00305 fprintf(stderr, "*** rpmrc_new(%p[%s],%p,%p) ret %p[%s]\n", subtype, lbl(subtype), args, kwds, ns, lbl(ns));
00306 return ns;
00307 }
00308 #endif
00309
00312
00313
00314 static struct PyMethodDef rpmrc_methods[] = {
00315 { "addMacro", (PyCFunction) rpmrc_AddMacro, METH_VARARGS,
00316 NULL },
00317 { "delMacro", (PyCFunction) rpmrc_DelMacro, METH_VARARGS,
00318 NULL },
00319 #if Py_TPFLAGS_HAVE_ITER && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 4
00320 { "next", (PyCFunction) rpmrc_next, METH_VARARGS,
00321 "next() -- get the next value, or raise StopIteration"},
00322 #endif
00323 {NULL, NULL}
00324 };
00325
00326
00329
00330 #if Py_TPFLAGS_HAVE_ITER
00331 PyTypeObject rpmrc_Type = {
00332 PyObject_HEAD_INIT(&PyType_Type)
00333 0,
00334 "rpm.rc",
00335 sizeof(rpmrcObject),
00336 0,
00337 (destructor) rpmrc_dealloc,
00338 rpmrc_print,
00339 0,
00340 0,
00341 rpmrc_compare,
00342 rpmrc_repr,
00343 0,
00344 0,
00345 &rpmrc_as_mapping,
00346 rpmrc_hash,
00347 0,
00348 0,
00349 (getattrofunc) rpmrc_getattro,
00350 (setattrofunc) rpmrc_setattro,
00351 0,
00352 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
00353 rpmrc_doc,
00354 rpmrc_traverse,
00355 rpmrc_clear,
00356 rpmrc_richcompare,
00357 0,
00358 rpmrc_iter,
00359 rpmrc_iternext,
00360 rpmrc_methods,
00361 0,
00362 0,
00363 &PyDict_Type,
00364 0,
00365 0,
00366 0,
00367 0,
00368 rpmrc_init,
00369 rpmrc_alloc,
00370 rpmrc_new,
00371 rpmrc_free,
00372 0,
00373 };
00374 #else
00375 PyTypeObject rpmrc_Type = {
00376 PyObject_HEAD_INIT(&PyType_Type)
00377 0,
00378 "rpm.rc",
00379 sizeof(rpmrcObject),
00380 0,
00381 0,
00382 0,
00383 0,
00384 0,
00385 0,
00386 0,
00387 0,
00388 0,
00389 0,
00390 0,
00391 0,
00392 0,
00393 0,
00394 0,
00395 0,
00396 0,
00397 0
00398 };
00399 #endif
00400
00401
00402 #if Py_TPFLAGS_HAVE_ITER
00403 PyObject * rpmrc_Create( PyObject * self, PyObject *args, PyObject *kwds)
00404 {
00405 return rpmrc_new(&rpmrc_Type, args, kwds);
00406 }
00407 #endif
00408