Skip to content

Commit

Permalink
PyFile_AsFile() doesn't exist in Python3
Browse files Browse the repository at this point in the history
  • Loading branch information
jpopelka committed Nov 4, 2013
1 parent 1cbb91f commit e8b9024
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cupsconnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,10 +2156,14 @@ Connection_getFile (Connection *self, PyObject *args, PyObject *kwds)
return NULL;
}

#if PY_MAJOR_VERSION >= 3
fd = PyObject_AsFileDescriptor(fileobj);
#else
if (fileobj) {
FILE *f = PyFile_AsFile (fileobj);
fd = fileno (f);
}
#endif

if (filename) {
debugprintf ("-> Connection_getFile(%s, %s)\n", resource, filename);
Expand Down Expand Up @@ -2205,10 +2209,14 @@ Connection_putFile (Connection *self, PyObject *args, PyObject *kwds)
return NULL;
}

#if PY_MAJOR_VERSION >= 3
fd = PyObject_AsFileDescriptor(fileobj);
#else
if (fileobj) {
FILE *f = PyFile_AsFile (fileobj);
fd = fileno (f);
}
#endif

if (filename) {
debugprintf ("-> Connection_putFile(%s, %s)\n", resource, filename);
Expand Down
20 changes: 20 additions & 0 deletions cupsppd.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,12 @@ PPD_emit (PPD *self, PyObject *args)
if (!PyArg_ParseTuple (args, "Oi", &pyFile, &section))
return NULL;

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;

Expand All @@ -655,7 +660,12 @@ PPD_emitAfterOrder (PPD *self, PyObject *args)
if (!PyArg_ParseTuple (args, "Oiif", &pyFile, &section, &limit, &min_order))
return NULL;

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;

Expand Down Expand Up @@ -708,7 +718,12 @@ PPD_emitJCL (PPD *self, PyObject *args)
return NULL;
}

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;

Expand All @@ -733,7 +748,12 @@ PPD_emitJCLEnd (PPD *self, PyObject *args)
if (!PyArg_ParseTuple (args, "O", &pyFile))
return NULL;

#if PY_MAJOR_VERSION >= 3
int fd = PyObject_AsFileDescriptor(pyFile);
f = fdopen(fd, "a+");
#else
f = PyFile_AsFile(pyFile);
#endif
if (!f)
return NULL;

Expand Down

0 comments on commit e8b9024

Please sign in to comment.