Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_value(self, context):
"""Run python eval on the input string."""
if self.value:
return expressions.eval_string(self.value, context)
else:
# Empty input raises cryptic EOF syntax err, this more human
# friendly
raise ValueError('!py string expression is empty. It must be a '
'valid python expression instead.')
the potential for damage is great.
The eval uses the current context object as the namespace. This means
if you have context['mykey'], in the input_string expression you can
use the key directly as a variable like this: "mykey == 'mykeyvalue'".
Both __builtins__ and context are available to the eval expression.
Args:
input_string: expression to evaluate.
Returns:
Whatever object results from the string expression valuation.
"""
return expressions.eval_string(input_string, dict(self))