diff options
author | Tim Harder <radhermit@gmail.com> | 2016-07-22 17:16:55 -0400 |
---|---|---|
committer | Tim Harder <radhermit@gmail.com> | 2016-07-22 17:16:55 -0400 |
commit | 5c4e9f93266908d976772ad1d81b8b47045d84b3 (patch) | |
tree | e7c54e03faa27ed2bd9c08a957e007d5b9feb839 | |
parent | repository/prototype: add __str__ fallback for custom repos without aliases (diff) | |
download | pkgcore-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.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pkgcore/restrictions/boolean.py b/pkgcore/restrictions/boolean.py index 2c4e1e82..6f771c37 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: |