Fix Python bindings and raise KeyError when there is no index for the given tag
authorFlorian Festi <ffesti@redhat.com>
Thu, 21 Oct 2010 09:59:14 +0000 (11:59 +0200)
committerFlorian Festi <ffesti@redhat.com>
Thu, 21 Oct 2010 09:59:14 +0000 (11:59 +0200)
lib/rpmdb.c
python/rpmts-py.c

index 73ca89a..bdb6cee 100644 (file)
@@ -2277,7 +2277,7 @@ rpmdbKeyIterator rpmdbKeyIteratorInit(rpmdb db, rpmTag rpmtag)
     (void) rpmdbCheckSignals();
 
     rc = dbiOpen(db, rpmtag, &dbi, 0);
-    if (dbi == NULL)
+    if (rc || dbi == NULL)
        return NULL;
 
     /* Chain cursors for teardown on abnormal exit. */
index 13bb3aa..fb8f0c2 100644 (file)
@@ -634,7 +634,7 @@ rpmts_Keys(rpmtsObject * s, PyObject * args, PyObject * kwds)
 {
     rpmTag tag;
     PyObject *mio = NULL;
-    char * kwlist[] = {"tag", "pattern", "type", NULL};
+    char * kwlist[] = {"tag", NULL};
 
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:Keys", kwlist,
               tagNumFromPyObject, &tag))
@@ -649,7 +649,12 @@ rpmts_Keys(rpmtsObject * s, PyObject * args, PyObject * kwds)
        }
     }
 
-    mio = rpmki_Wrap(&rpmki_Type, rpmdbKeyIteratorInit(rpmtsGetRdb(s->ts), tag), (PyObject*)s);
+    rpmdbKeyIterator ki = rpmdbKeyIteratorInit(rpmtsGetRdb(s->ts), tag);
+    if (ki == NULL) {
+        PyErr_SetString(PyExc_KeyError, "No index for this tag");
+        return NULL;
+    }
+    mio = rpmki_Wrap(&rpmki_Type, ki, (PyObject*)s);
 
 exit:
     return mio;