summaryrefslogtreecommitdiff
path: root/python/apt_instmodule.cc
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-04-13 19:13:25 +0200
committerJulian Andres Klode <jak@debian.org>2009-04-13 19:13:25 +0200
commit62d7f4b80d56ef1e27039441cd6584cfb71d6502 (patch)
treeaa2d006fccd4a4f8497eb25dc0bd6c8baf6e6e89 /python/apt_instmodule.cc
parenteaefd2f4cb97ed069375f18fb67d8570dc5eaed8 (diff)
downloadpython-apt-62d7f4b80d56ef1e27039441cd6584cfb71d6502.tar.gz
* 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.
Diffstat (limited to 'python/apt_instmodule.cc')
-rw-r--r--python/apt_instmodule.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/python/apt_instmodule.cc b/python/apt_instmodule.cc
index 48868d86..a9d81be4 100644
--- a/python/apt_instmodule.cc
+++ b/python/apt_instmodule.cc
@@ -35,14 +35,17 @@ static PyObject *debExtractControl(PyObject *Self,PyObject *Args)
{
char *Member = "control";
PyObject *File;
- if (PyArg_ParseTuple(Args,"O!|s",&PyFile_Type,&File,&Member) == 0)
+ if (PyArg_ParseTuple(Args,"O|s",&File,&Member) == 0)
return 0;
// Subscope makes sure any clean up errors are properly handled.
PyObject *Res = 0;
{
// Open the file and associate the .deb
- FileFd Fd(fileno(PyFile_AsFile(File)),false);
+ int fileno = PyObject_AsFileDescriptor(File);
+ if (fileno == -1)
+ return 0;
+ FileFd Fd(fileno,false);
debDebFile Deb(Fd);
if (_error->PendingError() == true)
return HandleErrors();
@@ -76,7 +79,7 @@ static PyObject *debExtractArchive(PyObject *Self,PyObject *Args)
char *Rootdir = NULL;
char cwd[512];
PyObject *File;
- if (PyArg_ParseTuple(Args,"O!|s",&PyFile_Type,&File,&Rootdir) == 0)
+ if (PyArg_ParseTuple(Args,"O|s",&File,&Rootdir) == 0)
return 0;
// Subscope makes sure any clean up errors are properly handled.
@@ -89,7 +92,10 @@ static PyObject *debExtractArchive(PyObject *Self,PyObject *Args)
}
// Open the file and associate the .deb
- FileFd Fd(fileno(PyFile_AsFile(File)),false);
+ int fileno = PyObject_AsFileDescriptor(File);
+ if (fileno == -1)
+ return 0;
+ FileFd Fd(fileno,false);
debDebFile Deb(Fd);
if (_error->PendingError() == true) {
if (Rootdir != NULL)
@@ -118,11 +124,14 @@ static PyObject *arCheckMember(PyObject *Self,PyObject *Args)
char *Member = NULL;
bool res = false;
PyObject *File;
- if (PyArg_ParseTuple(Args,"O!s",&PyFile_Type,&File,&Member) == 0)
+ if (PyArg_ParseTuple(Args,"Os",&File,&Member) == 0)
return 0;
// Open the file and associate the .deb
- FileFd Fd(fileno(PyFile_AsFile(File)),false);
+ int fileno = PyObject_AsFileDescriptor(File);
+ if (fileno == -1)
+ return 0;
+ FileFd Fd(fileno,false);
ARArchive AR(Fd);
if (_error->PendingError() == true)
return HandleErrors(Py_BuildValue("b",res));