return " ".join(mystrparts)
def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], is_src_uri=False, \
- allow_src_uri_file_renames=False, opconvert=False, flat=False):
+ allow_src_uri_file_renames=False, opconvert=False, flat=False, is_valid_flag=None):
"""
Takes a dep string and reduces the use? conditionals out, leaving an array
with subarrays. All redundant brackets are removed.
else:
flag = conditional[:-1]
is_negated = False
-
- if not flag:
- raise portage.exception.InvalidDependString(
- _("malformed syntax: '%s'") % depstr)
+
+ if is_valid_flag:
+ if not is_valid_flag(flag):
+ raise portage.exception.InvalidDependString(
+ _("malformed syntax: '%s'") % depstr)
+ else:
+ if _valid_use_re.match(flag) is None:
+ raise portage.exception.InvalidDependString(
+ _("malformed syntax: '%s'") % depstr)
if is_negated and flag in excludeall:
return False
_conditionals_class = portage.cache.mappings.slot_dict_class(
("disabled", "enabled", "equal", "not_equal"), prefix="")
- _valid_use_re = re.compile(r'^[A-Za-z0-9][A-Za-z0-9+_@-]*$')
-
def __init__(self, use):
enabled_flags = []
disabled_flags = []
break
def _validate_flag(self, token, flag):
- if self._valid_use_re.match(flag) is None:
+ if _valid_use_re.match(flag) is None:
raise InvalidAtom(_("Invalid use dep: '%s'") % (token,))
return flag
_atom_wildcard_re = re.compile('(?P<simple>(' + _extended_cat + ')/(' + _extended_pkg + '))(:(?P<slot>' + _slot + '))?$')
+_valid_use_re = re.compile(r'^[A-Za-z0-9][A-Za-z0-9+_@-]*$')
+
def isvalidatom(atom, allow_blockers=False, allow_wildcard=False):
"""
Check to see if a depend atom is valid
class UseReduceTestCase(object):
def __init__(self, deparray, uselist=[], masklist=[], \
matchall=0, excludeall=[], is_src_uri=False, \
- allow_src_uri_file_renames=False, opconvert=False, flat=False, expected_result=None):
+ allow_src_uri_file_renames=False, opconvert=False, flat=False, expected_result=None, is_valid_flag=None):
self.deparray = deparray
self.uselist = uselist
self.masklist = masklist
self.allow_src_uri_file_renames = allow_src_uri_file_renames
self.opconvert = opconvert
self.flat = flat
+ self.is_valid_flag = is_valid_flag
self.expected_result = expected_result
def run(self):
return use_reduce(self.deparray, self.uselist, self.masklist, \
self.matchall, self.excludeall, self.is_src_uri, self.allow_src_uri_file_renames, \
- self.opconvert, self.flat)
+ self.opconvert, self.flat, self.is_valid_flag)
class UseReduce(TestCase):
- def testUseReduce(self):
+ def always_true(self, ununsed_parameter):
+ return True
+
+ def always_false(self, ununsed_parameter):
+ return False
+ def testUseReduce(self):
+
test_cases = (
UseReduceTestCase(
"a? ( A ) b? ( B ) !c? ( C ) !d? ( D )",
uselist = ["foo"],
flat = True,
expected_result = ["A", "B"]),
-
+
+ UseReduceTestCase(
+ "foo? ( A )",
+ uselist = ["foo"],
+ is_valid_flag = self.always_true,
+ expected_result = ["A"]),
+
+ UseReduceTestCase(
+ "foo? ( A )",
+ is_valid_flag = self.always_true,
+ expected_result = []),
)
test_cases_xfail = (
"A",
opconvert = True,
flat = True),
+
+ UseReduceTestCase("1.0? ( A )"),
+ UseReduceTestCase("!1.0? ( A )"),
+ UseReduceTestCase("!? ( A )"),
+ UseReduceTestCase("!?? ( A )"),
+ UseReduceTestCase(
+ "foo? ( A )",
+ is_valid_flag = self.always_false,
+ ),
+ UseReduceTestCase(
+ "foo? ( A )",
+ uselist = ["foo"],
+ is_valid_flag = self.always_false,
+ ),
)
for test_case in test_cases: