def new_execute(self,command,envvar={}): if envvar.get("print",False): print "command:",command envvar["wait"] = False funcstack = [[[""]]] # of ["name",arg1,arg2,...,[argn1,operator1,argn2,operator2,...]] isstring = False escaped = False try: for letter in command: if escaped: funcstack[-1][-1][-1]+=letter escaped = False elif letter == "\\": escaped = True elif letter == '"': isstring = not isstring elif isstring: funcstack[-1][-1][-1]+=letter else: if letter in (" ",",",")"): pass if letter == "(": funcstack.append([""]) elif letter == ",": "sachen wie strings, numbers, = oder . auswerten" funcstack[-1].append("") elif letter == ")": args = funcstack.pop(-1) name = funcstack[-1].pop(-1) result=self.call_function(name,args) funcstack[-1].append(result) elif letter in "=<>": if letter == "=": "testen ob letzter Buchstabe davon in !,<,> war" elif letter in ".": pass else: funcstack[-1][-1][-1]+=letter """( -> argumente fangen an (neue function in funcstack) , -> nächstes Argument (letzte function ausführen, neue anhängen) ) -> letzten 2 functionen ausführen = -> davor und danach vergleichen -> vergleichsfunktion anhängen . -> attributefunktion anhängen""" if envvar["wait"]: "neuen command string aus funcstack erstellen" break print funcstack return funcstack[0][0] #String if command.startswith("\\"): if command[1] == "(" and command[-1] == ")": return command[2:-1] return command[1:] #Shortcuts command = StandartCommands.shortcuts.get(command,command) #Numbers split = self.split(command,".") if split[0].isdigit(): if len(split) == 1: return int(command) if len(split) == 2 and split[1].isdigit(): return float(command) return command #Attributes elif len(split)!=1: objexpr="".join(split[:-1]) obj=self.execute(objexpr,envvar) attr=split[-1] return self.get_attribute(obj,attr) #Comparison split = self.split(command,"=") if len(split)!=1: return StandartCommands.isequal((self,envvar), *[self.execute(j,envvar) for j in split]) #Everything not yet proofed except functions i = command.find("(") if i == -1: return command except: print "Error executing:", command raise
def new_execute(self, command, envvar={}): if envvar.get("print", False): print "command:", command envvar["wait"] = False funcstack = [[[ "" ]]] # of ["name",arg1,arg2,...,[argn1,operator1,argn2,operator2,...]] isstring = False escaped = False try: for letter in command: if escaped: funcstack[-1][-1][-1] += letter escaped = False elif letter == "\\": escaped = True elif letter == '"': isstring = not isstring elif isstring: funcstack[-1][-1][-1] += letter else: if letter in (" ", ",", ")"): pass if letter == "(": funcstack.append([""]) elif letter == ",": "sachen wie strings, numbers, = oder . auswerten" funcstack[-1].append("") elif letter == ")": args = funcstack.pop(-1) name = funcstack[-1].pop(-1) result = self.call_function(name, args) funcstack[-1].append(result) elif letter in "=<>": if letter == "=": "testen ob letzter Buchstabe davon in !,<,> war" elif letter in ".": pass else: funcstack[-1][-1][-1] += letter """( -> argumente fangen an (neue function in funcstack) , -> nächstes Argument (letzte function ausführen, neue anhängen) ) -> letzten 2 functionen ausführen = -> davor und danach vergleichen -> vergleichsfunktion anhängen . -> attributefunktion anhängen""" if envvar["wait"]: "neuen command string aus funcstack erstellen" break print funcstack return funcstack[0][0] #String if command.startswith("\\"): if command[1] == "(" and command[-1] == ")": return command[2:-1] return command[1:] #Shortcuts command = StandartCommands.shortcuts.get(command, command) #Numbers split = self.split(command, ".") if split[0].isdigit(): if len(split) == 1: return int(command) if len(split) == 2 and split[1].isdigit(): return float(command) return command #Attributes elif len(split) != 1: objexpr = "".join(split[:-1]) obj = self.execute(objexpr, envvar) attr = split[-1] return self.get_attribute(obj, attr) #Comparison split = self.split(command, "=") if len(split) != 1: return StandartCommands.isequal( (self, envvar), *[self.execute(j, envvar) for j in split]) #Everything not yet proofed except functions i = command.find("(") if i == -1: return command except: print "Error executing:", command raise
def execute(self,command,envvar=None,p=False): if envvar == None: envvar = {} if p: envvar["print"] = True p = False if envvar.get("print",False): print "command:",command try: #String if command.startswith("\\"): if command[1] == "(" and command[-1] == ")": return command[2:-1] return command[1:] #Shortcuts command = StandartCommands.shortcuts.get(command,command) #Numbers split = self.split(command,".") if split[0].isdigit(): if len(split) == 1: return int(command) if len(split) == 2 and split[1].isdigit(): return float(command) return command #Attributes elif len(split)!=1: objexpr="".join(split[:-1]) obj=self.execute(objexpr,envvar) attr=split[-1] return self.get_attribute(obj,attr) #Comparison split = self.split(command,"=") if len(split)!=1: return StandartCommands.isequal((self,envvar), *[self.execute(j,envvar) for j in split]) #Everything not yet proofed except functions i = command.find("(") if i == -1: return command #Function calls func = command[:i] args = self.split(command[i+1:-1]) if args == [""]: args = [] if StandartCommands.branch.has_key(func): branch = StandartCommands.branch[func] return branch((self,envvar),*args) else: args = [self.execute(j,envvar) for j in args] function = StandartCommands.commands.get(func,None) if function == None: for commandset in self.AdditionalCommandsets: function = commandset.get(func,None) if function != None: break if function == None: print "function", func, "not found" function = StandartCommands.dummi return function((self,envvar),*args) except: print "Error executing:", command raise
def execute(self, command, envvar=None, p=False): if envvar == None: envvar = {} if p: envvar["print"] = True p = False if envvar.get("print", False): print "command:", command try: #String if command.startswith("\\"): if command[1] == "(" and command[-1] == ")": return command[2:-1] return command[1:] #Shortcuts command = StandartCommands.shortcuts.get(command, command) #Numbers split = self.split(command, ".") if split[0].isdigit(): if len(split) == 1: return int(command) if len(split) == 2 and split[1].isdigit(): return float(command) return command #Attributes elif len(split) != 1: objexpr = "".join(split[:-1]) obj = self.execute(objexpr, envvar) attr = split[-1] return self.get_attribute(obj, attr) #Comparison split = self.split(command, "=") if len(split) != 1: return StandartCommands.isequal( (self, envvar), *[self.execute(j, envvar) for j in split]) #Everything not yet proofed except functions i = command.find("(") if i == -1: return command #Function calls func = command[:i] args = self.split(command[i + 1:-1]) if args == [""]: args = [] if StandartCommands.branch.has_key(func): branch = StandartCommands.branch[func] return branch((self, envvar), *args) else: args = [self.execute(j, envvar) for j in args] function = StandartCommands.commands.get(func, None) if function == None: for commandset in self.AdditionalCommandsets: function = commandset.get(func, None) if function != None: break if function == None: print "function", func, "not found" function = StandartCommands.dummi return function((self, envvar), *args) except: print "Error executing:", command raise