summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-09-30 14:51:33 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-09-30 14:51:33 +0300
commit32b0bba8a2fb5e534bddc9c02ff170726457bdcc (patch)
treecb7baaf043c38150cd8f6e778c4e02cdb1b082d6 /python
parent3d5455d42d48740ff23899f00a903f49b73eff00 (diff)
downloadrpm-32b0bba8a2fb5e534bddc9c02ff170726457bdcc.tar.gz
rpm-32b0bba8a2fb5e534bddc9c02ff170726457bdcc.tar.bz2
rpm-32b0bba8a2fb5e534bddc9c02ff170726457bdcc.zip
Add iterator support to python header objects
Diffstat (limited to 'python')
-rw-r--r--python/header-py.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/python/header-py.c b/python/header-py.c
index 32ec7bd1b..a2c71a689 100644
--- a/python/header-py.c
+++ b/python/header-py.c
@@ -129,7 +129,8 @@
struct hdrObject_s {
PyObject_HEAD
Header h;
-} ;
+ HeaderIterator hi;
+};
static PyObject * hdrKeyList(hdrObject * s)
{
@@ -405,6 +406,23 @@ static void hdr_dealloc(hdrObject * s)
s->ob_type->tp_free((PyObject *)s);
}
+static PyObject * hdr_iternext(hdrObject *s)
+{
+ PyObject *res = NULL;
+ rpmTag tag;
+
+ if (s->hi == NULL) s->hi = headerInitIterator(s->h);
+
+ if ((tag = headerNextTag(s->hi)) != RPMTAG_NOT_FOUND) {
+ int raw = 1;
+ res = PyObject_Call((PyObject *) &rpmtd_Type,
+ Py_BuildValue("(Oii)", s, tag, raw), NULL);
+ } else {
+ s->hi = headerFreeIterator(s->hi);
+ }
+ return res;
+}
+
int tagNumFromPyObject (PyObject *item, rpmTag *tagp)
{
rpmTag tag = RPMTAG_NOT_FOUND;
@@ -501,8 +519,8 @@ PyTypeObject hdr_Type = {
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
+ PyObject_SelfIter, /* tp_iter */
+ hdr_iternext, /* tp_iternext */
hdr_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */