def match(self, val, _values_override=None): vals = _values_override if _values_override is None: vals = self.vals if isinstance(val, basestring): for fval in vals: if fval in val: return not self.negate return self.negate # this can, and should be optimized to do len checks- iterate # over the smaller of the two see above about special casing # bits. need the same protection here, on the offchance (as # contents sets do), the __getitem__ is non standard. try: if self.all: return vals.issubset(val) != self.negate # if something intersects, then we return the inverse of negate- # if negate=False, something is found, result is True return is_disjoint(vals, val) == self.negate except TypeError: # isn't iterable, try the other way around. rely on contains. if self.all: for k in vals: if k not in val: return self.negate return not self.negate for k in vals: if k in val: return not self.negate
def request_disable(self, attr, *vals): if attr != 'use': return False set_vals = frozenset(vals) if self.eapi_obj.magic == '0': if not set_vals.issubset(self.iuse): return False else: if set_vals.issubset(x.lstrip('-+') for x in self.iuse): # requested a flag that doesn't exist in iuse return False # if any of the flags are forced_use, it's a no go. return not is_disjoint(set_vals, self._profile.forced_use. pull_data(self._raw_pkg))
def collect_package_restrictions(restrict, attrs=None, invert=False): """Collect PackageRestriction instances inside a restriction. :param restrict: package instance to scan :param attrs: None (return all package restrictions), or a sequence of specific attrs the package restriction must work against. """ if not isinstance(restrict, (list, tuple)): restrict = [restrict] for r in restrict: if not isinstance(r, restriction.base): raise TypeError( "restrict must be of a restriction.base, not %s: %r" % ( r.__class__.__name__, r)) if attrs is None: for r in iflatten_func(restrict, _is_package_instance): yield r else: attrs = frozenset(attrs) for r in iflatten_func(restrict, _is_package_instance): if invert == is_disjoint(attrs, getattr(r, 'attrs', ())): yield r