How to use the astor.ExplicitNodeVisitor function in astor

To help you get started, we’ve selected a few astor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dantarion / bbtools / bbcf_bbtag_script_rebuilder.py View on Github external
temp = namedValueLookup.get(oValue.id)
            if temp is not None:
                myParams[index] = int(temp)
            else:
                buttonstr = oValue.id[-1]
                directionstr = oValue.id[:-1]
                myParams[index] = (int(namedButtonLookup[buttonstr]) << 8) + int(namedDirectionLookup[directionstr])
        else:
            raise Exception("Unknown Type" + str(type(oValue)))
    output.write(struct.pack(MODE+"I",id))
    if "format" in cmdData:
        output.write(struct.pack(MODE+cmdData["format"],*myParams))
    elif cmdData["size"] > 4:
        output.write(myParams[0].decode('hex'))

class Rebuilder(astor.ExplicitNodeVisitor):
    def visit_Module(self,node):
        global output
        global root
        root = node
        stateCount = 0
        output.write(struct.pack(MODE+"I",stateCount))
        for function in node.body:
            if type(function) != FunctionDef:
                raise Exception("Root level elements must be functions")
            if function.decorator_list[0].id != "State":
                continue
            function._index = stateCount
            stateCount += 1
            if function.name.startswith('__') and function.name[2].isdigit():
                function.name = function.name[2:]
            if '__sp__' in function.name:
github dantarion / bbtools / dbfz_script_rebuilder.py View on Github external
myParams[index] = oValue.n
        # elif isinstance(oValue,Name):
            # myParams[index] = int(namedValueLookup[oValue.id])
        else:
            raise Exception("Unknown Type" + str(type(oValue)))
    output.write(struct.pack(MODE+"I",id))
    if cmdData.get('format', "notempty") == "":
        return
    if cmdData.get('size', 5) == 4:
        return
    if "format" in cmdData:
        output.write(struct.pack(MODE+cmdData["format"],*myParams))
    else:
        output.write(myParams[0].decode('hex'))

class Rebuilder(astor.ExplicitNodeVisitor):
    def visit_Module(self,node):
        global output
        global root
        root = node
        stateCount = 0
        futtobiBGTransVisited = False
        cmnActLoseVisited = False
        output.write(struct.pack(MODE+"I",stateCount))
        for function in node.body:
            if type(function) != FunctionDef:
                raise Exception("Root level elements must be functions")
            if function.name[:2] == '__' and function.name[2].isdigit():
                function.name = function.name[2:]
            if function.decorator_list[0].id != "State":
                continue
            if function.name == "CmnActFuttobiBGTrans" and not futtobiBGTransVisited:
github dantarion / bbtools / gg_rev_script_rebuilder.py View on Github external
myParams[index] = oValue.n
        elif isinstance(oValue,Name):
            myParams[index] = int(named_value_lookup.value_for_name(commandDB[str(id)]["name"], oValue.id))
        else:
            raise Exception("Unknown Type" + str(type(oValue)))
    output.write(struct.pack(MODE+"I",id))
    if cmdData.get('format', "notempty") == "":
        return
    if cmdData.get('size', 5) == 4:
        return
    if "format" in cmdData:
        output.write(struct.pack(MODE+cmdData["format"],*myParams))
    else:
        output.write(myParams[0].decode('hex'))

class Rebuilder(astor.ExplicitNodeVisitor):
    def visit_Module(self,node):
        global output
        global root
        root = node
        stateCount = 0
        output.write(struct.pack(MODE+"I",stateCount))
        for function in node.body:
            if type(function) != FunctionDef:
                raise Exception("Root level elements must be functions")
            if function.name[:2] == '__' and function.name[2].isdigit():
                function.name = function.name[2:]
            if function.decorator_list[0].id != "State":
                continue
            function._index = stateCount
            stateCount += 1
            output.write(struct.pack(MODE+"32sI",function.name,0xFADEF00D))
github dantarion / bbtools / bbcpex_script_rebuilder.py View on Github external
pass
        elif isinstance(oValue,float):
            pass
        elif isinstance(oValue,Str):
            myParams[index] = oValue.s
        elif isinstance(oValue,Num):
            myParams[index] = oValue.n
        else:
            raise Exception("Unknown Type" + str(type(oValue)))
    output.write(struct.pack(MODE+"I",id))
    if "format" in cmdData:
        output.write(struct.pack(MODE+cmdData["format"],*myParams))
    else:
        output.write(myParams[0].decode('hex'))

class Rebuilder(astor.ExplicitNodeVisitor):
    def visit_Module(self,node):
        global output
        global root
        root = node
        stateCount = 0
        output.write(struct.pack(MODE+"I",stateCount))
        for function in node.body:
            if type(function) != FunctionDef:
                raise Exception("Root level elements must be functions")
            if function.decorator_list[0].id != "State":
                continue
            function._index = stateCount
            stateCount += 1
            output.write(struct.pack(MODE+"32sI",function.name,0xFADEF00D))
        node._dataStart = output.tell()
        output.seek(0)