diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-09-28 16:07:09 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-09-28 16:07:09 +0300 |
commit | 07710f3033b277ccb46decd84f994e88d5e6869a (patch) | |
tree | f964c7790b26c5a02e459017073a250893a2835d | |
parent | f0e9245660100d3ce41692889899844f42feb7a4 (diff) | |
download | rpm-07710f3033b277ccb46decd84f994e88d5e6869a.tar.gz rpm-07710f3033b277ccb46decd84f994e88d5e6869a.tar.bz2 rpm-07710f3033b277ccb46decd84f994e88d5e6869a.zip |
Implement rpm.readHeaderListFromFD() in python instead of C
-rw-r--r-- | python/header-py.c | 52 | ||||
-rw-r--r-- | python/header-py.h | 3 | ||||
-rw-r--r-- | python/rpm/__init__.py | 18 | ||||
-rw-r--r-- | python/rpmmodule.c | 2 |
4 files changed, 18 insertions, 57 deletions
diff --git a/python/header-py.c b/python/header-py.c index 755252eb3..8467cfd34 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -524,58 +524,6 @@ Header hdrGetHeader(hdrObject * s) return s->h; } -PyObject * rpmReadHeaders (FD_t fd) -{ - PyObject * list; - Header h; - PyObject * hdr; - - if (!fd) { - PyErr_SetFromErrno(pyrpmError); - return NULL; - } - - list = PyList_New(0); - Py_BEGIN_ALLOW_THREADS - h = headerRead(fd, HEADER_MAGIC_YES); - Py_END_ALLOW_THREADS - - while (h) { - headerConvert(h, HEADERCONV_RETROFIT_V3); - hdr = hdr_Wrap(&hdr_Type, h); - if (PyList_Append(list, (PyObject *) hdr)) { - Py_DECREF(list); - Py_DECREF(hdr); - return NULL; - } - Py_DECREF(hdr); - - h = headerFree(h); /* XXX ref held by hdr */ - - Py_BEGIN_ALLOW_THREADS - h = headerRead(fd, HEADER_MAGIC_YES); - Py_END_ALLOW_THREADS - } - - return list; -} - -PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds) -{ - FD_t fd; - PyObject * list; - char * kwlist[] = {"fd", NULL}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kwlist, - rpmFdFromPyObject, &fd)) - return NULL; - - list = rpmReadHeaders (fd); - Fclose(fd); - - return list; -} - /** * This assumes the order of list matches the order of the new headers, and * throws an exception if that isn't true. diff --git a/python/header-py.h b/python/header-py.h index 4c3d8abe1..faebc4823 100644 --- a/python/header-py.h +++ b/python/header-py.h @@ -26,10 +26,7 @@ PyObject * labelCompare (PyObject * self, PyObject * args); PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds); PyObject * rpmMergeHeadersFromFD(PyObject * self, PyObject * args, PyObject * kwds); int rpmMergeHeaders(PyObject * list, FD_t fd, int matchTag); -PyObject * rpmHeaderFromFile(PyObject * self, PyObject * args, PyObject * kwds); -PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds); PyObject * rpmSingleHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds); -PyObject * rpmReadHeaders (FD_t fd); PyObject * hdrLoad(PyObject * self, PyObject * args, PyObject * kwds); #endif diff --git a/python/rpm/__init__.py b/python/rpm/__init__.py index bbce2368b..f59dffa23 100644 --- a/python/rpm/__init__.py +++ b/python/rpm/__init__.py @@ -17,6 +17,24 @@ def headerLoad(*args, **kwds): warnings.warn("Use rpm.hdr() instead.", DeprecationWarning, stacklevel=2) return hdr(*args, **kwds) +def readHeaderListFromFD(fd, retrofit = True): + if hasattr(fd, "fileno"): + fdno = fd.fileno() + else: + fdno = fd + + hlist = [] + while 1: + try: + h = hdr(fdno) + if retrofit: + h.convert(HEADERCONV_RETROFIT_V3) + hlist.append(h) + except _rpm.error: + break + + return hlist + def readHeaderListFromFile(path): f = open(path) hlist = readHeaderListFromFD(f) diff --git a/python/rpmmodule.c b/python/rpmmodule.c index 4328fd4db..63e2e65b8 100644 --- a/python/rpmmodule.c +++ b/python/rpmmodule.c @@ -156,8 +156,6 @@ static PyMethodDef rpmModuleMethods[] = { { "mergeHeaderListFromFD", (PyCFunction) rpmMergeHeadersFromFD, METH_VARARGS|METH_KEYWORDS, NULL }, - { "readHeaderListFromFD", (PyCFunction) rpmHeaderFromFD, METH_VARARGS|METH_KEYWORDS, - NULL }, { "readHeaderFromFD", (PyCFunction) rpmSingleHeaderFromFD, METH_VARARGS|METH_KEYWORDS, NULL }, |