Skip to content
Snippets Groups Projects
Commit 666c5e91 authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

mkexp: Changed to support lists in expressions.

* Changed to support list valued expressions
* Changed to support expressions in lists
parent d965a55b
No related branches found
No related tags found
No related merge requests found
......@@ -178,18 +178,42 @@ class ExpConfig(ConfigObj):
raise ValueError("invalid date/time '{0}'".format(value))
return [numbers[i] for i in [0,1,2,4,6,8]]
def eval_value(value):
'''
Evaluate key as python expression,
return as string or sequence of strings.
'''
result = eval(value)
if isinstance(result, (list, tuple)):
result = map(str, result)
else:
result = str(result)
return result
def eval_expression(value):
'''
Check if value is a supported expression.
If so, evaluate and return result, otherwise just pass through.
'''
match = re.match(r'^eval\((.*)\)$', value)
if match:
result = eval_value(match.group(1))
else:
match = re.match(r'^split_date\((.*)\)$', value)
if match:
result = split_date(match.group(1))
else:
result = value
return result
# Interpolate and evaluate keys if they are an expression
def eval_key(section, key):
try:
value = section[key]
if isinstance(value, basestring):
match = re.match(r'^eval\((.*)\)$', value)
if match:
value = str(eval(match.group(1)))
else:
match = re.match(r'^split_date\((.*)\)$', value)
if match:
value = split_date(match.group(1))
if isinstance(value, (list, tuple)):
value = map(eval_expression, value)
elif isinstance(value, basestring):
value = eval_expression(value)
except (InterpolationError, ValueError) as error:
raise ExpConfigError(error.message, key)
section[key] = value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment