summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/dep/__init__.py24
-rw-r--r--pym/portage/tests/dep/test_use_reduce.py55
2 files changed, 72 insertions, 7 deletions
diff --git a/pym/portage/dep/__init__.py b/pym/portage/dep/__init__.py
index 32d3155ab..8d9d185ad 100644
--- a/pym/portage/dep/__init__.py
+++ b/pym/portage/dep/__init__.py
@@ -214,7 +214,8 @@ def paren_enclose(mylist):
mystrparts.append(x)
return " ".join(mystrparts)
-def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[]):
+def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], is_src_uri=False, \
+ allow_src_uri_file_renames=False):
"""
Takes a dep string and reduces the use? conditionals out, leaving an array
with subarrays. All redundant brackets are removed.
@@ -261,14 +262,18 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[]):
level = 0
stack = [[]]
need_bracket = False
+ need_simple_token = False
for token in mysplit:
if token == "(":
+ if need_simple_token:
+ raise portage.exception.InvalidDependString(
+ _("malformed syntax: '%s'") % depstr)
need_bracket = False
stack.append([])
level += 1
elif token == ")":
- if need_bracket:
+ if need_bracket or need_simple_token:
raise portage.exception.InvalidDependString(
_("malformed syntax: '%s'") % depstr)
if level > 0:
@@ -302,22 +307,31 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[]):
raise portage.exception.InvalidDependString(
_("malformed syntax: '%s'") % depstr)
elif token == "||":
- if need_bracket:
+ if need_bracket or is_src_uri:
raise portage.exception.InvalidDependString(
_("malformed syntax: '%s'") % depstr)
need_bracket = True
stack[level].append(token)
+ elif token == "->":
+ if not allow_src_uri_file_renames or not is_src_uri or need_simple_token:
+ raise portage.exception.InvalidDependString(
+ _("SRC_URI arrow not allowed: '%s'") % depstr)
+ need_simple_token = True
+ stack[level].append(token)
else:
- if need_bracket or "(" in token or ")" in token or "|" in token:
+ if need_bracket or "(" in token or ")" in token or "|" in token or \
+ (need_simple_token and "/" in token):
raise portage.exception.InvalidDependString(
_("malformed syntax: '%s'") % depstr)
if token[-1] == "?":
need_bracket = True
+ else:
+ need_simple_token = False
stack[level].append(token)
- if level != 0 or need_bracket:
+ if level != 0 or need_bracket or need_simple_token:
raise portage.exception.InvalidDependString(
_("malformed syntax: '%s'") % depstr)
diff --git a/pym/portage/tests/dep/test_use_reduce.py b/pym/portage/tests/dep/test_use_reduce.py
index a4a23242d..ed77c40a3 100644
--- a/pym/portage/tests/dep/test_use_reduce.py
+++ b/pym/portage/tests/dep/test_use_reduce.py
@@ -7,17 +7,20 @@ from portage.dep import use_reduce
class UseReduceTestCase(object):
def __init__(self, deparray, uselist=[], masklist=[], \
- matchall=0, excludeall=[], expected_result=None):
+ matchall=0, excludeall=[], is_src_uri=False, \
+ allow_src_uri_file_renames=False, expected_result=None):
self.deparray = deparray
self.uselist = uselist
self.masklist = masklist
self.matchall = matchall
self.excludeall = excludeall
+ self.is_src_uri = is_src_uri
+ self.allow_src_uri_file_renames = allow_src_uri_file_renames
self.expected_result = expected_result
def run(self):
return use_reduce(self.deparray, self.uselist, self.masklist, \
- self.matchall, self.excludeall)
+ self.matchall, self.excludeall, self.is_src_uri, self.allow_src_uri_file_renames)
class UseReduce(TestCase):
@@ -202,6 +205,43 @@ class UseReduce(TestCase):
"foo? ( A ) foo? ( B )",
uselist = ["foo"],
expected_result = ["A", "B"]),
+
+ #SRC_URI stuff
+ UseReduceTestCase(
+ "http://foo/bar -> blah.tbz2",
+ is_src_uri = True,
+ allow_src_uri_file_renames = True,
+ expected_result = ["http://foo/bar", "->", "blah.tbz2"]),
+ UseReduceTestCase(
+ "foo? ( http://foo/bar -> blah.tbz2 )",
+ uselist = [],
+ is_src_uri = True,
+ allow_src_uri_file_renames = True,
+ expected_result = []),
+ UseReduceTestCase(
+ "foo? ( http://foo/bar -> blah.tbz2 )",
+ uselist = ["foo"],
+ is_src_uri = True,
+ allow_src_uri_file_renames = True,
+ expected_result = ["http://foo/bar", "->", "blah.tbz2"]),
+ UseReduceTestCase(
+ "http://foo/bar -> bar.tbz2 foo? ( ftp://foo/a )",
+ uselist = [],
+ is_src_uri = True,
+ allow_src_uri_file_renames = True,
+ expected_result = ["http://foo/bar", "->", "bar.tbz2"]),
+ UseReduceTestCase(
+ "http://foo/bar -> bar.tbz2 foo? ( ftp://foo/a )",
+ uselist = ["foo"],
+ is_src_uri = True,
+ allow_src_uri_file_renames = True,
+ expected_result = ["http://foo/bar", "->", "bar.tbz2", "ftp://foo/a"]),
+ UseReduceTestCase(
+ "http://foo.com/foo http://foo/bar -> blah.tbz2",
+ uselist = ["foo"],
+ is_src_uri = True,
+ allow_src_uri_file_renames = True,
+ expected_result = ["http://foo.com/foo", "http://foo/bar", "->", "blah.tbz2"]),
)
test_cases_xfail = (
@@ -221,6 +261,17 @@ class UseReduce(TestCase):
UseReduceTestCase("a? A"),
UseReduceTestCase("( || ( || || ( A ) foo? ( B ) ) )"),
UseReduceTestCase("( || ( || bar? ( A ) foo? ( B ) ) )"),
+
+ #SRC_URI stuff
+ UseReduceTestCase("http://foo/bar -> blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = False),
+ UseReduceTestCase("|| ( http://foo/bar -> blah.tbz2 )", is_src_uri = True, allow_src_uri_file_renames = True),
+ UseReduceTestCase("http://foo/bar -> foo? ( ftp://foo/a )", is_src_uri = True, allow_src_uri_file_renames = True),
+ UseReduceTestCase("http://foo/bar blah.tbz2 ->", is_src_uri = True, allow_src_uri_file_renames = True),
+ UseReduceTestCase("-> http://foo/bar blah.tbz2 )", is_src_uri = True, allow_src_uri_file_renames = True),
+ UseReduceTestCase("http://foo/bar ->", is_src_uri = True, allow_src_uri_file_renames = True),
+ UseReduceTestCase("http://foo/bar -> foo? ( http://foo.com/foo )", is_src_uri = True, allow_src_uri_file_renames = True),
+ UseReduceTestCase("foo? ( http://foo/bar -> ) blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = True),
+ UseReduceTestCase("http://foo/bar -> foo/blah.tbz2", is_src_uri = True, allow_src_uri_file_renames = True),
)
for test_case in test_cases: