def visitAugAssign(self, node, walker): """Makes a note that augmented assignment is in use. Note that although augmented assignment of attributes and subscripts is disallowed, augmented assignment of names (such as 'n += 1') is allowed. This could be a problem if untrusted code got access to a mutable database object that supports augmented assignment. """ if node.node.__class__.__name__ == 'Name': node = walker.defaultVisitNode(node) newnode = ast.Assign( [ast.AssName(node.node.name, OP_ASSIGN)], ast.CallFunc(_inplacevar_name, [ ast.Const(node.op), ast.Name(node.node.name), node.expr, ]), ) newnode.lineno = node.lineno return newnode else: node.node.in_aug_assign = True return walker.defaultVisitNode(node)
for child in node.getChildren(): if isinstance(child, ast.Node): rmLineno(child) def stmtNode(txt): """Make a "clean" statement node.""" node = parse(txt).node.nodes[0] rmLineno(node) return node # The security checks are performed by a set of six functions that # must be provided by the restricted environment. _apply_name = ast.Name("_apply_") _getattr_name = ast.Name("_getattr_") _getitem_name = ast.Name("_getitem_") _getiter_name = ast.Name("_getiter_") _print_target_name = ast.Name("_print") _write_name = ast.Name("_write_") _inplacevar_name = ast.Name("_inplacevar_") # Constants. _None_const = ast.Const(None) _write_const = ast.Const("write") _printed_expr = stmtNode("_print()").expr _print_target_node = stmtNode("_print = _print_()")