in perfkitbenchmarker/flag_util.py [0:0]
def parse(self, inp):
"""Parse an integer list.
Args:
inp: a string, a list, or an IntegerList.
Returns:
An iterable of integers.
Raises:
ValueError: if inp doesn't follow a format it recognizes.
"""
if isinstance(inp, IntegerList):
return inp
elif isinstance(inp, list):
return IntegerList(inp)
elif isinstance(inp, int):
return IntegerList([inp])
def HandleNonIncreasing():
if self.on_nonincreasing == IntegerListParser.WARN:
logging.warning('Integer list %s is not increasing', inp)
elif self.on_nonincreasing == IntegerListParser.EXCEPTION:
raise ValueError('Integer list %s is not increasing' % inp)
groups = inp.split(',')
result = []
for group in groups:
match = INTEGER_GROUP_REGEXP.match(
group
) or INTEGER_GROUP_REGEXP_COLONS.match(group)
if match is None:
raise ValueError('Invalid integer list %s' % inp)
elif match.group(2) is None:
val = int(match.group(1))
if _IsNonIncreasing(result, val):
HandleNonIncreasing()
result.append(val)
else:
low = int(match.group(1))
high = int(match.group(3))
step = int(match.group(5)) if match.group(5) is not None else 1
step = -step if step > 0 and low > high else step
if high <= low or (_IsNonIncreasing(result, low)):
HandleNonIncreasing()
result.append((low, high, step))
return IntegerList(result)