From: Florian Festi Date: Thu, 21 Oct 2010 09:59:14 +0000 (+0200) Subject: Fix Python bindings and raise KeyError when there is no index for the given tag X-Git-Tag: rpm-4.9.0-beta1~172 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e007f2258b845cfbe0a66bc8bf09eb9bdc2c9bc;p=platform%2Fupstream%2Frpm.git Fix Python bindings and raise KeyError when there is no index for the given tag --- 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;