I plan to use these features in a web environment, so I am worried that these features may be used and used to execute malicious software on the server.
Edit: I am not fulfilling the result. I parse the AST tree and / or catch a SyntaxError.
This is the code in question:
try: #compile the code and check for syntax errors compile(code_string, filename, "exec") except SyntaxError, value: msg = value.args[0] (lineno, offset, text) = value.lineno, value.offset, value.text if text is None: return [{"line": 0, "offset": 0, "message": u"Problem decoding source"}] else: line = text.splitlines()[-1] if offset is not None: offset = offset - (len(text) - len(line)) else: offset = 0 return [{"line": lineno, "offset": offset, "message": msg}] else: #no syntax errors, check it with pyflakes tree = compiler.parse(code_string) w = checker.Checker(tree, filename) w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
checker.Checker is a pyflakes class that parses the AST tree.
source share