I want an easy way to do a "calculator api" in python.
Right now I don't care much about the exact set of features the calculator is going to support.
I want it to receive a string, say "1+1" and return a string with the result, in our case "2".
Is there a way to make eval safe for such a thing?
For a start I would do
env = {}
env["locals"] = None
env["globals"] = None
env["__name__"] = None
env["__file__"] = None
env["__builtins__"] = None
eval(users_str, env)
so that the caller cannot mess with my local variables (or see them).
But I am sure I am overseeing a lot here. Please help: are eval's security issues fixable or are there just too many tiny details to get it working right?