diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-07-30 17:44:49 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-07-30 17:44:49 +0200 |
| commit | 0cb44e7c914bf98d92a85d83b0bdc15ebc73525d (patch) | |
| tree | 4ef92defd8ba3f28ac131d2ac335f1aacb738f67 /apt | |
| parent | 5441b32e4b56bfc79610bd32b4fe3c4c4b5671dc (diff) | |
| download | python-apt-0cb44e7c914bf98d92a85d83b0bdc15ebc73525d.tar.gz | |
apt/package.py: Make comparisons of Version object more robust.
Diffstat (limited to 'apt')
| -rw-r--r-- | apt/package.py | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/apt/package.py b/apt/package.py index f5bdc47d..0b8d4bf8 100644 --- a/apt/package.py +++ b/apt/package.py @@ -189,17 +189,47 @@ class Version(object): self.package = package self._cand = cand + def _cmp(self, other): + try: + return apt_pkg.VersionCompare(self._cand.VerStr, other.version) + except AttributeError: + return apt_pkg.VersionCompare(self._cand.VerStr, other) + def __eq__(self, other): - return self._cand.ID == other._cand.ID + try: + return self._cmp(other) == 0 + except TypeError: + return NotImplemented + + def __ge__(self): + try: + return self._cmp(other) >= 0 + except TypeError: + return NotImplemented def __gt__(self, other): - return apt_pkg.VersionCompare(self.version, other.version) > 0 + try: + return self._cmp(other) > 0 + except TypeError: + return NotImplemented + + def __le__(self): + try: + return self._cmp(other) <= 0 + except TypeError: + return NotImplemented def __lt__(self, other): - return apt_pkg.VersionCompare(self.version, other.version) < 0 + try: + return self._cmp(other) < 0 + except TypeError: + return NotImplemented def __ne__(self, other): - return not self.__eq__(other) + try: + return self._cmp(other) != 0 + except TypeError: + return NotImplemented def __hash__(self): return self._cand.Hash @@ -488,7 +518,7 @@ class Package(object): def candidate(self): """Return the candidate version of the package. - + This property is writeable to allow you to set the candidate version of the package. Just assign a Version() object, and it will be set as the candidate version. |
