summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2009-09-23 11:09:19 +0300
committerPanu Matilainen <pmatilai@redhat.com>2009-09-23 11:09:19 +0300
commit79e87e5ea16ed7118536b12e267d93db74e15265 (patch)
tree19a9e5a20992926fa213c9133c7dc5e952a55c89
parent6b9adb71f9715de3648673ae6ca4475a9e98d141 (diff)
downloadrpm-79e87e5ea16ed7118536b12e267d93db74e15265.tar.gz
rpm-79e87e5ea16ed7118536b12e267d93db74e15265.tar.bz2
rpm-79e87e5ea16ed7118536b12e267d93db74e15265.zip
Add helper to convert python file objects to rpmio FD_t type
-rw-r--r--python/Makefile.am1
-rw-r--r--python/rpmfd-py.c22
-rw-r--r--python/rpmfd-py.h8
3 files changed, 31 insertions, 0 deletions
diff --git a/python/Makefile.am b/python/Makefile.am
index 6f324e4a8..8d763ed12 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -21,6 +21,7 @@ _rpmmodule_la_LIBADD = \
_rpmmodule_la_SOURCES = rpmmodule.c rpmsystem-py.h \
header-py.c header-py.h \
rpmds-py.c rpmds-py.h \
+ rpmfd-py.c rpmfd-py.h \
rpmfi-py.c rpmfi-py.h \
rpmmi-py.c rpmmi-py.h \
rpmps-py.c rpmps-py.h \
diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c
new file mode 100644
index 000000000..2deb06793
--- /dev/null
+++ b/python/rpmfd-py.c
@@ -0,0 +1,22 @@
+
+#include "rpmsystem-py.h"
+#include "rpmfd-py.h"
+
+FD_t rpmFdFromPyObject(PyObject *obj)
+{
+ FD_t fd = NULL;
+
+ if (PyInt_Check(obj)) {
+ fd = fdDup(PyInt_AsLong(obj));
+ } else if (PyFile_Check(obj)) {
+ FILE *fp = PyFile_AsFile(obj);
+ fd = fdDup(fileno(fp));
+ } else {
+ PyErr_SetString(PyExc_TypeError, "integer or file object expected");
+ return NULL;
+ }
+ if (fd == NULL || Ferror(fd)) {
+ PyErr_SetFromErrno(PyExc_IOError);
+ }
+ return fd;
+}
diff --git a/python/rpmfd-py.h b/python/rpmfd-py.h
new file mode 100644
index 000000000..2c7a51cac
--- /dev/null
+++ b/python/rpmfd-py.h
@@ -0,0 +1,8 @@
+#ifndef H_RPMFD_PY
+#define H_RPMFD_PY
+
+#include <rpm/rpmio.h>
+
+FD_t rpmFdFromPyObject(PyObject *obj);
+
+#endif