summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-10-05 14:55:37 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-10-05 14:55:37 +0300
commit60ec5008bd6bc5f9cec43f64dd8129045080fa41 (patch)
tree3fde86f7519f95a612c01c17ba57673a88ce5dcb
parent0503d7f92e94a7986715756da5226fc18a1fba10 (diff)
downloadrpm-60ec5008bd6bc5f9cec43f64dd8129045080fa41.tar.gz
rpm-60ec5008bd6bc5f9cec43f64dd8129045080fa41.tar.bz2
rpm-60ec5008bd6bc5f9cec43f64dd8129045080fa41.zip
Push hdrCheck() error code handling over to python side
- return (rpmrc, message) tuple from C to let python do whatever it wishes with the information - let python side worry about generating backwards compatible returns
-rw-r--r--python/rpm/transaction.py10
-rw-r--r--python/rpmts-py.c33
2 files changed, 16 insertions, 27 deletions
diff --git a/python/rpm/transaction.py b/python/rpm/transaction.py
index c852b86b2..07a8db0fb 100644
--- a/python/rpm/transaction.py
+++ b/python/rpm/transaction.py
@@ -138,3 +138,13 @@ class TransactionSet(_rpm.ts):
res.append(((n, v, r),(needname,needver),needflags,sense,p.key))
return res
+
+ def hdrCheck(self, blob):
+ res, msg = _rpm.ts.hdrCheck(self, blob)
+ # generate backwards compatibly broken exceptions
+ if res == _rpm.RPMRC_NOKEY:
+ raise _rpm.error, "public key not availaiable"
+ elif res == _rpm.RPMRC_NOTTRUSTED:
+ raise _rpm.error, "public key not trusted"
+ elif res != _rpm.RPMRC_OK:
+ raise _rpm.error, msg
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
index 5d6bf8f4a..208de9a34 100644
--- a/python/rpmts-py.c
+++ b/python/rpmts-py.c
@@ -374,46 +374,25 @@ rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args, PyObject * kwds)
}
static PyObject *
-rpmts_HdrCheck(rpmtsObject * s, PyObject * args, PyObject * kwds)
+rpmts_HdrCheck(rpmtsObject * s, PyObject *obj)
{
PyObject * blob;
- PyObject * result = NULL;
char * msg = NULL;
const void * uh;
int uc;
rpmRC rpmrc;
- char * kwlist[] = {"headers", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "S:HdrCheck", kwlist, &blob))
+ if (!PyArg_Parse(obj, "S:HdrCheck", &blob))
return NULL;
uh = PyString_AsString(blob);
uc = PyString_Size(blob);
+ Py_BEGIN_ALLOW_THREADS;
rpmrc = headerCheck(s->ts, uh, uc, &msg);
+ Py_END_ALLOW_THREADS;
- switch (rpmrc) {
- case RPMRC_OK:
- Py_INCREF(Py_None);
- result = Py_None;
- break;
-
- case RPMRC_NOKEY:
- PyErr_SetString(pyrpmError, "public key not availaiable");
- break;
-
- case RPMRC_NOTTRUSTED:
- PyErr_SetString(pyrpmError, "public key not trusted");
- break;
-
- case RPMRC_FAIL:
- default:
- PyErr_SetString(pyrpmError, msg);
- break;
- }
- msg = _free(msg);
-
- return result;
+ return Py_BuildValue("(is)", rpmrc, msg);
}
static PyObject *
@@ -663,7 +642,7 @@ static struct PyMethodDef rpmts_methods[] = {
{"hdrFromFdno",(PyCFunction) rpmts_HdrFromFdno,METH_VARARGS|METH_KEYWORDS,
"ts.hdrFromFdno(fdno) -> hdr\n\
- Read a package header from a file descriptor.\n" },
- {"hdrCheck", (PyCFunction) rpmts_HdrCheck, METH_VARARGS|METH_KEYWORDS,
+ {"hdrCheck", (PyCFunction) rpmts_HdrCheck, METH_O,
NULL },
{"pgpPrtPkts", (PyCFunction) rpmts_PgpPrtPkts, METH_VARARGS|METH_KEYWORDS,
NULL },