From e50f19ba24ff8999d6d18da3fd06cdb44dfccced Mon Sep 17 00:00:00 2001 From: Michael Schaller Date: Sat, 11 Jan 2014 13:07:46 +0100 Subject: apt/package.py: Improved readability and documentation of BaseDependency.__dstr(). --- apt/package.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'apt') diff --git a/apt/package.py b/apt/package.py index 5d122968..d1a72744 100644 --- a/apt/package.py +++ b/apt/package.py @@ -72,17 +72,32 @@ class BaseDependency(object): """ class __dstr(str): - """Helper to make > match >> and < match <<""" + """Compare helper for compatibility with old third-party code. + + Old third-party code might still compare the relation with the + previously used relations (<<,<=,==,!=,>=,>>,) instead of the curently + used ones (<,<=,=,!=,>=,>,). This compare helper lets < match to <<, + > match to >> and = match to ==. + """ def __eq__(self, other): - return str.__eq__(self, other) or str.__eq__(2 * self, other) + if str.__eq__(self, other): + return True + elif str.__eq__(self, '<'): + return str.__eq__('<<', other) + elif str.__eq__(self, '>'): + return str.__eq__('>>', other) + elif str.__eq__(self, '='): + return str.__eq__('==', other) + else: + return False def __ne__(self, other): return not self.__eq__(other) def __init__(self, name, rel, ver, pre, rawtype=None): self.name = name - self.relation = len(rel) == 1 and self.__dstr(rel) or rel + self.relation = self.__dstr(rel) self.version = ver self.pre_depend = pre self.rawtype = rawtype -- cgit v1.2.3