diff --git a/python/header-py.c b/python/header-py.c index d2901220c..a06412775 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -456,6 +456,24 @@ static PyObject * hdr_subscript(hdrObject * s, PyObject * item) return hdrGetTag(s->h, tag); } +static int hdr_ass_subscript(hdrObject *s, PyObject *key, PyObject *value) +{ + rpmTag tag; + rpmtd td; + if (!tagNumFromPyObject(key, &tag)) return -1; + + if (value == NULL) { + /* XXX should failure raise key error? */ + headerDel(s->h, tag); + } else if (rpmtdFromPyObject(value, &td)) { + headerPut(s->h, td, HEADERPUT_DEFAULT); + } else { + PyErr_SetString(PyExc_TypeError, "rpm.td type expected"); + return -1; + } + return 0; +} + static PyObject * hdr_getattro(hdrObject * s, PyObject * n) { PyObject *res = PyObject_GenericGetAttr((PyObject *) s, n); @@ -477,7 +495,7 @@ static int hdr_setattro(PyObject * o, PyObject * n, PyObject * v) static PyMappingMethods hdr_as_mapping = { (lenfunc) 0, /* mp_length */ (binaryfunc) hdr_subscript, /* mp_subscript */ - (objobjargproc)0, /* mp_ass_subscript */ + (objobjargproc)hdr_ass_subscript,/* mp_ass_subscript */ }; static char hdr_doc[] = diff --git a/python/rpmtd-py.c b/python/rpmtd-py.c index 103910aef..e4549b0bf 100644 --- a/python/rpmtd-py.c +++ b/python/rpmtd-py.c @@ -178,3 +178,14 @@ PyTypeObject rpmtd_Type = { 0, /* tp_free */ 0, /* tp_is_gc */ }; + +int rpmtdFromPyObject(PyObject *obj, rpmtd *td) +{ + if (rpmtdObject_Check(obj)) { + *td = &(((rpmtdObject *)obj)->td); + return 1; + } else { + return 0; + } +} + diff --git a/python/rpmtd-py.h b/python/rpmtd-py.h index ac93b3a7a..4c95e89b4 100644 --- a/python/rpmtd-py.h +++ b/python/rpmtd-py.h @@ -5,6 +5,10 @@ typedef struct rpmtdObject_s rpmtdObject; extern PyTypeObject rpmtd_Type; +#define rpmtdObject_Check(v) ((v)->ob_type == &rpmtd_Type) + PyObject * rpmtd_AsPyobj(rpmtd td); +int rpmtdFromPyObject(PyObject *obj, rpmtd *td); + #endif