From 62d7f4b80d56ef1e27039441cd6584cfb71d6502 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Apr 2009 19:13:25 +0200 Subject: * python/*.cc: Use PyObject_AsFileDescriptor instead of fileno(PyFile_AsFile) Replace support for file objects with a more generic support for any object providing a fileno() method and for file descriptors (integers). This also helps us to port to Python 3, where the previously used PyFile_ functions are not available anymore. --- python/tag.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'python/tag.cc') diff --git a/python/tag.cc b/python/tag.cc index f3fb2e6c..baf97b59 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -272,11 +272,14 @@ char *doc_ParseTagFile = "ParseTagFile(File) -> TagFile"; PyObject *ParseTagFile(PyObject *self,PyObject *Args) { PyObject *File; - if (PyArg_ParseTuple(Args,"O!",&PyFile_Type,&File) == 0) + if (PyArg_ParseTuple(Args,"O",&File) == 0) + return 0; + int fileno = PyObject_AsFileDescriptor(File); + if (fileno == -1) return 0; TagFileData *New = PyObject_NEW(TagFileData,&TagFileType); - new (&New->Fd) FileFd(fileno(PyFile_AsFile(File)),false); + new (&New->Fd) FileFd(fileno,false); New->File = File; Py_INCREF(New->File); new (&New->Object) pkgTagFile(&New->Fd); -- cgit v1.2.3