From d280a08cee1bae5ff731f9cea2db5202fc119e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Mon, 25 Apr 2016 11:18:08 +0200 Subject: [PATCH] [enh] Implement the union of package version Specifier class --- src/yunohost/utils/packages.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/yunohost/utils/packages.py b/src/yunohost/utils/packages.py index 43d2f2927..3f168926c 100644 --- a/src/yunohost/utils/packages.py +++ b/src/yunohost/utils/packages.py @@ -146,6 +146,9 @@ class Specifier(object): def __and__(self, other): return self.intersection(other) + def __or__(self, other): + return self.union(other) + def _get_relation(self, op): return getattr(self, "_compare_{0}".format(self._relations[op])) @@ -218,6 +221,26 @@ class Specifier(object): result = [self, other] return SpecifierSet(result if result is not None else '') + def union(self, other): + """Make the union of two version specifiers + + Return a new `SpecifierSet` with version specifiers from the + specifier and the other. + + Example: + >>> Specifier('>= 2.2') | '<< 2.3' == '>= 2.2, << 2.3' + + """ + if isinstance(other, basestring): + try: + other = self.__class__(other) + except InvalidSpecifier: + return NotImplemented + elif not isinstance(other, self.__class__): + return NotImplemented + + return SpecifierSet([self, other]) + def contains(self, item): """Check if the specifier contains an other