From 5e007f2258b845cfbe0a66bc8bf09eb9bdc2c9bc Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Thu, 21 Oct 2010 11:59:14 +0200 Subject: [PATCH] Fix Python bindings and raise KeyError when there is no index for the given tag --- lib/rpmdb.c | 2 +- python/rpmts-py.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 73ca89a..bdb6cee 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -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. */ diff --git a/python/rpmts-py.c b/python/rpmts-py.c index 13bb3aa..fb8f0c2 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -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; -- 2.7.4