diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-09-23 12:05:02 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-09-23 12:05:02 +0300 |
commit | ac219c129d04952fbd205c536533723d582d1ad2 (patch) | |
tree | d1bdfa7e8653547a8634cec0507516cb97b3c005 /python | |
parent | e72a51d081b192cbc35af47f8281e939370f8b55 (diff) | |
download | librpm-tizen-ac219c129d04952fbd205c536533723d582d1ad2.tar.gz librpm-tizen-ac219c129d04952fbd205c536533723d582d1ad2.tar.bz2 librpm-tizen-ac219c129d04952fbd205c536533723d582d1ad2.zip |
Turn rpmFdFromPyObject() into an object converter interface
- permits direct validation and conversion from arg parsing
Diffstat (limited to 'python')
-rw-r--r-- | python/header-py.c | 14 | ||||
-rw-r--r-- | python/rpmfd-py.c | 9 | ||||
-rw-r--r-- | python/rpmfd-py.h | 2 | ||||
-rw-r--r-- | python/rpmts-py.c | 5 |
4 files changed, 14 insertions, 16 deletions
diff --git a/python/header-py.c b/python/header-py.c index ec6a325fe..bf734d123 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -298,17 +298,15 @@ static PyObject *hdrConvert(hdrObject *self, PyObject *args, PyObject *kwds) static PyObject * hdrWrite(hdrObject *s, PyObject *args, PyObject *kwds) { - PyObject *fo = NULL; char *kwlist[] = { "file", "magic", NULL }; int magic = 1; FD_t fd = NULL; int rc; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i", kwlist, &fo, &magic)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|i", kwlist, + rpmFdFromPyObject, &fd, &magic)) return NULL; - if ((fd = rpmFdFromPyObject(fo)) == NULL) return NULL; - Py_BEGIN_ALLOW_THREADS; rc = headerWrite(fd, s->h, magic ? HEADER_MAGIC_YES : HEADER_MAGIC_NO); Py_END_ALLOW_THREADS; @@ -388,7 +386,7 @@ static PyObject *hdr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds) h = headerCopy(hdrGetHeader((hdrObject*) obj)); } else if (PyString_Check(obj)) { h = headerCopyLoad(PyString_AsString(obj)); - } else if ((fd = rpmFdFromPyObject(obj)) != NULL) { + } else if (rpmFdFromPyObject(obj, &fd)) { Py_BEGIN_ALLOW_THREADS; h = headerRead(fd, HEADER_MAGIC_YES); Fclose(fd); @@ -673,15 +671,13 @@ PyObject * rpmReadHeaders (FD_t fd) PyObject * rpmHeaderFromFD(PyObject * self, PyObject * args, PyObject * kwds) { FD_t fd; - PyObject *fo; PyObject * list; char * kwlist[] = {"fd", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &fo)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&", kwlist, + rpmFdFromPyObject, &fd)) return NULL; - if ((fd = rpmFdFromPyObject(fo)) == NULL) return NULL; - list = rpmReadHeaders (fd); Fclose(fd); diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c index 2deb06793..868c293da 100644 --- a/python/rpmfd-py.c +++ b/python/rpmfd-py.c @@ -2,7 +2,7 @@ #include "rpmsystem-py.h" #include "rpmfd-py.h" -FD_t rpmFdFromPyObject(PyObject *obj) +int rpmFdFromPyObject(PyObject *obj, FD_t *fdp) { FD_t fd = NULL; @@ -13,10 +13,13 @@ FD_t rpmFdFromPyObject(PyObject *obj) fd = fdDup(fileno(fp)); } else { PyErr_SetString(PyExc_TypeError, "integer or file object expected"); - return NULL; + return 0; } if (fd == NULL || Ferror(fd)) { PyErr_SetFromErrno(PyExc_IOError); + Fclose(fd); + return 0; } - return fd; + *fdp = fd; + return 1; } diff --git a/python/rpmfd-py.h b/python/rpmfd-py.h index 2c7a51cac..2063fbfa5 100644 --- a/python/rpmfd-py.h +++ b/python/rpmfd-py.h @@ -3,6 +3,6 @@ #include <rpm/rpmio.h> -FD_t rpmFdFromPyObject(PyObject *obj); +int rpmFdFromPyObject(PyObject *obj, FD_t *fdp); #endif diff --git a/python/rpmts-py.c b/python/rpmts-py.c index 7824ba884..4f163c4a7 100644 --- a/python/rpmts-py.c +++ b/python/rpmts-py.c @@ -455,16 +455,15 @@ static PyObject * rpmts_HdrFromFdno(rpmtsObject * s, PyObject * args, PyObject * kwds) { PyObject * result = NULL; - PyObject * fo = NULL; Header h; FD_t fd; rpmRC rpmrc; char * kwlist[] = {"fd", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:HdrFromFdno", kwlist, &fo)) + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:HdrFromFdno", kwlist, + rpmFdFromPyObject, &fd)) return NULL; - if ((fd = rpmFdFromPyObject(fo)) == NULL) return NULL; rpmrc = rpmReadPackageFile(s->ts, fd, "rpmts_HdrFromFdno", &h); Fclose(fd); |