2 * \file python/rpmtd-py.c
5 #include "rpmsystem-py.h"
7 #include <rpm/header.h>
12 * Convert single tag data item to python object of suitable type
14 PyObject * rpmtd_ItemAsPyobj(rpmtd td, rpmTagClass tclass)
19 case RPM_STRING_CLASS:
20 res = PyBytes_FromString(rpmtdGetString(td));
22 case RPM_NUMERIC_CLASS:
23 res = PyLong_FromLongLong(rpmtdGetNumber(td));
25 case RPM_BINARY_CLASS:
26 res = PyBytes_FromStringAndSize(td->data, td->count);
29 PyErr_SetString(PyExc_KeyError, "unknown data type");
35 PyObject *rpmtd_AsPyobj(rpmtd td)
38 int array = (rpmTagGetReturnType(td->tag) == RPM_ARRAY_RETURN_TYPE);
39 rpmTagClass tclass = rpmtdClass(td);
41 if (!array && rpmtdCount(td) < 1) {
47 res = PyList_New(rpmtdCount(td));
51 while ((ix = rpmtdNext(td)) >= 0) {
52 PyObject *item = rpmtd_ItemAsPyobj(td, tclass);
57 PyList_SET_ITEM(res, ix, item);
60 res = rpmtd_ItemAsPyobj(td, tclass);