Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_basic(self):
def yes(val):
return True
def no(val):
return False
for negate in (False, True):
yes_restrict = values.FunctionRestriction(yes, negate=negate)
no_restrict = values.FunctionRestriction(no, negate=negate)
assert not negate == yes_restrict.match(7)
assert negate == no_restrict.match(7)
for restrict in yes_restrict, no_restrict:
# Just check this does not raise
assert str(restrict)
assert repr(restrict)
def test_collect_all(self):
prs = [packages.PackageRestriction("category", values.AlwaysTrue)] * 10
self.assertEqual(
list(util.collect_package_restrictions(packages.AndRestriction(
packages.OrRestriction(), packages.AndRestriction(),
*prs))),
prs)
val = True
except ValueError:
pass
return val
if __name__ == "__main__":
a = sys.argv[1:]
if grab_arg("--help", a) or grab_arg("-h", a) or not a:
print "need at least one arg, file to find the owner of"
print "default matching mode is return after first match, however if [ --all || -a ] is specified"
print "all owners are return"
print "Multiple args are further restrictions on a match- pkg must own all of the files"
sys.exit(1)
all = grab_arg("-a", a) or grab_arg("--all", a)
repo = load_config().get_default("domain").vdb[0]
restrict = packages.PackageRestriction("contents", values.ContainmentMatch(
*[normpath(x) for x in a]))
start_time = time.time()
count = 0
print "query- %s, returning all matches? %s" % (restrict, all)
for pkg in repo.itermatch(restrict):
print "pkg: %s" % (pkg)
count += 1
if not all:
break
print "found %i matches in %.2f seconds" % (count, time.time() - start_time)
if count:
sys.exit(0)
sys.exit(1)
"""
if nodeps:
vdbs = list(map(misc.nodeps_repo, vdbs))
dbs = list(map(misc.nodeps_repo, dbs))
elif not verify_vdb:
vdbs = list(map(misc.nodeps_repo, vdbs))
dbs = list(dbs)
if force_replace:
resolver_cls = generate_replace_resolver_kls(resolver_cls)
return resolver_cls(vdbs + dbs, plan.pkg_sort_highest,
plan.merge_plan.prefer_reuse_strategy, **kwds)
_vdb_restrict = packages.OrRestriction(
packages.PackageRestriction("repo.livefs", values.EqualityMatch(False)),
packages.AndRestriction(
packages.PackageRestriction(
"category", values.StrExactMatch("virtual")),
packages.PackageRestriction(
"package_is_real", values.EqualityMatch(False)),
),
)
class empty_tree_merge_plan(plan.merge_plan):
_vdb_restriction = _vdb_restrict
def __init__(self, dbs, *args, **kwds):
"""
:param args: see :obj:`pkgcore.resolver.plan.merge_plan.__init__`
def f(x, y):
c = cmp(x, y)
if c:
return c
elif x.repo.livefs:
if y.repo.livefs:
return 0
return -1
elif y.repo.livefs:
return 1
return 0
sort_cmp(l, f, key=pkg_grabber)
return l
class MutableContainmentRestriction(values.base):
__slots__ = ('_blacklist', 'match')
def __init__(self, blacklist):
sf = object.__setattr__
sf(self, '_blacklist', blacklist)
sf(self, 'match', self._blacklist.__contains__)
class resolver_frame:
__slots__ = ("parent", "atom", "choices", "mode", "start_point", "dbs",
"depth", "drop_cycles", "__weakref__", "ignored", "vdb_limited",
"events", "succeeded")
def __init__(self, parent, mode, atom, choices, dbs, start_point, depth,
def gen_config_protect_filter(offset, extra_protects=(), extra_disables=()):
collapsed_d, inc, colon = collapse_envd(pjoin(offset, "etc/env.d"))
collapsed_d.setdefault("CONFIG_PROTECT", []).extend(extra_protects)
collapsed_d.setdefault("CONFIG_PROTECT_MASK", []).extend(extra_disables)
r = [values.StrGlobMatch(normpath(x).rstrip("/") + "/")
for x in set(stable_unique(collapsed_d["CONFIG_PROTECT"] + ["/etc"]))]
if len(r) > 1:
r = values.OrRestriction(*r)
else:
r = r[0]
neg = stable_unique(collapsed_d["CONFIG_PROTECT_MASK"])
if neg:
if len(neg) == 1:
r2 = values.StrGlobMatch(normpath(neg[0]).rstrip("/") + "/",
negate=True)
else:
r2 = values.OrRestriction(
negate=True,
*[values.StrGlobMatch(normpath(x).rstrip("/") + "/")
for x in set(neg)])
r = values.AndRestriction(r, r2)
def parse_envmatch(value):
"""Apply a regexp to the environment."""
return packages.PackageRestriction(
'environment', DataSourceRestriction(values.AnyMatch(
values.StrRegex(value))))
def __init__(self, false_use, true_use):
v = []
if false_use:
v.append(values.ContainmentMatch2(false_use, negate=True, match_all=True))
if true_use:
v.append(values.ContainmentMatch2(true_use, match_all=True))
l = len(v)
if l == 2:
v = values.AndRestriction(*v)
elif l == 1:
v = v[0]
else:
v = values.AlwaysTrue
super().__init__('use', v)
for _name in ['match']:
PARSE_FUNCS[_name] = parserestrict.parse_funcs[_name]
for _name, _attr in [
('herd', 'herds'),
('license', 'license'),
('hasuse', 'iuse'),
('maintainer', 'maintainers'),
('owns', 'contents'),
]:
PARSE_FUNCS[_name] = parserestrict.comma_separated_containment(_attr)
del _name, _attr
class AtomIntersectsAtom(values.base):
"""Fuzzy intersection used for the revdep match.
Intended effect is roughly:
- if you query for just "dev-lang/python" it "intersects" both
"dev-lang/python" and ">=dev-lang/python-2.4"
- if you query for "=dev-lang/python-2.4" it "intersects"
">=dev-lang/python-2.4" and "dev-lang/python" but not
"