def getArgumentValue(self, token): if token[0] in quotechars: # it's a string return token[1:-1] # strip the quotation marks if token == BGNLIST: self.parendepth += 1 return list(self.getArguments(None)[0]) if token == BGNTUPLE: self.parendepth += 1 return tuple(self.getArguments(None)[0]) try: # is it a number? val = string2number(token) except ValueError: # no, it's not pass else: return val # yes, it's a number # Is it None? if token == 'None': return None if token == 'True': return True if token == 'False': return False # Is it a function or variable defined in the OOF namespace? try: argval = utils.OOFeval_r(token) except KeyError: raise ooferror.ErrDataFileError("Incomprehensible argument: %s" % token) # If it's a function, the next token is an open paren. nexttoken = self.nextToken() if nexttoken == BGNARG: self.parendepth += 1 args, kwargs = self.getArguments(argval) return argval(*args, **kwargs) if nexttoken == BGNINDEX: self.parendepth += 1 args, kwargs = self.getArguments(argval) return argval[args[0]] self.pushbackToken(nexttoken) # to be read again return argval # arg was an OOF namespace variable
def objectKeyCB(menuitem, obj, key): menuitem.parser.mode.defineObjKey(utils.OOFeval_r(obj), key)