def run(self): f = False for m in self.valid: if self.method in m[0]: if self.method in m[1].banned and not self.ab: f = False break if self.de: if self.method != "var": args2pass = "" args2pass = "******".join(self.vals) args2pass = intp.eval(args2pass) else: args2pass = "" args2pass = "******".join(self.vals) a = tokenz.tokenize(args2pass) args2pass = intp.eval(tokenz.detokenize(a[1:])) a[0].type = "ident" args2pass = [a[0]] + args2pass else: args2pass = self.a return_val = m[1].funcs[m[0].index(self.method)](args2pass) f = True break if not f: return_val = None raise UndefinedFunctionError( "Attempted to run function %s, but was undefined" % self.method) return return_val
def run(self): f = False for m in self.valid: if self.method in m[0]: if self.method in m[1].banned and not self.ab: f = False break if self.de: if self.method != "var": args2pass = "" args2pass = "******".join(self.vals) args2pass = intp.eval(args2pass) else: args2pass = "" args2pass = "******".join(self.vals) a = tokenz.tokenize(args2pass) args2pass = intp.eval(tokenz.detokenize(a[1:])) a[0].type = "ident" args2pass = [a[0]] + args2pass else: args2pass = self.a return_val = m[1].funcs[m[0].index(self.method)](args2pass) f = True break if not f: return_val = None raise UndefinedFunctionError("Attempted to run function %s, but was undefined" % self.method) return return_val
def valueify(args): x = [] for t in args: if t.type == "value": y = tokenz.tokenize(t.val)[0] x.append(y) else: x.append(t) return x
def eval(self, code): # Code is string... self.tokens = tokenz.tokenize(str(code)) # print("%s tokenized = %s" %(code, str(self.tokens))) self.pos = 0 returns = [] while self.tokens != []: try: tok = self.tokens[self.pos] if tok.type == "call": args = self.get_args(self.tokens) # print("args got: %s" % str(args)) if args[0] == "notAfunc": self.tokens = args[1] returns.append(args[2]) # print("Not a func, appending %s" % str(args[2].val)) else: self.tokens = args[1] returns.append(methodMang.Call(tok.val, args[0]).run()) elif tok.type == "numb": self.crunch() returns.append(tok) elif tok.type == "str": self.crunch() returns.append(tok) elif tok.type == "bool": self.crunch() returns.append(tok) except IndexError: break # print(returns) return returns
def eval(self, code): # Code is string... self.tokens = tokenz.tokenize(str(code)) self.pos = 0 returns = [] while self.tokens != []: try: tok = self.tokens[0] if tok.type == "call": args = self.func( self.tokens ) # [isFunction, resulting token stream, arguments] if not args[0]: self.tokens = args[1][1:] that = tokenz.Token("ident", args[1][0].val) that.id = args[1][0].val this = tokenz.Token( "value", methodMang.Call("get", [that], True, False).run().val) returns.append(this) else: returns.append( methodMang.Call(tok.val, _2list(args[2]), False).run()) self.tokens = args[1] elif tok.type == "codeblock": self.crunch() returns.append(tok) elif tok.type == "ident": self.crunch() returns.append(tok) elif tok.type == "numb": self.crunch() returns.append(tok) elif tok.type == "str": self.crunch() returns.append(tok) elif tok.type == "bool": self.crunch() returns.append(tok) elif tok.type == "func": if len(self.tokens) > 2: if self.tokens[1].val == "(": i = 1 d = 1 while True: i += 1 if self.tokens[i].val == "(": d += 1 elif self.tokens[i].val == ")": d -= 1 if d == 0: break that = self.tokens[1:i + 1] that[0] = tok that.pop() # Get rid of ) methodMang.Call("call", that, True, False).run() self.tokens = self.tokens[i + 2:] returns.append(tokenz.Token("None", None)) self.crunch() returns.append(tok) elif tok.type == "codeblock": self.crunch() returns.append(tok) except IndexError: break return returns