python Programming Glossary: ast.parse
Executing mathematical user code on a python web server, what is the simplest secure way? http://stackoverflow.com/questions/10647234/executing-mathematical-user-code-on-a-python-web-server-what-is-the-simplest-se SyntaxChecker ast.NodeVisitor def check self syntax tree ast.parse syntax self.passed True self.visit tree def visit_Call self..
Restricting Python's syntax to execute user code safely. Is this a safe approach? http://stackoverflow.com/questions/10661079/restricting-pythons-syntax-to-execute-user-code-safely-is-this-a-safe-approach SyntaxChecker ast.NodeVisitor def check self syntax tree ast.parse syntax self.visit tree def visit_Call self node if node.func.id..
Use of eval in Python? http://stackoverflow.com/questions/1087255/use-of-eval-in-python a one off and relies on simple constants only or do node ast.parse source first then keep the node around perhaps munge it with..
Using ast and whitelists to make python's eval() safe? http://stackoverflow.com/questions/12523516/using-ast-and-whitelists-to-make-pythons-eval-safe Unknown function s call.func.id def my_safe_eval s tree ast.parse s mode 'eval' cnv CleansingNodeVisitor cnv.visit tree compiled..
Simple example of how to use ast.NodeVisitor? http://stackoverflow.com/questions/1515357/simple-example-of-how-to-use-ast-nodevisitor children will also be visited . So for example... x v t ast.parse 'd x v y x ' x.visit t emits Module AugAssign Subscript Name..
How to differentiate between “a string” and “a actual code” in python? http://stackoverflow.com/questions/16809248/how-to-differentiate-between-a-string-and-a-actual-code-in-python def statement import ast with open 'mymodule.py' as f tree ast.parse f.read for node in ast.walk tree if isinstance node ast.FunctionDef..
Accessing the name that an object being created is assigned to http://stackoverflow.com/questions/3744792/accessing-the-name-that-an-object-being-created-is-assigned-to open inspect.getframeinfo caller .filename and send it to ast.parse . I don't do any error checking here because 1 this is just..
Converting a python numeric expression to LaTeX http://stackoverflow.com/questions/3867028/converting-a-python-numeric-expression-to-latex str n def generic_prec self n return 0 def py2tex expr pt ast.parse expr return LatexVisitor .visit pt.body 0 .value share improve..
Is possible to override the {…} notation so i get an OrderedDict() instead of a dict()? http://stackoverflow.com/questions/7878933/is-possible-to-override-the-notation-so-i-get-an-ordereddict-instead-of is None globals if locals is None locals globals node ast.parse open filename .read transformed DictDisplayTransformer .visit..
|