Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def visit_body(self,nodebody):
try:
for childNode in nodebody:
self.visit(childNode)
except AttributeError as e:
print e,astor.dump(childNode)
def visit_Expr(self,node):
if len(node.orelse) > 0:
writeCommandByName("else",[])
self.visit_body(node.orelse)
writeCommandByName("endElse",[])
elif isinstance(node.test,UnaryOp) and (isinstance(node.test.operand,Call) or isinstance(node.test.operand,Compare)):
self.visit(node.test.operand)
if(isinstance(node.test.operand,Call)):
writeCommandByName("ifNot",[2,0])
self.visit_body(node.body)
writeCommandByName("endIf",[])
if len(node.orelse) > 0:
writeCommandByName("else",[])
self.visit_body(node.orelse)
writeCommandByName("endElse",[])
else:
print "UNHANDLED IF",astor.dump(node)
#If(SLOT)
def rebuild_dbzfscript(sourceFilename,outFilename):
global output
sourceAST = astor.parsefile(sourceFilename)
if(os.path.isfile(sourceFilename+".txt")):
os.remove(sourceFilename+".txt")
f = open(sourceFilename+".txt","w")
f.write(astor.dump(sourceAST))
f.close()
output = open(outFilename,"wb")
Rebuilder().visit(sourceAST)
output.close()
def visit_body(self,nodebody):
try:
for childNode in nodebody:
self.visit(childNode)
except AttributeError as e:
print e,astor.dump(childNode)
def visit_Expr(self,node):
def visit_Assign(self,node):
if isinstance(node.value,BinOp):
params = []
if isinstance(node.value.op,Add):
params.append(0)
elif isinstance(node.value.op,Sub):
params.append(1)
elif isinstance(node.value.op,Mult):
params.append(2)
elif isinstance(node.value.op,Div):
params.append(3)
else:
print "UNIMPLEMENTED BINOP",astor.dump(node)
raise Exception("Unknown Operation!")
writeCommandByName("ModifyVar_",params+decodeVar(node.targets[0])+decodeVar(node.value.right))
else:
writeCommandByName("StoreValue",decodeVar(node.targets[0])+decodeVar(node.value))
def visit_Compare(self,node):
def visit_Assign(self,node):
if isinstance(node.value,BinOp):
params = []
if isinstance(node.value.op,Add):
params.append(0)
elif isinstance(node.value.op,Sub):
params.append(1)
elif isinstance(node.value.op,Mult):
params.append(2)
elif isinstance(node.value.op,Div):
params.append(3)
else:
print "UNIMPLEMENTED BINOP",astor.dump(node)
raise Exception("Unknown Operation!")
writeCommandByName("ModifyVar_",params+decodeVar(node.targets[0])+decodeVar(node.value.right))
else:
writeCommandByName("StoreValue",decodeVar(node.targets[0])+decodeVar(node.value))
def visit_Compare(self,node):
def visit_Compare(self,node):
params = []
if isinstance(node.ops[0],Eq):
params.append(9)
elif isinstance(node.ops[0],Gt):
params.append(10)
elif isinstance(node.ops[0],Lt):
params.append(11)
elif isinstance(node.ops[0],GtE):
params.append(12)
elif isinstance(node.ops[0],LtE):
params.append(13)
else:
print "UNIMPLEMENTED BINOP",astor.dump(node)
raise Exception("Unknown Compare")
writeCommandByName("op",params+decodeVar(node.left)+decodeVar(node.comparators[0]))
def visit_body(self,nodebody):
def visit_Compare(self,node):
params = []
if isinstance(node.ops[0],Eq):
params.append(9)
elif isinstance(node.ops[0],Gt):
params.append(10)
elif isinstance(node.ops[0],Lt):
params.append(11)
elif isinstance(node.ops[0],GtE):
params.append(12)
elif isinstance(node.ops[0],LtE):
params.append(13)
else:
print "UNIMPLEMENTED BINOP",astor.dump(node)
raise Exception("Unknown Compare")
writeCommandByName("op",params+decodeVar(node.left)+decodeVar(node.comparators[0]))
def visit_body(self,nodebody):