Add has_key() method to header object
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 23 Sep 2009 06:03:25 +0000 (09:03 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 23 Sep 2009 06:03:25 +0000 (09:03 +0300)
python/header-py.c

index 98d76d3..739f858 100644 (file)
@@ -265,6 +265,15 @@ static PyObject *hdrIsSource(hdrObject *s)
     return PyBool_FromLong(headerIsSource(s->h));
 }
 
+static PyObject *hdrHasKey(hdrObject *s, PyObject *pytag)
+{
+    rpmTag tag = tagNumFromPyObject(pytag);
+    if (tag == RPMTAG_NOT_FOUND) {
+       return NULL;
+    }
+    return PyBool_FromLong(headerIsEntry(s->h, tag));
+}
+
 static int hdr_compare(hdrObject * a, hdrObject * b)
 {
     return rpmVersionCompare(a->h, b->h);
@@ -286,6 +295,8 @@ static struct PyMethodDef hdr_methods[] = {
        NULL },
     {"fullFilelist",   (PyCFunction) hdrFullFilelist,  METH_NOARGS,
        NULL },
+    {"has_key",                (PyCFunction) hdrHasKey,        METH_O,
+       NULL },
     {"sprintf",                (PyCFunction) hdrSprintf,       METH_VARARGS|METH_KEYWORDS,
        NULL },
     {"isSource",       (PyCFunction)hdrIsSource,       METH_NOARGS,