Use PyObject_AsFileDescriptor instead of PyFile_AsFile and fileno.
So that apr_file_from_object works under Win32.