From ca4408170dd5d2a6bba176409e0f0af1156357a6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Thu, 25 Jun 2009 17:37:23 +0200 Subject: python/cache.cc: Support unicode objects and str objects in Python 2. --- python/generic.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'python/generic.cc') diff --git a/python/generic.cc b/python/generic.cc index 7309d978..51439a1b 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -25,8 +25,9 @@ PyObject *HandleErrors(PyObject *Res) return Res; } - if (Res != 0) + if (Res != 0) { Py_DECREF(Res); + } string Err; int errcnt = 0; -- cgit v1.2.3 From b2a1af65654e4584d6b54c5d4e12175ff0dffad9 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Tue, 2 Feb 2010 17:19:25 +0100 Subject: Remove inline functions from the C++ API, export them instead (part 2). --- python/acquire.cc | 2 +- python/apt_pkgmodule.cc | 36 +++++++++++-- python/apt_pkgmodule.h | 42 ++++++++++++++- python/configuration.cc | 8 +-- python/generic.cc | 2 + python/indexrecords.cc | 2 +- python/python-apt-helpers.cc | 68 ++++++++++++++++++++++++ python/python-apt.h | 124 +++++++++++++++++++++++-------------------- setup.py | 2 +- 9 files changed, 217 insertions(+), 69 deletions(-) create mode 100644 python/python-apt-helpers.cc (limited to 'python/generic.cc') diff --git a/python/acquire.cc b/python/acquire.cc index cd7f7709..04e00b02 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -255,7 +255,7 @@ static PyObject *PkgAcquireGetWorkers(PyObject *self, void *closure) { PyObject *List = PyList_New(0); pkgAcquire *Owner = GetCpp(self); - CppPyObject *PyWorker = NULL; + PyObject *PyWorker = NULL; for (pkgAcquire::Worker *Worker = Owner->WorkersBegin(); Worker != 0; Worker = Owner->WorkerStep(Worker)) { PyWorker = PyAcquireWorker_FromCpp(Worker, false, self); diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index d2472395..e3da1820 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -529,64 +529,94 @@ static struct _PyAptPkgAPIStruct API = { &PyAcquire_FromCpp, // acquire_fromcpp &PyAcquire_ToCpp, // acquire_tocpp &PyAcquireFile_Type, // acquirefile_type + &PyAcquireFile_FromCpp, // acquirefile_fromcpp &PyAcquireFile_ToCpp, // acquirefile_tocpp &PyAcquireItem_Type, // acquireitem_type + &PyAcquireItem_FromCpp, // acquireitem_fromcpp &PyAcquireItem_ToCpp, // acquireitem_type &PyAcquireItemDesc_Type, // acquireitemdesc_type + &PyAcquireItemDesc_FromCpp,// acquireitemdesc_fromcpp &PyAcquireItemDesc_ToCpp, // acquireitemdesc_tocpp &PyAcquireWorker_Type, // acquireworker_type + &PyAcquireWorker_FromCpp, // acquireworker_fromcpp &PyAcquireWorker_ToCpp, // acquireworker_tocpp &PyActionGroup_Type, // actiongroup_type - &PyActionGroup_ToCpp, // actiongroup_type + &PyActionGroup_FromCpp, // actiongroup_fromcpp + &PyActionGroup_ToCpp, // actiongroup_tocpp &PyCache_Type, // cache_type + &PyCache_FromCpp, // cache_fromcpp &PyCache_ToCpp, // cache_tocpp &PyCacheFile_Type, // cachefile_type + &PyCacheFile_FromCpp, // cachefile_fromcpp &PyCacheFile_ToCpp, // cachefile_tocpp &PyCdrom_Type, // cdrom_type + &PyCdrom_FromCpp, // cdrom_fromcpp &PyCdrom_ToCpp, // cdrom_tocpp &PyConfiguration_Type, // configuration_type + &PyConfiguration_FromCpp, // configuration_fromcpp &PyConfiguration_ToCpp, // configuration_tocpp &PyDepCache_Type, // depcache_type + &PyDepCache_FromCpp, // depcache_fromcpp &PyDepCache_ToCpp, // depcache_tocpp &PyDependency_Type, // dependency_type - &PyDependency_ToCpp, // dependency_type + &PyDependency_FromCpp, // dependency_fromcpp + &PyDependency_ToCpp, // dependency_tocpp &PyDependencyList_Type, // dependencylist_type + 0, // FIXME: dependencylist_fromcpp 0, // FIXME: dependencylist_tocpp &PyDescription_Type, // description_type + &PyDescription_FromCpp, // description_fromcpp &PyDescription_ToCpp, // description_tocpp &PyHashes_Type, // hashes_type + &PyHashes_FromCpp, // hashes_fromcpp &PyHashes_ToCpp, // hashes_tocpp &PyHashString_Type, // hashstring_type + &PyHashString_FromCpp, // hashstring_fromcpp &PyHashString_ToCpp, // hashstring_tocpp &PyIndexRecords_Type, // indexrecords_type + &PyIndexRecords_FromCpp, // indexrecords_tocpp &PyIndexRecords_ToCpp, // indexrecords_tocpp &PyMetaIndex_Type, // metaindex_type + &PyMetaIndex_FromCpp, // metaindex_tocpp &PyMetaIndex_ToCpp, // metaindex_tocpp &PyPackage_Type, // package_type + &PyPackage_FromCpp, // package_tocpp &PyPackage_ToCpp, // package_tocpp &PyPackageFile_Type, // packagefile_type + &PyPackageFile_FromCpp, // packagefile_tocpp &PyPackageFile_ToCpp, // packagefile_tocpp &PyIndexFile_Type, // packageindexfile_type + &PyIndexFile_FromCpp, // packageindexfile_tocpp &PyIndexFile_ToCpp, // packageindexfile_tocpp &PyPackageList_Type, // packagelist_type + 0, // FIXME: packagelist_fromcpp 0, // FIXME: packagelist_tocpp &PyPackageManager_Type, // packagemanager_type + &PyPackageManager_FromCpp, // packagemanager_type &PyPackageManager_ToCpp, // packagemanager_type &PyPackageRecords_Type, // packagerecords_type + 0, // FIXME: packagerecords_fromcpp 0, // FIXME: packagerecords_tocpp &PyPolicy_Type, // policy_type + &PyPolicy_FromCpp, // policy_tocpp &PyPolicy_ToCpp, // policy_tocpp &PyProblemResolver_Type, // problemresolver_type + &PyProblemResolver_FromCpp, // problemresolver_tocpp &PyProblemResolver_ToCpp, // problemresolver_tocpp &PySourceList_Type, // sourcelist_type + &PySourceList_FromCpp, // sourcelist_tocpp &PySourceList_ToCpp, // sourcelist_tocpp &PySourceRecords_Type, // sourcerecords_type - 0, // sourcerecords_tocpp + 0, // FIXME: sourcerecords_fromcpp + 0, // FIXME: sourcerecords_tocpp &PyTagFile_Type, // tagfile_type + &PyTagFile_FromCpp, // tagfile_tocpp &PyTagFile_ToCpp, // tagfile_tocpp &PyTagSection_Type, // tagsection_type + &PyTagSection_FromCpp, // tagsection_tocpp &PyTagSection_ToCpp, // tagsection_tocpp &PyVersion_Type, // version_type + &PyVersion_FromCpp, // version_tocpp &PyVersion_ToCpp, // version_tocpp }; diff --git a/python/apt_pkgmodule.h b/python/apt_pkgmodule.h index a22a25f0..3dcf8069 100644 --- a/python/apt_pkgmodule.h +++ b/python/apt_pkgmodule.h @@ -13,10 +13,20 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "generic.h" // Configuration Stuff -#define Configuration_Check(op) ((op)->ob_type == &PyConfiguration_Type) extern PyTypeObject PyConfiguration_Type; extern PyTypeObject PyVersion_Type; @@ -157,6 +167,36 @@ PyObject *PyAcquire_FromCpp(pkgAcquire *fetcher, bool Delete); # define PyTagSection_ToCpp GetCpp # define PyVersion_ToCpp GetCpp +PyObject* PyAcquireFile_FromCpp(pkgAcqFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireItem_FromCpp(pkgAcquire::Item* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireItemDesc_FromCpp(pkgAcquire::ItemDesc* const &obj, bool Delete, PyObject *Owner); +PyObject* PyAcquireWorker_FromCpp(pkgAcquire::Worker* const &obj, bool Delete, PyObject *Owner); +PyObject* PyActionGroup_FromCpp(pkgDepCache::ActionGroup* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCache_FromCpp(pkgCache* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCacheFile_FromCpp(pkgCacheFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyCdrom_FromCpp(pkgCdrom const &obj, bool Delete, PyObject *Owner); +PyObject* PyConfiguration_FromCpp(Configuration* const &obj, bool Delete, PyObject *Owner); +PyObject* PyDepCache_FromCpp(pkgDepCache* const &obj, bool Delete, PyObject *Owner); +PyObject* PyDependency_FromCpp(pkgCache::DepIterator const &obj, bool Delete, PyObject *Owner); +//PyObject* PyDependencyList_FromCpp(RDepListStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyDescription_FromCpp(pkgCache::DescIterator const &obj, bool Delete, PyObject *Owner); +PyObject* PyHashes_FromCpp(Hashes const &obj, bool Delete, PyObject *Owner); +PyObject* PyHashString_FromCpp(HashString* const &obj, bool Delete, PyObject *Owner); +PyObject* PyIndexRecords_FromCpp(indexRecords* const &obj, bool Delete, PyObject *Owner); +PyObject* PyMetaIndex_FromCpp(metaIndex* const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackage_FromCpp(pkgCache::PkgIterator const &obj, bool Delete, PyObject *Owner); +PyObject* PyIndexFile_FromCpp(pkgIndexFile* const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackageFile_FromCpp(pkgCache::PkgFileIterator const &obj, bool Delete, PyObject *Owner); +//PyObject* PyPackageList_FromCpp(PkgListStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyPackageManager_FromCpp(pkgPackageManager* const &obj, bool Delete, PyObject *Owner); +//PyObject* PyPackageRecords_FromCpp(PkgRecordsStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyPolicy_FromCpp(pkgPolicy* const &obj, bool Delete, PyObject *Owner); +PyObject* PyProblemResolver_FromCpp(pkgProblemResolver* const &obj, bool Delete, PyObject *Owner); +PyObject* PySourceList_FromCpp(pkgSourceList* const &obj, bool Delete, PyObject *Owner); +//PyObject* PySourceRecords_FromCpp(PkgSrcRecordsStruct const &obj, bool Delete, PyObject *Owner); +PyObject* PyTagFile_FromCpp(pkgTagFile const &obj, bool Delete, PyObject *Owner); +PyObject* PyTagSection_FromCpp(pkgTagSection const &obj, bool Delete, PyObject *Owner); +PyObject* PyVersion_FromCpp(pkgCache::VerIterator const &obj, bool Delete, PyObject *Owner); #include "python-apt.h" #endif diff --git a/python/configuration.cc b/python/configuration.cc index 0cad8db3..974f6f3d 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -280,7 +280,7 @@ PyObject *LoadConfig(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -298,7 +298,7 @@ PyObject *LoadConfigISC(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -316,7 +316,7 @@ PyObject *LoadConfigDir(PyObject *Self,PyObject *Args) char *Name = 0; if (PyArg_ParseTuple(Args,"Os",&Self,&Name) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; @@ -348,7 +348,7 @@ PyObject *ParseCommandLine(PyObject *Self,PyObject *Args) if (PyArg_ParseTuple(Args,"OO!O!",&Self, &PyList_Type,&POList,&PyList_Type,&Pargv) == 0) return 0; - if (Configuration_Check(Self)== 0) + if (PyConfiguration_Check(Self)== 0) { PyErr_SetString(PyExc_TypeError,"argument 1: expected Configuration."); return 0; diff --git a/python/generic.cc b/python/generic.cc index 51439a1b..640f0862 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -9,6 +9,8 @@ /*}}}*/ // Include Files /*{{{*/ #include "generic.h" +using namespace std; + #include /*}}}*/ diff --git a/python/indexrecords.cc b/python/indexrecords.cc index 5750bf6b..80960160 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -60,7 +60,7 @@ static PyObject *indexrecords_lookup(PyObject *self,PyObject *args) } // Copy the HashString(), to prevent crashes and to not require the // indexRecords object to exist. - PyObject *py_hash = PyHashString_FromCpp(new HashString(result->Hash)); + PyObject *py_hash = PyHashString_FromCpp(new HashString(result->Hash), true, NULL); PyObject *value = Py_BuildValue("(Oi)",py_hash,result->Size); Py_DECREF(py_hash); return value; diff --git a/python/python-apt-helpers.cc b/python/python-apt-helpers.cc new file mode 100644 index 00000000..7a0f20c4 --- /dev/null +++ b/python/python-apt-helpers.cc @@ -0,0 +1,68 @@ +/* + * python-apt.h - Common object creation functions for the public API + * + * Copyright 2010 Julian Andres Klode + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include "apt_pkgmodule.h" + +/** + * Short macro to be used for the generic FromCpp functions. + * + */ +#define NEW_FROM(NAME,TYPE,Cpp) \ +PyObject* NAME(Cpp const &obj, bool Delete, PyObject *Owner) \ +{ \ + CppPyObject *Obj = CppPyObject_NEW(Owner, TYPE, obj); \ + Obj->NoDelete = (!Delete); \ + return Obj; \ +} + +// Create all those functions +NEW_FROM(PyAcquireFile_FromCpp,&PyAcquireFile_Type,pkgAcqFile*) +NEW_FROM(PyAcquireItem_FromCpp,&PyAcquireItem_Type,pkgAcquire::Item*) +NEW_FROM(PyAcquireItemDesc_FromCpp,&PyAcquireItemDesc_Type,pkgAcquire::ItemDesc*) +NEW_FROM(PyAcquireWorker_FromCpp,&PyAcquireWorker_Type,pkgAcquire::Worker*) +NEW_FROM(PyActionGroup_FromCpp,&PyActionGroup_Type,pkgDepCache::ActionGroup*) +NEW_FROM(PyCache_FromCpp,&PyCache_Type,pkgCache*) +NEW_FROM(PyCacheFile_FromCpp,&PyCacheFile_Type,pkgCacheFile*) +NEW_FROM(PyCdrom_FromCpp,&PyCdrom_Type,pkgCdrom) +NEW_FROM(PyConfiguration_FromCpp,&PyConfiguration_Type,Configuration*) +NEW_FROM(PyDepCache_FromCpp,&PyDepCache_Type,pkgDepCache*) +NEW_FROM(PyDependency_FromCpp,&PyDependency_Type,pkgCache::DepIterator) +//NEW_FROM(PyDependencyList_FromCpp,&PyDependencyList_Type,RDepListStruct) +NEW_FROM(PyDescription_FromCpp,&PyDescription_Type,pkgCache::DescIterator) +NEW_FROM(PyHashes_FromCpp,&PyHashes_Type,Hashes) +NEW_FROM(PyHashString_FromCpp,&PyHashString_Type,HashString*) +NEW_FROM(PyIndexRecords_FromCpp,&PyIndexRecords_Type,indexRecords*) +NEW_FROM(PyMetaIndex_FromCpp,&PyMetaIndex_Type,metaIndex*) +NEW_FROM(PyPackage_FromCpp,&PyPackage_Type,pkgCache::PkgIterator) +NEW_FROM(PyIndexFile_FromCpp,&PyIndexFile_Type,pkgIndexFile*) +NEW_FROM(PyPackageFile_FromCpp,&PyPackageFile_Type,pkgCache::PkgFileIterator) +//NEW_FROM(PyPackageList_FromCpp,&PyPackageList_Type,PkgListStruct) +NEW_FROM(PyPackageManager_FromCpp,&PyPackageManager_Type,pkgPackageManager*) +//NEW_FROM(PyPackageRecords_FromCpp,&PyPackageRecords_Type,PkgRecordsStruct) +NEW_FROM(PyPolicy_FromCpp,&PyPolicy_Type,pkgPolicy*) +NEW_FROM(PyProblemResolver_FromCpp,&PyProblemResolver_Type,pkgProblemResolver*) +NEW_FROM(PySourceList_FromCpp,&PySourceList_Type,pkgSourceList*) +//NEW_FROM(PySourceRecords_FromCpp,&PySourceRecords_Type,PkgSrcRecordsStruct) +NEW_FROM(PyTagFile_FromCpp,&PyTagFile_Type,pkgTagFile) +NEW_FROM(PyTagSection_FromCpp,&PyTagSection_Type,pkgTagSection) +NEW_FROM(PyVersion_FromCpp,&PyVersion_Type,pkgCache::VerIterator) + +#undef NEW_FROM diff --git a/python/python-apt.h b/python/python-apt.h index 7b34c249..0c25ff02 100644 --- a/python/python-apt.h +++ b/python/python-apt.h @@ -47,94 +47,126 @@ struct _PyAptPkgAPIStruct { pkgAcquire*& (*acquire_tocpp)(PyObject *self); // apt_pkg.AcquireFile PyTypeObject *acquirefile_type; + PyObject* (*acquirefile_fromcpp)(pkgAcqFile* const &obj, bool Delete, PyObject *Owner); pkgAcqFile*& (*acquirefile_tocpp)(PyObject *self); + // apt_pkg.AcquireItem PyTypeObject *acquireitem_type; + PyObject* (*acquireitem_fromcpp)(pkgAcquire::Item* const &obj, bool Delete, PyObject *Owner); pkgAcquire::Item*& (*acquireitem_tocpp)(PyObject *self); // apt_pkg.AcquireItemDesc PyTypeObject *acquireitemdesc_type; + PyObject* (*acquireitemdesc_fromcpp)(pkgAcquire::ItemDesc* const &obj, bool Delete, PyObject *Owner); pkgAcquire::ItemDesc*& (*acquireitemdesc_tocpp)(PyObject *self); PyTypeObject *acquireworker_type; + PyObject* (*acquireworker_fromcpp)(pkgAcquire::Worker* const &obj, bool Delete, PyObject *Owner); pkgAcquire::Worker*& (*acquireworker_tocpp)(PyObject *self); PyTypeObject *actiongroup_type; + PyObject* (*actiongroup_fromcpp)(pkgDepCache::ActionGroup* const &obj, bool Delete, PyObject *Owner); pkgDepCache::ActionGroup*& (*actiongroup_tocpp)(PyObject *self); PyTypeObject *cache_type; + PyObject* (*cache_fromcpp)(pkgCache* const &obj, bool Delete, PyObject *Owner); pkgCache*& (*cache_tocpp)(PyObject *self); PyTypeObject *cachefile_type; + PyObject* (*cachefile_fromcpp)(pkgCacheFile* const &obj, bool Delete, PyObject *Owner); pkgCacheFile*& (*cachefile_tocpp)(PyObject *self); PyTypeObject *cdrom_type; + PyObject* (*cdrom_fromcpp)(pkgCdrom const &obj, bool Delete, PyObject *Owner); pkgCdrom& (*cdrom_tocpp)(PyObject *self); PyTypeObject *configuration_type; + PyObject* (*configuration_fromcpp)(Configuration* const &obj, bool Delete, PyObject *Owner); Configuration*& (*configuration_tocpp)(PyObject *self); PyTypeObject *depcache_type; + PyObject* (*depcache_fromcpp)(pkgDepCache* const &obj, bool Delete, PyObject *Owner); pkgDepCache*& (*depcache_tocpp)(PyObject *self); PyTypeObject *dependency_type; + PyObject* (*dependency_fromcpp)(pkgCache::DepIterator const &obj, bool Delete, PyObject *Owner); pkgCache::DepIterator& (*dependency_tocpp)(PyObject *self); PyTypeObject *dependencylist_type; - void *dependencylist_tocpp; // FIXME: need packagelist_tocpp + void *dependencylist_fromcpp; // FIXME: need dependencylist_fromcpp + void *dependencylist_tocpp; // FIXME: need dependencylist_tocpp PyTypeObject *description_type; + PyObject* (*description_fromcpp)(pkgCache::DescIterator const &obj, bool Delete, PyObject *Owner); pkgCache::DescIterator& (*description_tocpp)(PyObject *self); PyTypeObject *hashes_type; + PyObject* (*hashes_fromcpp)(Hashes const &obj, bool Delete, PyObject *Owner); Hashes& (*hashes_tocpp)(PyObject *self); PyTypeObject *hashstring_type; + PyObject* (*hashstring_fromcpp)(HashString* const &obj, bool Delete, PyObject *Owner); HashString*& (*hashstring_tocpp)(PyObject *self); PyTypeObject *indexrecords_type; + PyObject* (*indexrecords_fromcpp)(indexRecords* const &obj, bool Delete, PyObject *Owner); indexRecords*& (*indexrecords_tocpp)(PyObject *self); PyTypeObject *metaindex_type; + PyObject* (*metaindex_fromcpp)(metaIndex* const &obj, bool Delete, PyObject *Owner); metaIndex*& (*metaindex_tocpp)(PyObject *self); PyTypeObject *package_type; + PyObject* (*package_fromcpp)(pkgCache::PkgIterator const &obj, bool Delete, PyObject *Owner); pkgCache::PkgIterator& (*package_tocpp)(PyObject *self); PyTypeObject *packagefile_type; + PyObject* (*packagefile_fromcpp)(pkgCache::PkgFileIterator const &obj, bool Delete, PyObject *Owner); pkgCache::PkgFileIterator& (*packagefile_tocpp)(PyObject *self); PyTypeObject *packageindexfile_type; + PyObject* (*indexfile_fromcpp)(pkgIndexFile* const &obj, bool Delete, PyObject *Owner); pkgIndexFile*& (*packageindexfile_tocpp)(PyObject *self); PyTypeObject *packagelist_type; + void *packagelist_fromcpp; // FIXME: need packagelist_fromcpp void *packagelist_tocpp; // FIXME: need packagelist_tocpp PyTypeObject *packagemanager_type; + PyObject* (*packagemanager_fromcpp)(pkgPackageManager* const &obj, bool Delete, PyObject *Owner); pkgPackageManager*& (*packagemanager_tocpp)(PyObject *self); PyTypeObject *packagerecords_type; + void *packagerecords_fromcpp; // FIXME: need packagerecords_fromcpp void *packagerecords_tocpp; // FIXME: need packagerecords_tocpp PyTypeObject *policy_type; + PyObject* (*policy_fromcpp)(pkgPolicy* const &obj, bool Delete, PyObject *Owner); pkgPolicy*& (*policy_tocpp)(PyObject *self); PyTypeObject *problemresolver_type; + PyObject* (*problemresolver_fromcpp)(pkgProblemResolver* const &obj, bool Delete, PyObject *Owner); pkgProblemResolver*& (*problemresolver_tocpp)(PyObject *self); PyTypeObject *sourcelist_type; + PyObject* (*sourcelist_fromcpp)(pkgSourceList* const &obj, bool Delete, PyObject *Owner); pkgSourceList*& (*sourcelist_tocpp)(PyObject *self); PyTypeObject *sourcerecords_type; + void *sourcerecords_fromcpp; // FIXME: need sourcerecords_fromcpp void *sourcerecords_tocpp; // FIXME: need sourcerecords_tocpp PyTypeObject *tagfile_type; + PyObject* (*tagfile_fromcpp)(pkgTagFile const &obj, bool Delete, PyObject *Owner); pkgTagFile& (*tagfile_tocpp)(PyObject *self); PyTypeObject *tagsection_type; + PyObject* (*tagsection_fromcpp)(pkgTagSection const &obj, bool Delete, PyObject *Owner); pkgTagSection& (*tagsection_tocpp)(PyObject *self); PyTypeObject *version_type; + PyObject* (*version_fromcpp)(pkgCache::VerIterator const &obj, bool Delete, PyObject *Owner); pkgCache::VerIterator& (*version_tocpp)(PyObject *self); + }; // Checking macros. @@ -208,24 +240,10 @@ static struct _PyAptPkgAPIStruct *_PyAptPkg_API; static int import_apt_pkg(void) { # if PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 _PyAptPkg_API = (_PyAptPkgAPIStruct *)PyCapsule_Import("apt_pkg._C_API", 0); - return (_PyAptPkg_API != NULL) ? 0 : -1; # else - - PyObject *module = PyImport_ImportModule("apt_pkg"); - - if (module == NULL) { - return -1; - } - if (module != NULL) { - PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API"); - if (c_api_object == NULL) - return -1; - if (PyCObject_Check(c_api_object)) - _PyAptPkg_API = (struct _PyAptPkgAPIStruct *)PyCObject_AsVoidPtr(c_api_object); - Py_DECREF(c_api_object); - } - return 0; + _PyAptPkg_API = (_PyAptPkgAPIStruct *)PyCObject_Import("apt_pkg", "_C_API"); # endif // PY_MAJOR_VERSION >= 3 && PY_MINOR_VERSION >= 1 + return (_PyAptPkg_API != NULL) ? 0 : -1; } # define PyAcquire_Type *(_PyAptPkg_API->acquire_type) @@ -292,48 +310,38 @@ static int import_apt_pkg(void) { # define PyTagSection_ToCpp _PyAptPkg_API->tagsection_tocpp # define PyVersion_ToCpp _PyAptPkg_API->version_tocpp // Get the C++ object -# define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp +# define PyAcquire_FromCpp _PyAptPkg_API->acquire_fromcpp +# define PyAcquireFile_FromCpp _PyAptPkg_API->acquirefile_fromcpp +# define PyAcquireItem_FromCpp _PyAptPkg_API->acquireitem_fromcpp +# define PyAcquireItemDesc_FromCpp _PyAptPkg_API->acquireitemdesc_fromcpp +# define PyAcquireWorker_FromCpp _PyAptPkg_API->acquireworker_fromcpp +# define PyActionGroup_FromCpp _PyAptPkg_API->actiongroup_fromcpp +# define PyCache_FromCpp _PyAptPkg_API->cache_fromcpp +# define PyCacheFile_FromCpp _PyAptPkg_API->cachefile_fromcpp +# define PyCdrom_FromCpp _PyAptPkg_API->cdrom_fromcpp +# define PyConfiguration_FromCpp _PyAptPkg_API->configuration_fromcpp +# define PyDepCache_FromCpp _PyAptPkg_API->depcache_fromcpp +# define PyDependency_FromCpp _PyAptPkg_API->dependency_fromcpp +# define PyDependencyList_FromCpp _PyAptPkg_API->dependencylist_fromcpp // NULL +# define PyDescription_FromCpp _PyAptPkg_API->description_fromcpp +# define PyHashes_FromCpp _PyAptPkg_API->hashes_fromcpp +# define PyHashString_FromCpp _PyAptPkg_API->hashstring_fromcpp +# define PyIndexRecords_FromCpp _PyAptPkg_API->indexrecords_fromcpp +# define PyMetaIndex_FromCpp _PyAptPkg_API->metaindex_fromcpp +# define PyPackage_FromCpp _PyAptPkg_API->package_fromcpp +# define PyPackageFile_FromCpp _PyAptPkg_API->packagefile_fromcpp +# define PyIndexFile_FromCpp _PyAptPkg_API->packageindexfile_fromcpp +# define PyPackageList_FromCpp _PyAptPkg_API->packagelist_fromcpp // NULL +# define PyPackageManager_FromCpp _PyAptPkg_API->packagemanager_fromcpp +# define PyPackageRecords_FromCpp _PyAptPkg_API->packagerecords_fromcpp +# define PyPolicy_FromCpp _PyAptPkg_API->policy_fromcpp +# define PyProblemResolver_FromCpp _PyAptPkg_API->problemresolver_fromcpp +# define PySourceList_FromCpp _PyAptPkg_API->sourcelist_fromcpp +# define PySourceRecords_FromCpp _PyAptPkg_API->sourcerecords_fromcpp // NULL +# define PyTagFile_FromCpp _PyAptPkg_API->tagfile_fromcpp +# define PyTagSection_FromCpp _PyAptPkg_API->tagsection_fromcpp +# define PyVersion_FromCpp _PyAptPkg_API->version_fromcpp # endif // APT_PKGMODULE_H -// Template using a simpler version of from cpp -template -inline CppPyObject *FromCpp(PyTypeObject *pytype, Cpp const &obj, bool Delete=false, PyObject *Owner=NULL) -{ - CppPyObject *Obj = CppPyObject_NEW(Owner, pytype, obj); - Obj->NoDelete = (!Delete); - return Obj; -} - - -# define PyAcquireFile_FromCpp(...) FromCpp(&PyAcquireFile_Type, ##__VA_ARGS__) -# define PyAcquireItem_FromCpp(...) FromCpp(&PyAcquireItem_Type,##__VA_ARGS__) -# define PyAcquireItemDesc_FromCpp(...) FromCpp(&PyAcquireItemDesc_Type,##__VA_ARGS__) -# define PyAcquireWorker_FromCpp(...) FromCpp(&PyAcquireWorker_Type,##__VA_ARGS__) -# define PyActionGroup_FromCpp(...) FromCpp(&PyActionGroup_Type,##__VA_ARGS__) -# define PyCache_FromCpp(...) FromCpp(&PyCache_Type,##__VA_ARGS__) -# define PyCacheFile_FromCpp(...) FromCpp(&PyCacheFile_Type,##__VA_ARGS__) -# define PyCdrom_FromCpp(...) FromCpp(&PyCdrom_Type,##__VA_ARGS__) -# define PyConfiguration_FromCpp(...) FromCpp(&PyConfiguration_Type, ##__VA_ARGS__) -# define PyDepCache_FromCpp(...) FromCpp(&PyDepCache_Type,##__VA_ARGS__) -# define PyDependency_FromCpp(...) FromCpp(&PyDependency_Type,##__VA_ARGS__) -//# define PyDependencyList_FromCpp(...) FromCpp(&PyDependencyList_Type,##__VA_ARGS__) -# define PyDescription_FromCpp(...) FromCpp(&PyDescription_Type,##__VA_ARGS__) -# define PyHashes_FromCpp(...) FromCpp(&PyHashes_Type,##__VA_ARGS__) -# define PyHashString_FromCpp(...) FromCpp(&PyHashString_Type,##__VA_ARGS__) -# define PyIndexRecords_FromCpp(...) FromCpp(&PyIndexRecords_Type,##__VA_ARGS__) -# define PyMetaIndex_FromCpp(...) FromCpp(&PyMetaIndex_Type,##__VA_ARGS__) -# define PyPackage_FromCpp(...) FromCpp(&PyPackage_Type,##__VA_ARGS__) -# define PyIndexFile_FromCpp(...) FromCpp(&PyIndexFile_Type,##__VA_ARGS__) -# define PyPackageFile_FromCpp(...) FromCpp(&PyPackageFile_Type,##__VA_ARGS__) -//# define PyPackageList_FromCpp(...) FromCpp(&PyPackageList_Type,##__VA_ARGS__) -# define PyPackageManager_FromCpp(...) FromCpp(&PyPackageManager_Type,##__VA_ARGS__) -//# define PyPackageRecords_FromCpp(...) FromCpp(&PyPackageRecords_Type,##__VA_ARGS__) -# define PyPolicy_FromCpp(...) FromCpp(&PyPolicy_Type,##__VA_ARGS__) -# define PyProblemResolver_FromCpp(...) FromCpp(&PyProblemResolver_Type,##__VA_ARGS__) -# define PySourceList_FromCpp(...) FromCpp(&PySourceList_Type,##__VA_ARGS__) -//# define PySourceRecords_FromCpp(...) FromCpp(&PySourceRecords_Type,##__VA_ARGS__) -# define PyTagFile_FromCpp(...) FromCpp(&PyTagFile_Type,##__VA_ARGS__) -# define PyTagSection_FromCpp(...) FromCpp(&PyTagSection_Type,##__VA_ARGS__) -# define PyVersion_FromCpp(...) FromCpp(&PyVersion_Type,##__VA_ARGS__) #endif diff --git a/setup.py b/setup.py index 635fee9b..2fa8198b 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc', 'hashstring.cc', 'indexfile.cc', 'indexrecords.cc', 'metaindex.cc', 'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc', 'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc', - 'lock.cc', 'acquire-item.cc'] + 'lock.cc', 'acquire-item.cc', 'python-apt-helpers.cc'] files = sorted(['python/' + fname for fname in files], key=lambda s: s[:-3]) apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"]) -- cgit v1.2.3 From a169fd15520d61303639c0dfa2aabec3f6446fb6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Sat, 27 Feb 2010 17:31:39 +0100 Subject: * python: - Handle deprecated attributes and methods in the tp_gettattro slot, this allows us to easily warn if a deprecated function is used. --- debian/changelog | 7 ++-- python/acquire-item.cc | 13 +------- python/acquire.cc | 12 +------ python/cache.cc | 88 ++++--------------------------------------------- python/cdrom.cc | 8 +++-- python/configuration.cc | 16 +-------- python/depcache.cc | 46 ++------------------------ python/generic.cc | 62 ++++++++++++++++++++++++++++++++++ python/generic.h | 6 ++++ python/indexfile.cc | 13 +------- python/metaindex.cc | 8 +---- python/pkgmanager.cc | 7 +--- python/pkgrecords.cc | 19 +---------- python/pkgsrcrecords.cc | 14 +------- python/sourcelist.cc | 10 +----- python/tag.cc | 19 ++--------- 16 files changed, 98 insertions(+), 250 deletions(-) (limited to 'python/generic.cc') diff --git a/debian/changelog b/debian/changelog index 25553644..e5945ef4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -python-apt (0.7.93.2) UNRELEASED; urgency=low +python-apt (0.7.93.2) unstable; urgency=low [ Julian Andres Klode ] * Fix some places where the old API was still used: @@ -8,6 +8,9 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low * utils/migrate-0.8.py: - Improve C++ parsing and add apt.progress.old to the modules, reduces false positives. + * python: + - Handle deprecated attributes and methods in the tp_gettattro slot, this + allows us to easily warn if a deprecated function is used. * python/tagfile.cc: - Implement the iterator protocol in TagFile. * python/cache.cc: @@ -35,7 +38,7 @@ python-apt (0.7.93.2) UNRELEASED; urgency=low * python/progress.cc: - try to call compatibility functions first, then new functions - -- Julian Andres Klode Sun, 07 Feb 2010 19:58:40 +0100 + -- Julian Andres Klode Sat, 27 Feb 2010 14:00:43 +0100 python-apt (0.7.93.1) unstable; urgency=low diff --git a/python/acquire-item.cc b/python/acquire-item.cc index d5f9ad10..09f0d643 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -128,17 +128,6 @@ static PyGetSetDef acquireitem_getset[] = { {"is_trusted",acquireitem_get_is_trusted}, {"local",acquireitem_get_local}, {"status",acquireitem_get_status}, -#ifdef COMPAT_0_7 - {"Complete",acquireitem_get_complete}, - {"DescURI",acquireitem_get_desc_uri}, - {"DestFile",acquireitem_get_destfile}, - {"ErrorText",acquireitem_get_error_text}, - {"FileSize",acquireitem_get_filesize}, - {"ID",acquireitem_get_id}, - {"IsTrusted",acquireitem_get_is_trusted}, - {"Local",acquireitem_get_local}, - {"Status",acquireitem_get_status}, -#endif {} }; @@ -180,7 +169,7 @@ PyTypeObject PyAcquireItem_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | diff --git a/python/acquire.cc b/python/acquire.cc index 5e22280e..cc9ee310 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -229,10 +229,6 @@ static PyObject *PkgAcquireShutdown(PyObject *Self,PyObject *Args) static PyMethodDef PkgAcquireMethods[] = { {"run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, {"shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, -#ifdef COMPAT_0_7 - {"Run",PkgAcquireRun,METH_VARARGS,"Run the fetcher"}, - {"Shutdown",PkgAcquireShutdown, METH_VARARGS,"Shutdown the fetcher"}, -#endif {} }; @@ -284,12 +280,6 @@ static PyGetSetDef PkgAcquireGetSet[] = { {"workers",PkgAcquireGetWorkers}, {"partial_present",PkgAcquireGetPartialPresent}, {"total_needed",PkgAcquireGetTotalNeeded}, -#ifdef COMPAT_0_7 - {"FetchNeeded",PkgAcquireGetFetchNeeded}, - {"Items",PkgAcquireGetItems}, - {"PartialPresent",PkgAcquireGetPartialPresent}, - {"TotalNeeded",PkgAcquireGetTotalNeeded}, -#endif {} }; @@ -354,7 +344,7 @@ PyTypeObject PyAcquire_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/cache.cc b/python/cache.cc index 5743d9df..3c9bc785 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -153,7 +153,6 @@ static PyMethodDef PkgCacheMethods[] = { {"update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, #ifdef COMPAT_0_7 - {"Update",PkgCacheUpdate,METH_VARARGS,"Update the cache"}, {"Open", PkgCacheOpen, METH_VARARGS,"Open the cache"}, {"Close", PkgCacheClose, METH_VARARGS,"Close the cache"}, #endif @@ -216,16 +215,6 @@ static PyGetSetDef PkgCacheGetSet[] = { {"provides_count",PkgCacheGetProvidesCount}, {"ver_file_count",PkgCacheGetVerFileCount}, {"version_count",PkgCacheGetVersionCount}, -#ifdef COMPAT_0_7 - {"DependsCount",PkgCacheGetDependsCount}, - {"FileList",PkgCacheGetFileList}, - {"PackageCount",PkgCacheGetPackageCount}, - {"PackageFileCount",PkgCacheGetPackageFileCount}, - {"Packages",PkgCacheGetPackages}, - {"ProvidesCount",PkgCacheGetProvidesCount}, - {"VerFileCount",PkgCacheGetVerFileCount}, - {"VersionCount",PkgCacheGetVersionCount}, -#endif {} }; @@ -349,7 +338,7 @@ PyTypeObject PyCache_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -543,21 +532,6 @@ static PyGetSetDef PackageGetSet[] = { {"important",PackageGetImportant}, {"version_list",PackageGetVersionList}, {"current_ver",PackageGetCurrentVer}, - #ifdef COMPAT_0_7 - {"Name",PackageGetName}, - {"Section",PackageGetSection}, - {"RevDependsList",PackageGetRevDependsList}, - {"ProvidesList",PackageGetProvidesList}, - {"SelectedState",PackageGetSelectedState}, - {"InstState",PackageGetInstState}, - {"CurrentState",PackageGetCurrentState}, - {"ID",PackageGetID}, - {"Auto",PackageGetAuto}, - {"Essential",PackageGetEssential}, - {"Important",PackageGetImportant}, - {"VersionList",PackageGetVersionList}, - {"CurrentVer",PackageGetCurrentVer}, - #endif {} }; @@ -590,7 +564,7 @@ PyTypeObject PyPackage_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -641,10 +615,6 @@ static PyGetSetDef DescriptionGetSet[] = { {"language_code",DescriptionGetLanguageCode}, {"md5",DescriptionGetMd5}, {"file_list",DescriptionGetFileList}, - #ifdef COMPAT_0_7 - {"LanguageCode",DescriptionGetLanguageCode}, - {"FileList",DescriptionGetFileList}, - #endif {} }; @@ -675,7 +645,7 @@ PyTypeObject PyDescription_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -886,24 +856,6 @@ static PyGetSetDef VersionGetSet[] = { {"size",VersionGetSize}, {"translated_description",VersionGetTranslatedDescription}, {"ver_str",VersionGetVerStr}, -#ifdef COMPAT_0_7 - {"Arch",VersionGetArch}, - {"DependsList",VersionGetDependsList}, - {"DependsListStr",VersionGetDependsListStr}, - {"Downloadable",VersionGetDownloadable}, - {"FileList",VersionGetFileList}, - {"Hash",VersionGetHash}, - {"ID",VersionGetID}, - {"InstalledSize",VersionGetInstalledSize}, - {"ParentPkg",VersionGetParentPkg}, - {"Priority",VersionGetPriority}, - {"PriorityStr",VersionGetPriorityStr}, - {"ProvidesList",VersionGetProvidesList}, - {"Section",VersionGetSection}, - {"Size",VersionGetSize}, - {"TranslationDescription",VersionGetTranslatedDescription}, - {"VerStr",VersionGetVerStr}, -#endif {} }; @@ -926,7 +878,7 @@ PyTypeObject PyVersion_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -1053,21 +1005,6 @@ static PyGetSetDef PackageFileGetSet[] = { {(char*)"site",PackageFile_GetSite}, {(char*)"size",PackageFile_GetSize}, {(char*)"version",PackageFile_GetVersion}, - #ifdef COMPAT_0_7 - {"Architecture",PackageFile_GetArchitecture}, - {"Archive",PackageFile_GetArchive}, - {"Component",PackageFile_GetComponent}, - {"FileName",PackageFile_GetFileName}, - {"ID",PackageFile_GetID}, - {"IndexType",PackageFile_GetIndexType}, - {"Label",PackageFile_GetLabel}, - {"NotAutomatic",PackageFile_GetNotAutomatic}, - {"NotSource",PackageFile_GetNotSource}, - {"Origin",PackageFile_GetOrigin}, - {"Site",PackageFile_GetSite}, - {"Size",PackageFile_GetSize}, - {"Version",PackageFile_GetVersion}, - #endif {} }; @@ -1088,7 +1025,7 @@ PyTypeObject PyPackageFile_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags @@ -1158,10 +1095,6 @@ static PyMethodDef DependencyMethods[] = { {"smart_target_pkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, {"all_targets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, -#ifdef COMPAT_0_7 - {"SmartTargetPkg",DepSmartTargetPkg,METH_VARARGS,"Returns the natural Target or None"}, - {"AllTargets",DepAllTargets,METH_VARARGS,"Returns all possible Versions that match this dependency"}, -#endif {} }; @@ -1240,15 +1173,6 @@ static PyGetSetDef DependencyGetSet[] = { {"parent_ver",DependencyGetParentVer}, {"target_pkg",DependencyGetTargetPkg}, {"target_ver",DependencyGetTargetVer}, -#ifdef COMPAT_0_7 - {"CompType",DependencyGetCompType}, - {"DepType",DependencyGetDepType}, - {"ID",DependencyGetID}, - {"ParentPkg",DependencyGetParentPkg}, - {"ParentVer",DependencyGetParentVer}, - {"TargetPkg",DependencyGetTargetPkg}, - {"TargetVer",DependencyGetTargetVer}, -#endif {} }; @@ -1272,7 +1196,7 @@ PyTypeObject PyDependency_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags diff --git a/python/cdrom.cc b/python/cdrom.cc index 0b9ae578..9eae49dc 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -78,6 +78,9 @@ static PyObject *cdrom_ident(PyObject *Self,PyObject *Args) #ifdef COMPAT_0_7 static PyObject *cdrom_ident_old(PyObject *Self,PyObject *Args) { + PyErr_WarnEx(PyExc_DeprecationWarning, "Method 'Ident' of the " + "'apt_pkg.Cdrom' object is deprecated, use 'ident' instead.", + 1); pkgCdrom &Cdrom = GetCpp(Self); PyObject *pyCdromProgressInst = 0; @@ -101,8 +104,7 @@ static PyMethodDef cdrom_methods[] = { {"add",cdrom_add,METH_VARARGS,cdrom_add_doc}, {"ident",cdrom_ident,METH_VARARGS,cdrom_ident_doc}, #ifdef COMPAT_0_7 - {"Add",cdrom_add,METH_VARARGS,"Add(progress) -> Add a cdrom"}, - {"Ident",cdrom_ident_old,METH_VARARGS,"Ident(progress) -> Ident a cdrom"}, + {"Ident",cdrom_ident_old,METH_VARARGS,"DEPRECATED. DO NOT USE"}, #endif {} }; @@ -134,7 +136,7 @@ PyTypeObject PyCdrom_Type = { 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/configuration.cc b/python/configuration.cc index 974f6f3d..299e06ec 100644 --- a/python/configuration.cc +++ b/python/configuration.cc @@ -446,20 +446,6 @@ static PyMethodDef CnfMethods[] = {"value_list",CnfValueList,METH_VARARGS,doc_ValueList}, {"my_tag",CnfMyTag,METH_VARARGS,doc_MyTag}, {"clear",CnfClear,METH_VARARGS,doc_Clear}, -#ifdef COMPAT_0_7 - {"Find",CnfFind,METH_VARARGS,doc_Find}, - {"FindFile",CnfFindFile,METH_VARARGS,doc_FindFile}, - {"FindDir",CnfFindDir,METH_VARARGS,doc_FindDir}, - {"FindI",CnfFindI,METH_VARARGS,doc_FindI}, - {"FindB",CnfFindB,METH_VARARGS,doc_FindB}, - {"Set",CnfSet,METH_VARARGS,doc_Set}, - {"Exists",CnfExists,METH_VARARGS,doc_Exists}, - {"SubTree",CnfSubTree,METH_VARARGS,doc_SubTree}, - {"List",CnfList,METH_VARARGS,doc_List}, - {"ValueList",CnfValueList,METH_VARARGS,doc_ValueList}, - {"MyTag",CnfMyTag,METH_VARARGS,doc_MyTag}, - {"Clear",CnfClear,METH_VARARGS,doc_Clear}, -#endif // Python Special {"keys",CnfKeys,METH_VARARGS,doc_Keys}, #if PY_MAJOR_VERSION < 3 @@ -498,7 +484,7 @@ PyTypeObject PyConfiguration_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/depcache.cc b/python/depcache.cc index 53459c32..8b4e02b5 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -569,34 +569,8 @@ static PyMethodDef PkgDepCacheMethods[] = {"marked_keep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, {"marked_reinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, {"marked_downgrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, - // Action {"commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, -#ifdef COMPAT_0_7 - {"Init",PkgDepCacheInit,METH_VARARGS,"Init the depcache (done on construct automatically)"}, - {"GetCandidateVer",PkgDepCacheGetCandidateVer,METH_VARARGS,"Get candidate version"}, - {"SetCandidateVer",PkgDepCacheSetCandidateVer,METH_VARARGS,"Set candidate version"}, - {"Upgrade",PkgDepCacheUpgrade,METH_VARARGS,"Perform Upgrade (optional boolean argument if dist-upgrade should be performed)"}, - {"FixBroken",PkgDepCacheFixBroken,METH_VARARGS,"Fix broken packages"}, - {"ReadPinFile",PkgDepCacheReadPinFile,METH_VARARGS,"Read the pin policy"}, - {"MinimizeUpgrade",PkgDepCacheMinimizeUpgrade, METH_VARARGS,"Go over the entire set of packages and try to keep each package marked for upgrade. If a conflict is generated then the package is restored."}, - {"MarkKeep",PkgDepCacheMarkKeep,METH_VARARGS,"Mark package for keep"}, - {"MarkDelete",PkgDepCacheMarkDelete,METH_VARARGS,"Mark package for delete (optional boolean argument if it should be purged)"}, - {"MarkInstall",PkgDepCacheMarkInstall,METH_VARARGS,"Mark package for Install"}, - {"SetReInstall",PkgDepCacheSetReInstall,METH_VARARGS,"Set if the package should be reinstalled"}, - {"IsUpgradable",PkgDepCacheIsUpgradable,METH_VARARGS,"Is pkg upgradable"}, - {"IsNowBroken",PkgDepCacheIsNowBroken,METH_VARARGS,"Is pkg is now broken"}, - {"IsInstBroken",PkgDepCacheIsInstBroken,METH_VARARGS,"Is pkg broken on the current install"}, - {"IsGarbage",PkgDepCacheIsGarbage,METH_VARARGS,"Is pkg garbage (mark-n-sweep)"}, - {"IsAutoInstalled",PkgDepCacheIsAutoInstalled,METH_VARARGS,"Is pkg marked as auto installed"}, - {"MarkedInstall",PkgDepCacheMarkedInstall,METH_VARARGS,"Is pkg marked for install"}, - {"MarkedUpgrade",PkgDepCacheMarkedUpgrade,METH_VARARGS,"Is pkg marked for upgrade"}, - {"MarkedDelete",PkgDepCacheMarkedDelete,METH_VARARGS,"Is pkg marked for delete"}, - {"MarkedKeep",PkgDepCacheMarkedKeep,METH_VARARGS,"Is pkg marked for keep"}, - {"MarkedReinstall",PkgDepCacheMarkedReinstall,METH_VARARGS,"Is pkg marked for reinstall"}, - {"MarkedDowngrade",PkgDepCacheMarkedDowngrade,METH_VARARGS,"Is pkg marked for downgrade"}, - {"Commit", PkgDepCacheCommit, METH_VARARGS, "Commit pending changes"}, -#endif {} }; @@ -641,14 +615,6 @@ static PyGetSetDef PkgDepCacheGetSet[] = { {"keep_count",PkgDepCacheGetKeepCount}, {"usr_size",PkgDepCacheGetUsrSize}, {"policy",PkgDepCacheGetPolicy}, - #ifdef COMPAT_0_7 - {"BrokenCount",PkgDepCacheGetBrokenCount}, - {"DebSize",PkgDepCacheGetDebSize}, - {"DelCount",PkgDepCacheGetDelCount}, - {"InstCount",PkgDepCacheGetInstCount}, - {"KeepCount",PkgDepCacheGetKeepCount}, - {"UsrSize",PkgDepCacheGetUsrSize}, - #endif {} }; @@ -699,7 +665,7 @@ PyTypeObject PyDepCache_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -856,14 +822,6 @@ static PyMethodDef PkgProblemResolverMethods[] = // Actions {"resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, {"resolve_by_keep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, - #ifdef COMPAT_0_7 - {"Protect", PkgProblemResolverProtect, METH_VARARGS, "Protect(PkgIterator)"}, - {"Remove", PkgProblemResolverRemove, METH_VARARGS, "Remove(PkgIterator)"}, - {"Clear", PkgProblemResolverClear, METH_VARARGS, "Clear(PkgIterator)"}, - {"InstallProtect", PkgProblemResolverInstallProtect, METH_VARARGS, "ProtectInstalled()"}, - {"Resolve", PkgProblemResolverResolve, METH_VARARGS, "Try to intelligently resolve problems by installing and removing packages"}, - {"ResolveByKeep", PkgProblemResolverResolveByKeep, METH_VARARGS, "Try to resolv problems only by using keep"}, - #endif {} }; @@ -886,7 +844,7 @@ PyTypeObject PyProblemResolver_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/generic.cc b/python/generic.cc index 640f0862..7af34d39 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -48,6 +48,68 @@ PyObject *HandleErrors(PyObject *Res) PyErr_SetString(PyExc_SystemError,Err.c_str()); return 0; } + +# ifdef COMPAT_0_7 +// Helpers for deprecation. + +// Given the name of the old attribute, return the name of the new attribute +// in a PyObject. +static PyObject *_PyApt_NewNameForAttribute(const char *attr) { + // Some exceptions from the standard algorithm. + if (strcasecmp(attr, "FileName") == 0) return PyString_FromString("filename"); + if (strcasecmp(attr, "DestFile") == 0) return PyString_FromString("destfile"); + if (strcasecmp(attr, "FileSize") == 0) return PyString_FromString("filesize"); + if (strcasecmp(attr, "SubTree") == 0) return PyString_FromString("subtree"); + if (strcasecmp(attr, "ReadPinFile") == 0) return PyString_FromString("read_pinfile"); + if (strcasecmp(attr, "SetReInstall") == 0) return PyString_FromString("set_reinstall"); + if (strcasecmp(attr, "URI") == 0) return PyString_FromString("uri"); + if (strcasecmp(attr, "MD5Hash") == 0) return PyString_FromString("md5_hash"); + if (strcasecmp(attr, "SHA1Hash") == 0) return PyString_FromString("sha1_hash"); + if (strcasecmp(attr, "SHA256Hash") == 0) return PyString_FromString("sha256_hash"); + size_t attrlen = strlen(attr); + // Reserve the old name + 5, this should reduce resize to a minimum. + string new_name; + new_name.reserve(attrlen + 5); + for(unsigned int i=0; i < attrlen; i++) { + // Replace all uppercase ASCII characters with their lower-case ones. + if (attr[i] > 64 && attr[i] < 91) { + if (i > 0) + new_name += "_"; + new_name += attr[i] + 32; + } else { + new_name += attr[i]; + } + } + return CppPyString(new_name); +} + +// Handle deprecated attributes by setting a warning and returning the new +// attribute. +PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr) { + PyObject *value = PyObject_GenericGetAttr(self, attr); + if (value == NULL) { + PyObject *ptype, *pvalue, *ptraceback; + PyErr_Fetch(&ptype, &pvalue, &ptraceback); + const char *attrname = PyObject_AsString(attr); + PyObject *newattr = _PyApt_NewNameForAttribute(attrname); + value = PyObject_GenericGetAttr(self, newattr); + if (value != NULL) { + const char *newattrname = PyString_AsString(newattr); + const char *cls = self->ob_type->tp_name; + char *warning_string = new char[strlen(newattrname) + strlen(cls) + + strlen(attrname) + 66]; + sprintf(warning_string, "Attribute '%s' of the '%s' object is " + "deprecated, use '%s' instead.", attrname, cls, newattrname); + PyErr_WarnEx(PyExc_DeprecationWarning, warning_string, 1); + delete[] warning_string; + } else { + PyErr_Restore(ptype, pvalue, ptraceback); + } + Py_DECREF(newattr); + } + return value; +} +# endif //COMPAT_0_7 /*}}}*/ // ListToCharChar - Convert a list to an array of char char /*{{{*/ // --------------------------------------------------------------------- diff --git a/python/generic.h b/python/generic.h index 7d2d6d3e..31c1bc2d 100644 --- a/python/generic.h +++ b/python/generic.h @@ -227,4 +227,10 @@ PyObject *HandleErrors(PyObject *Res = 0); const char **ListToCharChar(PyObject *List,bool NullTerm = false); PyObject *CharCharToList(const char **List,unsigned long Size = 0); +# ifdef COMPAT_0_7 +PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr); +# else +# define _PyAptObject_getattro 0 +# endif + #endif diff --git a/python/indexfile.cc b/python/indexfile.cc index e8df9cf2..c6d0b1cc 100644 --- a/python/indexfile.cc +++ b/python/indexfile.cc @@ -28,9 +28,6 @@ static PyObject *IndexFileArchiveURI(PyObject *Self,PyObject *Args) static PyMethodDef IndexFileMethods[] = { {"archive_uri",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, - #ifdef COMPAT_0_7 - {"ArchiveURI",IndexFileArchiveURI,METH_VARARGS,"Returns the ArchiveURI"}, - #endif {} }; @@ -76,14 +73,6 @@ static PyGetSetDef IndexFileGetSet[] = { {"is_trusted",IndexFileGetIsTrusted}, {"label",IndexFileGetLabel}, {"size",IndexFileGetSize}, - #ifdef COMPAT_0_7 - {"Describe",IndexFileGetDescribe}, - {"Exists",IndexFileGetExists}, - {"HasPackages",IndexFileGetHasPackages}, - {"IsTrusted",IndexFileGetIsTrusted}, - {"Label",IndexFileGetLabel}, - {"Size",IndexFileGetSize}, - #endif {} }; @@ -107,7 +96,7 @@ PyTypeObject PyIndexFile_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, // tp_flags diff --git a/python/metaindex.cc b/python/metaindex.cc index dee54521..2dcade7d 100644 --- a/python/metaindex.cc +++ b/python/metaindex.cc @@ -52,12 +52,6 @@ static PyGetSetDef MetaIndexGetSet[] = { {"index_files",MetaIndexGetIndexFiles}, {"is_trusted",MetaIndexGetIsTrusted}, {"uri",MetaIndexGetURI}, - #ifdef COMPAT_0_7 - {"Dist",MetaIndexGetDist}, - {"IndexFiles",MetaIndexGetIndexFiles}, - {"IsTrusted",MetaIndexGetIsTrusted}, - {"URI",MetaIndexGetURI}, - #endif {} }; @@ -91,7 +85,7 @@ PyTypeObject PyMetaIndex_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer Py_TPFLAGS_DEFAULT, // tp_flags diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 9b4a9ab7..2fda14ee 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -100,11 +100,6 @@ static PyMethodDef PkgManagerMethods[] = {"get_archives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archives into the fetcher"}, {"do_install",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, {"fix_missing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, -#ifdef COMPAT_0_7 - {"GetArchives",PkgManagerGetArchives,METH_VARARGS,"Load the selected archives into the fetcher"}, - {"DoInstall",PkgManagerDoInstall,METH_VARARGS,"Do the actual install"}, - {"FixMissing",PkgManagerFixMissing,METH_VARARGS,"Fix the install if a pkg couldn't be downloaded"}, -#endif {} }; @@ -128,7 +123,7 @@ PyTypeObject PyPackageManager_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 1e43b2e8..0e00edcd 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -50,9 +50,6 @@ static PyObject *PkgRecordsLookup(PyObject *Self,PyObject *Args) static PyMethodDef PkgRecordsMethods[] = { {"lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, - #ifdef COMPAT_0_7 - {"Lookup",PkgRecordsLookup,METH_VARARGS,"Changes to a new package"}, - #endif {} }; @@ -132,20 +129,6 @@ static PyGetSetDef PkgRecordsGetSet[] = { {"short_desc",PkgRecordsGetShortDesc}, {"source_pkg",PkgRecordsGetSourcePkg}, {"source_ver",PkgRecordsGetSourceVer}, -#ifdef COMPAT_0_7 - {"FileName",PkgRecordsGetFileName}, - {"Homepage",PkgRecordsGetHomepage}, - {"LongDesc",PkgRecordsGetLongDesc}, - {"MD5Hash",PkgRecordsGetMD5Hash}, - {"Maintainer",PkgRecordsGetMaintainer}, - {"Name",PkgRecordsGetName}, - {"Record",PkgRecordsGetRecord}, - {"SHA1Hash",PkgRecordsGetSHA1Hash}, - {"SHA256Hash",PkgRecordsGetSHA256Hash}, - {"ShortDesc",PkgRecordsGetShortDesc}, - {"SourcePkg",PkgRecordsGetSourcePkg}, - {"SourceVer",PkgRecordsGetSourceVer}, -#endif {} }; @@ -180,7 +163,7 @@ PyTypeObject PyPackageRecords_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 41ee6276..95f35f23 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -71,10 +71,6 @@ static PyMethodDef PkgSrcRecordsMethods[] = { {"lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, {"restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, -#ifdef COMPAT_0_7 - {"Lookup",PkgSrcRecordsLookup,METH_VARARGS,doc_PkgSrcRecordsLookup}, - {"Restart",PkgSrcRecordsRestart,METH_VARARGS,doc_PkgSrcRecordsRestart}, -#endif {} }; @@ -234,15 +230,7 @@ static PyGetSetDef PkgSrcRecordsGetSet[] = { {"section",PkgSrcRecordsGetSection}, {"version",PkgSrcRecordsGetVersion}, #ifdef COMPAT_0_7 - {"Binaries",PkgSrcRecordsGetBinaries}, {"BuildDepends",PkgSrcRecordsGetBuildDepends_old,0,"Deprecated function and deprecated output format."}, - {"Files",PkgSrcRecordsGetFiles}, - {"Index",PkgSrcRecordsGetIndex}, - {"Maintainer",PkgSrcRecordsGetMaintainer}, - {"Package",PkgSrcRecordsGetPackage}, - {"Record",PkgSrcRecordsGetRecord}, - {"Section",PkgSrcRecordsGetSection}, - {"Version",PkgSrcRecordsGetVersion}, #endif {} }; @@ -274,7 +262,7 @@ PyTypeObject PySourceRecords_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/sourcelist.cc b/python/sourcelist.cc index b705d8b8..6184fee3 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -77,11 +77,6 @@ static PyMethodDef PkgSourceListMethods[] = {"find_index",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, {"read_main_list",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, {"get_indexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, -#ifdef COMPAT_0_7 - {"FindIndex",PkgSourceListFindIndex,METH_VARARGS,doc_PkgSourceListFindIndex}, - {"ReadMainList",PkgSourceListReadMainList,METH_VARARGS,doc_PkgSourceListReadMainList}, - {"GetIndexes",PkgSourceListGetIndexes,METH_VARARGS,doc_PkgSourceListGetIndexes}, -#endif {} }; @@ -104,9 +99,6 @@ static PyObject *PkgSourceListGetList(PyObject *Self,void*) static PyGetSetDef PkgSourceListGetSet[] = { {"list",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, -#ifdef COMPAT_0_7 - {"List",PkgSourceListGetList,0,"A list of MetaIndex() objects.",0}, -#endif {} }; @@ -137,7 +129,7 @@ PyTypeObject PySourceList_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags diff --git a/python/tag.cc b/python/tag.cc index 4971a03d..6d327d27 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -458,12 +458,6 @@ static PyMethodDef TagSecMethods[] = {"find_raw",TagSecFindRaw,METH_VARARGS,doc_FindRaw}, {"find_flag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, {"bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, -#ifdef COMPAT_0_7 - {"Find",TagSecFind,METH_VARARGS,doc_Find}, - {"FindRaw",TagSecFindRaw,METH_VARARGS,doc_FindRaw}, - {"FindFlag",TagSecFindFlag,METH_VARARGS,doc_FindFlag}, - {"Bytes",TagSecBytes,METH_VARARGS,doc_Bytes}, -#endif // Python Special {"keys",TagSecKeys,METH_VARARGS,doc_Keys}, @@ -503,7 +497,7 @@ PyTypeObject PyTagSection_Type = 0, // tp_hash 0, // tp_call TagSecStr, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags @@ -536,11 +530,6 @@ static PyMethodDef TagFileMethods[] = {"step",TagFileStep,METH_VARARGS,doc_Step}, {"offset",TagFileOffset,METH_VARARGS,doc_Offset}, {"jump",TagFileJump,METH_VARARGS,doc_Jump}, -#ifdef COMPAT_0_7 - {"Step",TagFileStep,METH_VARARGS,doc_Step}, - {"Offset",TagFileOffset,METH_VARARGS,doc_Offset}, - {"Jump",TagFileJump,METH_VARARGS,doc_Jump}, -#endif {} }; @@ -554,12 +543,10 @@ static PyObject *TagFileGetSection(PyObject *Self,void*) { static PyGetSetDef TagFileGetSet[] = { {"section",TagFileGetSection,0,"Return a TagSection.",0}, -#ifdef COMPAT_0_7 - {"Section",TagFileGetSection,0,"Return a TagSection.",0}, -#endif {} }; + static char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" "TagFile() objects provide access to debian control files, which consists\n" "of multiple RFC822-like formatted sections.\n\n" @@ -593,7 +580,7 @@ PyTypeObject PyTagFile_Type = 0, // tp_hash 0, // tp_call 0, // tp_str - 0, // tp_getattro + _PyAptObject_getattro, // tp_getattro 0, // tp_setattro 0, // tp_as_buffer (Py_TPFLAGS_DEFAULT | // tp_flags -- cgit v1.2.3 From 60fa1ae39d5911d7051cfbeb1016db9d47ca331a Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Wed, 3 Mar 2010 19:40:22 +0100 Subject: python/generic.cc: Map UntranslatedDepType to dep_type_untranslated. --- debian/changelog | 2 ++ python/generic.cc | 1 + 2 files changed, 3 insertions(+) (limited to 'python/generic.cc') diff --git a/debian/changelog b/debian/changelog index cb825163..7986b91c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -2,6 +2,8 @@ python-apt (0.7.93.4) unstable; urgency=low * python/acquire-item.cc: - Add AcquireItem.partialsize member. + * python/generic.cc: + - Map UntranslatedDepType to dep_type_untranslated. * apt/package.py: - Create a string class BaseDependency.__dstr which makes '>' equal to '>>' and '<' equal to '<<' (compatibility). diff --git a/python/generic.cc b/python/generic.cc index 7af34d39..d3f6a6d6 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -66,6 +66,7 @@ static PyObject *_PyApt_NewNameForAttribute(const char *attr) { if (strcasecmp(attr, "MD5Hash") == 0) return PyString_FromString("md5_hash"); if (strcasecmp(attr, "SHA1Hash") == 0) return PyString_FromString("sha1_hash"); if (strcasecmp(attr, "SHA256Hash") == 0) return PyString_FromString("sha256_hash"); + if (strcasecmp(attr, "UntranslatedDepType") == 0) return PyString_FromString("dep_type_untranslated"); size_t attrlen = strlen(attr); // Reserve the old name + 5, this should reduce resize to a minimum. string new_name; -- cgit v1.2.3 From 62a7342edb16c38e3d646cc731a4a50ad6657b4f Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 9 Mar 2010 14:15:47 +0100 Subject: python/generic.cc: use std::string instead of string --- python/generic.cc | 4 ++-- python/progress.cc | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'python/generic.cc') diff --git a/python/generic.cc b/python/generic.cc index 640f0862..b0770e02 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -31,11 +31,11 @@ PyObject *HandleErrors(PyObject *Res) Py_DECREF(Res); } - string Err; + std::string Err; int errcnt = 0; while (_error->empty() == false) { - string Msg; + std::string Msg; bool Type = _error->PopMessage(Msg); if (errcnt > 0) Err.append(", "); diff --git a/python/progress.cc b/python/progress.cc index 18081690..097f06cf 100644 --- a/python/progress.cc +++ b/python/progress.cc @@ -491,7 +491,6 @@ pkgPackageManager::OrderResult PyInstallProgress::Run(pkgPackageManager *pm) StartUpdate(); - PyCbObj_END_ALLOW_THREADS if(PyObject_HasAttrString(callbackInst, "waitChild") || PyObject_HasAttrString(callbackInst, "wait_child")) { -- cgit v1.2.3 From dbfcddec5c85d306a97cdf73e539656c6d7225c5 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 15 Mar 2010 17:05:26 +0100 Subject: * python/generic.cc: - Fix a memory leak when using old attribute names. --- debian/changelog | 7 +++++++ python/generic.cc | 3 +++ 2 files changed, 10 insertions(+) (limited to 'python/generic.cc') diff --git a/debian/changelog b/debian/changelog index 31bdf042..84938005 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +python-apt (0.7.94.3) UNRELEASED; urgency=low + + * python/generic.cc: + - Fix a memory leak when using old attribute names. + + -- Julian Andres Klode Mon, 15 Mar 2010 17:04:49 +0100 + python-apt (0.7.94.2) unstable; urgency=low * Revert 0.7.93.3 and just set APT::Architecture to i386 for diff --git a/python/generic.cc b/python/generic.cc index d3f6a6d6..84dda9aa 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -107,6 +107,9 @@ PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr) { PyErr_Restore(ptype, pvalue, ptraceback); } Py_DECREF(newattr); + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); } return value; } -- cgit v1.2.3 From 29353cf54289f80eaa5923a1c73a36fb0bf3abb9 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 15 Mar 2010 17:10:24 +0100 Subject: Correctly fix the last one, PyErr_Restore takes a reference. --- python/generic.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'python/generic.cc') diff --git a/python/generic.cc b/python/generic.cc index 84dda9aa..1c68a481 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -104,6 +104,9 @@ PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr) { PyErr_WarnEx(PyExc_DeprecationWarning, warning_string, 1); delete[] warning_string; } else { + Py_XINCREF(ptype); + Py_XINCREF(pvalue); + Py_XINCREF(ptraceback); PyErr_Restore(ptype, pvalue, ptraceback); } Py_DECREF(newattr); -- cgit v1.2.3