aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Harder <radhermit@gmail.com>2016-07-22 17:16:55 -0400
committerTim Harder <radhermit@gmail.com>2016-07-22 17:16:55 -0400
commit5c4e9f93266908d976772ad1d81b8b47045d84b3 (patch)
treee7c54e03faa27ed2bd9c08a957e007d5b9feb839
parentrepository/prototype: add __str__ fallback for custom repos without aliases (diff)
downloadpkgcore-5c4e9f93266908d976772ad1d81b8b47045d84b3.tar.gz
pkgcore-5c4e9f93266908d976772ad1d81b8b47045d84b3.tar.bz2
pkgcore-5c4e9f93266908d976772ad1d81b8b47045d84b3.zip
restrictions/boolean: add remove_restriction() method
Allows for the removal of specific restrictions or restriction class types from a given restriction object.
-rw-r--r--pkgcore/restrictions/boolean.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/pkgcore/restrictions/boolean.py b/pkgcore/restrictions/boolean.py
index 2c4e1e828..6f771c373 100644
--- a/pkgcore/restrictions/boolean.py
+++ b/pkgcore/restrictions/boolean.py
@@ -90,13 +90,22 @@ class base(restriction.base):
kwds.setdefault("negate", self.negate)
return self.__class__(*restrictions, **kwds)
+ def remove_restriction(self, restriction_types=(), *restrictions):
+ """return a new instance of self.__class__, dropping supplied restrictions or types"""
+ new_restrictions = tuple(
+ r for r in self.restrictions if
+ not isinstance(r, tuple(restriction_types))
+ and r not in restrictions)
+ if new_restrictions != self.restrictions:
+ return self.change_restrictions(*new_restrictions)
+ return self
+
def add_restriction(self, *new_restrictions):
"""add more restriction(s)
:param new_restrictions: if node_type is enforced,
restrictions must be of that type.
"""
-
if not new_restrictions:
raise TypeError("need at least one restriction handed in")
if self.type is not None: