How to use the pypyr.utils.expressions.eval_string function in pypyr

To help you get started, we’ve selected a few pypyr examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pypyr / pypyr-cli / pypyr / dsl.py View on Github external
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.')
github pypyr / pypyr-cli / pypyr / context.py View on Github external
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))