diff options
| -rw-r--r-- | apt/__init__.py | 5 | ||||
| -rw-r--r-- | apt/deprecation.py | 13 | ||||
| -rw-r--r-- | apt/package.py | 2 | ||||
| -rw-r--r-- | apt/progress/old.py | 25 | ||||
| -rw-r--r-- | debian/changelog | 8 | ||||
| -rw-r--r-- | python/acquire-item.cc | 7 | ||||
| -rw-r--r-- | python/acquire.cc | 5 | ||||
| -rw-r--r-- | python/apt_pkgmodule.cc | 5 | ||||
| -rw-r--r-- | python/cache.cc | 17 | ||||
| -rw-r--r-- | python/cdrom.cc | 12 | ||||
| -rw-r--r-- | python/depcache.cc | 19 | ||||
| -rw-r--r-- | python/generic.cc | 3 | ||||
| -rw-r--r-- | python/generic.h | 1 | ||||
| -rw-r--r-- | python/pkgmanager.cc | 7 | ||||
| -rw-r--r-- | python/pkgrecords.cc | 7 | ||||
| -rw-r--r-- | python/pkgsrcrecords.cc | 7 | ||||
| -rw-r--r-- | python/sourcelist.cc | 7 | ||||
| -rw-r--r-- | python/tag.cc | 14 | ||||
| -rw-r--r--[-rwxr-xr-x] | tests/old/memleak.py | 0 |
19 files changed, 98 insertions, 66 deletions
diff --git a/apt/__init__.py b/apt/__init__.py index 8b66ad13..a8a8b8fc 100644 --- a/apt/__init__.py +++ b/apt/__init__.py @@ -17,11 +17,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA -import os -import warnings -if not "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: - warnings.simplefilter('ignore', DeprecationWarning) - # import the core of apt_pkg """High-Level Interface for working with apt.""" import apt_pkg diff --git a/apt/deprecation.py b/apt/deprecation.py index 0f39ad63..cd33a51b 100644 --- a/apt/deprecation.py +++ b/apt/deprecation.py @@ -24,6 +24,7 @@ not use it for anything outside the apt package. """ import re import operator +import os import warnings import apt_pkg @@ -49,12 +50,14 @@ class AttributeDeprecatedBy(object): """Issue a DeprecationWarning and return the requested value.""" if obj is None: return getattr(type_, self.attribute, self) - warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2) return self.getter(obj or type_) def __set__(self, obj, value): """Issue a DeprecationWarning and set the requested value.""" - warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2) setattr(obj, self.attribute, value) @@ -71,7 +74,8 @@ def function_deprecated_by(func, convert_names=True): def deprecated_function(*args, **kwds): """Wrapper around a deprecated function.""" - warnings.warn(warning, DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn(warning, DeprecationWarning, stacklevel=2) if convert_names: for key in kwds.keys(): kwds[re.sub('([A-Z])', '_\\1', key).lower()] = kwds.pop(key) @@ -93,7 +97,8 @@ def deprecated_args(func): for key in kwds.keys(): new_key = re.sub('([A-Z])', '_\\1', key).lower() if new_key != key: - warnings.warn("Deprecated parameter %r" % key) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn("Deprecated parameter %r" % key) kwds[new_key] = kwds.pop(key) return func(*args, **kwds) diff --git a/apt/package.py b/apt/package.py index 0c026504..701872a8 100644 --- a/apt/package.py +++ b/apt/package.py @@ -120,7 +120,7 @@ class DeprecatedProperty(property): self.__doc__ = (doc or fget.__doc__ or '') def __get__(self, obj, type_=None): - if obj is not None: + if obj is not None and "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: warnings.warn("Accessed deprecated property %s.%s, please see the " "Version class for alternatives." % ((obj.__class__.__name__ or type_.__name__), diff --git a/apt/progress/old.py b/apt/progress/old.py index 4bd79f2e..2d3fdb59 100644 --- a/apt/progress/old.py +++ b/apt/progress/old.py @@ -42,8 +42,9 @@ class OpProgress(base.OpProgress): def __init__(self): base.OpProgress.__init__(self) - warnings.warn("apt.progress.OpProgress is deprecated.", - DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn("apt.progress.OpProgress is deprecated.", + DeprecationWarning, stacklevel=2) subOp = AttributeDeprecatedBy('subop') Op = AttributeDeprecatedBy('op') @@ -54,8 +55,9 @@ class OpTextProgress(OpProgress, text.OpProgress): def __init__(self): text.OpProgress.__init__(self) - warnings.warn("apt.progress.OpTextProgress is deprecated.", - DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn("apt.progress.OpTextProgress is deprecated.", + DeprecationWarning, stacklevel=2) class FetchProgress(object): @@ -75,8 +77,9 @@ class FetchProgress(object): self.totalBytes = 0 self.totalItems = 0 self.currentCPS = 0 - warnings.warn("apt.progress.FetchProgress is deprecated.", - DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn("apt.progress.FetchProgress is deprecated.", + DeprecationWarning, stacklevel=2) def start(self): """Called when the fetching starts.""" @@ -175,8 +178,9 @@ class CdromProgress(object): """Report the cdrom add progress.""" def __init__(self): - warnings.warn("apt.progress.CdromProgress is deprecated.", - DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn("apt.progress.CdromProgress is deprecated.", + DeprecationWarning, stacklevel=2) def askCdromName(self): """Ask for a cdrom name""" @@ -193,8 +197,9 @@ class DumbInstallProgress(base.InstallProgress): def __init__(self): base.InstallProgress.__init__(self) - warnings.warn("apt.progress.*InstallProgress are deprecated.", - DeprecationWarning, stacklevel=2) + if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ: + warnings.warn("apt.progress.*InstallProgress are deprecated.", + DeprecationWarning, stacklevel=2) def updateInterface(self): # *_stream were not available in the old progress reporting classes, diff --git a/debian/changelog b/debian/changelog index 747fea77..0013daf1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +python-apt (0.7.94.2ubuntu4) lucid; urgency=low + + * If PYTHON_APT_DEPRECATION_WARNINGS is unset, also disable the + deprecation warnings in apt_pkg directly; and don't just + disable any deprecation warning in apt/__init__.py (LP: #548623) + + -- Julian Andres Klode <juliank@ubuntu.com> Mon, 29 Mar 2010 13:18:20 +0200 + python-apt (0.7.94.2ubuntu3) lucid; urgency=low * python/indexfile.cc: diff --git a/python/acquire-item.cc b/python/acquire-item.cc index cdb4a4bc..cb41f489 100644 --- a/python/acquire-item.cc +++ b/python/acquire-item.cc @@ -279,9 +279,10 @@ char *doc_GetPkgAcqFile = "GetPkgAcqFile(pkgAquire, uri[, md5, size, descr, shortDescr, destDir, destFile]) -> PkgAcqFile\n"; PyObject *GetPkgAcqFile(PyObject *Self, PyObject *Args, PyObject * kwds) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgAcqFile() is " - "deprecated. Please see apt_pkg.AcquireFile() for the " - "replacement", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgAcqFile() is " + "deprecated. Please see apt_pkg.AcquireFile() for the " + "replacement", 1); PyObject *pyfetcher; char *uri, *md5, *descr, *shortDescr, *destDir, *destFile; int size = 0; diff --git a/python/acquire.cc b/python/acquire.cc index cc9ee310..3f24a3e7 100644 --- a/python/acquire.cc +++ b/python/acquire.cc @@ -372,8 +372,9 @@ PyTypeObject PyAcquire_Type = { #ifdef COMPAT_0_7 PyObject *GetAcquire(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetAcquire() is deprecated." - " Please see apt_pkg.Acquire() for the replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetAcquire() is deprecated." + " Please see apt_pkg.Acquire() for the replacement.", 1); return PkgAcquireNew(&PyAcquire_Type,Args,0); } #endif diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 3d40832b..2a181619 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -54,8 +54,9 @@ static PyObject *py_gettext(PyObject *self, PyObject *Args) { static char *doc_newConfiguration = "Construct a configuration instance"; static PyObject *newConfiguration(PyObject *self,PyObject *args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " - "deprecated. Use apt_pkg.Configuration() instead.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.newConfiguration() is " + "deprecated. Use apt_pkg.Configuration() instead.", 1); return CppPyObject_NEW<Configuration*>(NULL, &PyConfiguration_Type, new Configuration()); } #endif diff --git a/python/cache.cc b/python/cache.cc index 3c9bc785..ba620099 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -105,8 +105,9 @@ static PyObject *PkgCacheUpdate(PyObject *Self,PyObject *Args) #ifdef COMPAT_0_7 static PyObject *PkgCacheClose(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "Cache.Close() is deprecated, " - "because it causes segfaults. Delete the Cache instead.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "Cache.Close() is deprecated, " + "because it causes segfaults. Delete the Cache instead.", 1); PyObject *CacheFilePy = GetOwner<pkgCache*>(Self); pkgCacheFile *Cache = GetCpp<pkgCacheFile*>(CacheFilePy); Cache->Close(); @@ -117,9 +118,10 @@ static PyObject *PkgCacheClose(PyObject *Self,PyObject *Args) static PyObject *PkgCacheOpen(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "Cache.Open() is deprecated, " - "because it causes memory leaks. Create a new Cache instead.", - 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "Cache.Open() is deprecated, " + "because it causes memory leaks. Create a new Cache instead.", + 1); PyObject *CacheFilePy = GetOwner<pkgCache*>(Self); pkgCacheFile *Cache = GetCpp<pkgCacheFile*>(CacheFilePy); @@ -1296,8 +1298,9 @@ PyTypeObject PyDependencyList_Type = #ifdef COMPAT_0_7 PyObject *TmpGetCache(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCache() is deprecated. " - "Please see apt_pkg.Cache() for the replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCache() is deprecated. " + "Please see apt_pkg.Cache() for the replacement.", 1); return PkgCacheNew(&PyCache_Type,Args,0); } #endif diff --git a/python/cdrom.cc b/python/cdrom.cc index 9eae49dc..d732a810 100644 --- a/python/cdrom.cc +++ b/python/cdrom.cc @@ -78,9 +78,10 @@ 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); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "Method 'Ident' of the " + "'apt_pkg.Cdrom' object is deprecated, use 'ident' instead.", + 1); pkgCdrom &Cdrom = GetCpp<pkgCdrom>(Self); PyObject *pyCdromProgressInst = 0; @@ -164,8 +165,9 @@ PyTypeObject PyCdrom_Type = { #ifdef COMPAT_0_7 PyObject *GetCdrom(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCdrom() is deprecated. " - "Please see apt_pkg.Cdrom() for the replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetCdrom() is deprecated. " + "Please see apt_pkg.Cdrom() for the replacement.", 1); return cdrom_new(&PyCdrom_Type,Args,0); } #endif diff --git a/python/depcache.cc b/python/depcache.cc index 8b4e02b5..0d5d7882 100644 --- a/python/depcache.cc +++ b/python/depcache.cc @@ -694,8 +694,9 @@ PyTypeObject PyDepCache_Type = #ifdef COMPAT_0_7 PyObject *GetDepCache(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetDepCache() is deprecated" - ". Please see apt_pkg.DepCache() for the replacement.",1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning,"apt_pkg.GetDepCache() is deprecated" + ". Please see apt_pkg.DepCache() for the replacement.",1); return PkgDepCacheNew(&PyDepCache_Type,Args,0); } #endif @@ -728,9 +729,10 @@ static PyObject *PkgProblemResolverNew(PyTypeObject *type,PyObject *Args,PyObjec #ifdef COMPAT_0_7 PyObject *GetPkgProblemResolver(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgProblemResolver() is" - " deprecated. Please see apt_pkg.ProblemResolver() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgProblemResolver() is" + " deprecated. Please see apt_pkg.ProblemResolver() for the " + "replacement.", 1); return PkgProblemResolverNew(&PyProblemResolver_Type,Args,0); } #endif @@ -989,9 +991,10 @@ PyTypeObject PyActionGroup_Type = #ifdef COMPAT_0_7 PyObject *GetPkgActionGroup(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgActionGroup() is " - "deprecated. Please see apt_pkg.ActionGroup() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgActionGroup() is " + "deprecated. Please see apt_pkg.ActionGroup() for the " + "replacement.", 1); return PkgActionGroupNew(&PyActionGroup_Type,Args,0); } #endif diff --git a/python/generic.cc b/python/generic.cc index f0980f2b..d08b12c0 100644 --- a/python/generic.cc +++ b/python/generic.cc @@ -101,7 +101,8 @@ PyObject *_PyAptObject_getattro(PyObject *self, PyObject *attr) { 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); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, warning_string, 1); delete[] warning_string; } else { Py_XINCREF(ptype); diff --git a/python/generic.h b/python/generic.h index 31c1bc2d..98c6d82b 100644 --- a/python/generic.h +++ b/python/generic.h @@ -31,6 +31,7 @@ #include <string> #include <iostream> #include <new> +#include <cstdlib> #if PYTHON_API_VERSION < 1013 typedef int Py_ssize_t; diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc index 2fda14ee..e8346b3d 100644 --- a/python/pkgmanager.cc +++ b/python/pkgmanager.cc @@ -39,9 +39,10 @@ static PyObject *PkgManagerNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) #ifdef COMPAT_0_7 PyObject *GetPkgManager(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPackageManager() is " - "deprecated. Please see apt_pkg.PackageManager() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPackageManager() is " + "deprecated. Please see apt_pkg.PackageManager() for the " + "replacement.", 1); return PkgManagerNew(&PyPackageManager_Type,Args,0); } #endif diff --git a/python/pkgrecords.cc b/python/pkgrecords.cc index 0e00edcd..916a2e0f 100644 --- a/python/pkgrecords.cc +++ b/python/pkgrecords.cc @@ -195,9 +195,10 @@ PyTypeObject PyPackageRecords_Type = #ifdef COMPAT_0_7 PyObject *GetPkgRecords(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgRecords() is " - "deprecated. Please see apt_pkg.Records() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgRecords() is " + "deprecated. Please see apt_pkg.Records() for the " + "replacement.", 1); return PkgRecordsNew(&PyPackageRecords_Type,Args,0); } #endif diff --git a/python/pkgsrcrecords.cc b/python/pkgsrcrecords.cc index 95f35f23..729a74b5 100644 --- a/python/pkgsrcrecords.cc +++ b/python/pkgsrcrecords.cc @@ -292,9 +292,10 @@ PyTypeObject PySourceRecords_Type = #ifdef COMPAT_0_7 PyObject *GetPkgSrcRecords(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSrcRecords() is " - "deprecated. Please see apt_pkg.SourceRecords() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSrcRecords() is " + "deprecated. Please see apt_pkg.SourceRecords() for the " + "replacement.", 1); if (PyArg_ParseTuple(Args,"") == 0) return 0; diff --git a/python/sourcelist.cc b/python/sourcelist.cc index 6184fee3..5a950b2c 100644 --- a/python/sourcelist.cc +++ b/python/sourcelist.cc @@ -157,9 +157,10 @@ PyTypeObject PySourceList_Type = #ifdef COMPAT_0_7 PyObject *GetPkgSourceList(PyObject *Self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSourceList() is " - "deprecated. Please see apt_pkg.SourceList() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.GetPkgSourceList() is " + "deprecated. Please see apt_pkg.SourceList() for the " + "replacement.", 1); return PkgSourceListNew(&PySourceList_Type,Args,0); } #endif diff --git a/python/tag.cc b/python/tag.cc index c7edcb31..bc470620 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -349,9 +349,10 @@ static PyObject *TagSecNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) { char *doc_ParseSection ="ParseSection(Text) -> TagSection() object. Deprecated."; PyObject *ParseSection(PyObject *self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseSection() is " - "deprecated. Please see apt_pkg.TagSection() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseSection() is " + "deprecated. Please see apt_pkg.TagSection() for the " + "replacement.", 1); return TagSecNew(&PyTagSection_Type,Args,0); } #endif @@ -388,9 +389,10 @@ static PyObject *TagFileNew(PyTypeObject *type,PyObject *Args,PyObject *kwds) #ifdef COMPAT_0_7 char *doc_ParseTagFile = "ParseTagFile(File) -> TagFile() object. Deprecated."; PyObject *ParseTagFile(PyObject *self,PyObject *Args) { - PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseTagFile() is " - "deprecated. Please see apt_pkg.TagFile() for the " - "replacement.", 1); + if (getenv("PYTHON_APT_DEPRECATION_WARNINGS") != NULL) + PyErr_WarnEx(PyExc_DeprecationWarning, "apt_pkg.ParseTagFile() is " + "deprecated. Please see apt_pkg.TagFile() for the " + "replacement.", 1); return TagFileNew(&PyTagFile_Type,Args,0); } #endif diff --git a/tests/old/memleak.py b/tests/old/memleak.py index 5299f35f..5299f35f 100755..100644 --- a/tests/old/memleak.py +++ b/tests/old/memleak.py |
