Py_RETURN_NONE;
}
-PyObject *
-rpmSingleHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds)
-{
- FD_t fd;
- int fileno;
- off_t offset;
- PyObject * tuple;
- Header h;
- char * kwlist[] = {"fd", NULL};
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &fileno))
- return NULL;
-
- offset = lseek(fileno, 0, SEEK_CUR);
-
- fd = fdDup(fileno);
-
- if (!fd) {
- PyErr_SetFromErrno(pyrpmError);
- return NULL;
- }
-
- Py_BEGIN_ALLOW_THREADS
- h = headerRead(fd, HEADER_MAGIC_YES);
- Py_END_ALLOW_THREADS
-
- Fclose(fd);
-
- tuple = PyTuple_New(2);
-
- if (h && tuple) {
- PyTuple_SET_ITEM(tuple, 0, hdr_Wrap(&hdr_Type, h));
- PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(offset));
- h = headerFree(h);
- } else {
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- PyTuple_SET_ITEM(tuple, 0, Py_None);
- PyTuple_SET_ITEM(tuple, 1, Py_None);
- }
-
- return tuple;
-}
-
PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds)
{
hdrObject * h1, * h2;
"""
import warnings
+import os
from _rpm import *
import _rpm
warnings.warn("Use rpm.hdr() instead.", DeprecationWarning, stacklevel=2)
return hdr(*args, **kwds)
-def readHeaderListFromFD(fd, retrofit = True):
+def _fdno(fd):
if hasattr(fd, "fileno"):
- fdno = fd.fileno()
+ return fd.fileno()
else:
- fdno = fd
+ return fd
+def readHeaderListFromFD(fd, retrofit = True):
+ fdno = _fdno(fd)
hlist = []
while 1:
try:
f.close()
return hlist
+def readHeaderFromFD(fd):
+ fdno = _fdno(fd)
+ offset = os.lseek(fdno, 0, os.SEEK_CUR)
+ try:
+ h = hdr(fdno)
+ except _rpm.error:
+ h = None
+ offset = None
+
+ return (h, offset)
{ "mergeHeaderListFromFD", (PyCFunction) rpmMergeHeadersFromFD, METH_VARARGS|METH_KEYWORDS,
NULL },
- { "readHeaderFromFD", (PyCFunction) rpmSingleHeaderFromFD, METH_VARARGS|METH_KEYWORDS,
- NULL },
{ "setLogFile", (PyCFunction) setLogFile, METH_VARARGS|METH_KEYWORDS,
NULL },