diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-10-28 15:55:35 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-10-28 15:55:35 +0200 |
commit | a5e123bc3e07fa6cc3fad13bc7f8a471ecb17d9b (patch) | |
tree | acc2bc3bf4182a92e4c8282618ba04c3d6489a9f /python/rpmfd-py.c | |
parent | 590914c32c1d514d1a4e5c2244e1e38548a2e87d (diff) | |
download | librpm-tizen-a5e123bc3e07fa6cc3fad13bc7f8a471ecb17d9b.tar.gz librpm-tizen-a5e123bc3e07fa6cc3fad13bc7f8a471ecb17d9b.tar.bz2 librpm-tizen-a5e123bc3e07fa6cc3fad13bc7f8a471ecb17d9b.zip |
Use PyObject_AsFileDescriptor() instead of object type comparison
- this permits any file-like object implementing .fileno() method
(including rpm.fd) to be dup'ed, not just PyFile subtypes
- this also avoids yet another incompatibility with Python 3 which doesn't
have PyFile_Check() and PyFile_AsFile() at all
Diffstat (limited to 'python/rpmfd-py.c')
-rw-r--r-- | python/rpmfd-py.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c index 8b0da0e6e..5c50a4f63 100644 --- a/python/rpmfd-py.c +++ b/python/rpmfd-py.c @@ -51,6 +51,7 @@ static PyObject *rpmfd_new(PyTypeObject *subtype, PyObject *fo = NULL; rpmfdObject *s = NULL; FD_t fd = NULL; + int fdno; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|ss", kwlist, &fo, &mode, &flags)) @@ -62,11 +63,8 @@ static PyObject *rpmfd_new(PyTypeObject *subtype, fd = Fopen(PyBytes_AsString(fo), m); Py_END_ALLOW_THREADS free(m); - } else if (PyInt_Check(fo)) { - fd = fdDup(PyInt_AsLong(fo)); - } else if (PyFile_Check(fo)) { - FILE *fp = PyFile_AsFile(fo); - fd = fdDup(fileno(fp)); + } else if ((fdno = PyObject_AsFileDescriptor(fo)) >= 0) { + fd = fdDup(fdno); } else { PyErr_SetString(PyExc_TypeError, "path or file object expected"); return NULL; |