summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/header-py.c21
-rw-r--r--python/header-py.h2
-rw-r--r--python/rpmds-py.c18
-rw-r--r--python/rpmfi-py.c4
-rw-r--r--python/rpmmi-py.c8
-rw-r--r--python/rpmte-py.c7
-rw-r--r--python/rpmts-py.c9
7 files changed, 23 insertions, 46 deletions
diff --git a/python/header-py.c b/python/header-py.c
index bf734d123..c84056d92 100644
--- a/python/header-py.c
+++ b/python/header-py.c
@@ -278,10 +278,9 @@ static PyObject *hdrIsSource(hdrObject *s)
static PyObject *hdrHasKey(hdrObject *s, PyObject *pytag)
{
- rpmTag tag = tagNumFromPyObject(pytag);
- if (tag == RPMTAG_NOT_FOUND) {
- return NULL;
- }
+ rpmTag tag;
+ if (!tagNumFromPyObject(pytag, &tag)) return NULL;
+
return PyBool_FromLong(headerIsEntry(s->h, tag));
}
@@ -410,7 +409,7 @@ static void hdr_dealloc(hdrObject * s)
PyObject_Del(s);
}
-rpmTag tagNumFromPyObject (PyObject *item)
+int tagNumFromPyObject (PyObject *item, rpmTag *tagp)
{
rpmTag tag = RPMTAG_NOT_FOUND;
@@ -419,12 +418,17 @@ rpmTag tagNumFromPyObject (PyObject *item)
tag = PyInt_AsLong(item);
} else if (PyString_Check(item)) {
tag = rpmTagGetValue(PyString_AsString(item));
+ } else {
+ PyErr_SetString(PyExc_TypeError, "expected a string or integer");
+ return 0;
}
if (tag == RPMTAG_NOT_FOUND) {
PyErr_SetString(PyExc_ValueError, "unknown header tag");
+ return 0;
}
-
- return tag;
+
+ *tagp = tag;
+ return 1;
}
static PyObject * hdr_subscript(hdrObject * s, PyObject * item)
@@ -438,8 +442,7 @@ static PyObject * hdr_subscript(hdrObject * s, PyObject * item)
int forceArray = 0;
struct rpmtd_s td;
- tag = tagNumFromPyObject (item);
- if (tag == RPMTAG_NOT_FOUND) return NULL;
+ if (!tagNumFromPyObject(item, &tag)) return NULL;
tagtype = rpmTagGetType(tag);
forceArray = (tagtype & RPM_MASK_RETURN_TYPE) == RPM_ARRAY_RETURN_TYPE;
diff --git a/python/header-py.h b/python/header-py.h
index 51f176b33..534e038b0 100644
--- a/python/header-py.h
+++ b/python/header-py.h
@@ -15,7 +15,7 @@ PyObject * hdr_Wrap(Header h);
Header hdrGetHeader(hdrObject * h);
-rpmTag tagNumFromPyObject (PyObject *item);
+int tagNumFromPyObject (PyObject *item, rpmTag *tagp);
PyObject * labelCompare (PyObject * self, PyObject * args);
PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds);
diff --git a/python/rpmds-py.c b/python/rpmds-py.c
index fe0e164a5..7514bdd24 100644
--- a/python/rpmds-py.c
+++ b/python/rpmds-py.c
@@ -428,20 +428,15 @@ static void rpmds_free(rpmdsObject * s)
static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
{
hdrObject * ho = NULL;
- PyObject * to = NULL;
rpmTag tagN = RPMTAG_REQUIRENAME;
rpmsenseFlags flags = 0;
rpmds ds = NULL;
char * kwlist[] = {"header", "tag", "flags", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Oi:rpmds_new", kwlist,
- &hdr_Type, &ho, &to, &flags))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|O&i:rpmds_new", kwlist,
+ &hdr_Type, &ho, tagNumFromPyObject, &tagN, &flags))
return NULL;
- if (to != NULL) {
- tagN = tagNumFromPyObject(to);
- if (tagN == RPMTAG_NOT_FOUND) return NULL;
- }
ds = rpmdsNew(hdrGetHeader(ho), tagN, 0);
return rpmds_Wrap(ds);
@@ -515,21 +510,16 @@ PyObject * rpmds_Wrap(rpmds ds)
PyObject * rpmds_Single(PyObject * s, PyObject * args, PyObject * kwds)
{
- PyObject * to = NULL;
rpmTag tagN = RPMTAG_PROVIDENAME;
const char * N;
const char * EVR = NULL;
rpmsenseFlags Flags = 0;
char * kwlist[] = {"to", "name", "evr", "flags", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "Os|si:Single", kwlist,
- &to, &N, &EVR, &Flags))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&s|si:Single", kwlist,
+ tagNumFromPyObject, &tagN, &N, &EVR, &Flags))
return NULL;
- if (to != NULL) {
- tagN = tagNumFromPyObject(to);
- if (tagN == RPMTAG_NOT_FOUND) return NULL;
- }
return rpmds_Wrap( rpmdsSingle(tagN, N, EVR, Flags) );
}
diff --git a/python/rpmfi-py.c b/python/rpmfi-py.c
index f1ab3a8de..673d40569 100644
--- a/python/rpmfi-py.c
+++ b/python/rpmfi-py.c
@@ -316,10 +316,6 @@ static PyObject * rpmfi_new(PyTypeObject * subtype, PyObject *args, PyObject *kw
&hdr_Type, &ho, &to, &flags))
return NULL;
- if (to != NULL) {
- tagN = tagNumFromPyObject(to);
- if (tagN == RPMTAG_NOT_FOUND) return NULL;
- }
fi = rpmfiNew(NULL, hdrGetHeader(ho), tagN, flags);
return rpmfi_Wrap(fi);
diff --git a/python/rpmmi-py.c b/python/rpmmi-py.c
index 7176844bb..5da2644ff 100644
--- a/python/rpmmi-py.c
+++ b/python/rpmmi-py.c
@@ -104,19 +104,15 @@ rpmmi_Count(rpmmiObject * s)
static PyObject *
rpmmi_Pattern(rpmmiObject * s, PyObject * args, PyObject * kwds)
{
- PyObject *TagN = NULL;
int type;
char * pattern;
rpmTag tag;
char * kwlist[] = {"tag", "type", "patern", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "Ois:Pattern", kwlist,
- &TagN, &type, &pattern))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&is:Pattern", kwlist,
+ tagNumFromPyObject, &tag, &type, &pattern))
return NULL;
- tag = tagNumFromPyObject (TagN);
- if (tag == RPMTAG_NOT_FOUND) return NULL;
-
rpmdbSetIteratorRE(s->mi, tag, type, pattern);
Py_RETURN_NONE;
diff --git a/python/rpmte-py.c b/python/rpmte-py.c
index f4b7d8139..3d1a3057c 100644
--- a/python/rpmte-py.c
+++ b/python/rpmte-py.c
@@ -175,17 +175,14 @@ rpmte_Key(rpmteObject * s)
static PyObject *
rpmte_DS(rpmteObject * s, PyObject * args, PyObject * kwds)
{
- PyObject * TagN = NULL;
rpmds ds;
rpmTag tag;
char * kwlist[] = {"tag", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:DS", kwlist, &TagN))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:DS", kwlist,
+ tagNumFromPyObject, &tag))
return NULL;
- tag = tagNumFromPyObject(TagN);
- if (tag == RPMTAG_NOT_FOUND) return NULL;
-
ds = rpmteDS(s->te, tag);
if (ds == NULL) {
#ifdef DYING
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
index 4f163c4a7..a80bbb934 100644
--- a/python/rpmts-py.c
+++ b/python/rpmts-py.c
@@ -874,7 +874,6 @@ spec_Parse(rpmtsObject * s, PyObject * args, PyObject * kwds)
static PyObject *
rpmts_Match(rpmtsObject * s, PyObject * args, PyObject * kwds)
{
- PyObject *TagN = NULL;
PyObject *Key = NULL;
char *key = NULL;
/* XXX lkey *must* be a 32 bit integer, int "works" on all known platforms. */
@@ -883,14 +882,10 @@ rpmts_Match(rpmtsObject * s, PyObject * args, PyObject * kwds)
rpmTag tag = RPMDBI_PACKAGES;
char * kwlist[] = {"tagNumber", "key", NULL};
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO:Match", kwlist,
- &TagN, &Key))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&O:Match", kwlist,
+ tagNumFromPyObject, &tag, &Key))
return NULL;
- if (TagN && (tag = tagNumFromPyObject (TagN)) == RPMTAG_NOT_FOUND) {
- return NULL;
- }
-
if (Key) {
if (PyString_Check(Key)) {
key = PyString_AsString(Key);