"or": lambda a, b: a or b, "and": lambda a, b: a and b, } opn1 = {"not": lambda a: not a} operators2 = frozenset(opn2.keys()) operators1 = frozenset(opn1.keys()) fn = { "len": len, "abs": abs, "str": str, "lower": lambda a: a.lower(), "upper": lambda a: a.upper(), "date": lambda a: Date.from_iso_8601(a).value, "trunc": lambda a: int(a), "round": lambda a: int(a + 0.5), "sgn": lambda a: ((a < 0 and -1) or (a > 0 and 1) or 0), "isnone": lambda a, b: a or b, "getattr": lambda a, b: get_attribute(a, [b]), } def prepare(ast): prepared = [] vars = {} for cmd in ast: cmd_code, args = cmd cmd_prep = globals().get("h_%s_prepare" % cmd_code, None) if cmd_prep is not None:
'or': lambda a, b: a or b, 'and': lambda a, b: a and b} opn1 = { "not": lambda a: not a} operators2 = frozenset(opn2.keys()) operators1 = frozenset(opn1.keys()) fn = {'len': len, 'abs': abs, 'str': str, 'lower': lambda a: a.lower(), 'upper': lambda a: a.upper(), 'date': lambda a: Date.from_iso_8601(a).value, 'trunc': lambda a: int(a), 'round': lambda a: int(a + 0.5), 'sgn': lambda a: ((a < 0 and -1) or (a > 0 and 1) or 0), 'isnone': lambda a, b: a or b, 'getattr': lambda a, b: get_attribute(a, [b])} def prepare(ast): prepared = [] vars = {} for cmd in ast: cmd_code, args = cmd cmd_prep = globals().get('h_%s_prepare' % cmd_code, None) if cmd_prep is not None: cmd_prepared = cmd_prep(args, vars)
} opn1 = { "not": lambda a: not a } operators2 = opn2.keys() operators1 = opn1.keys() fn = { 'len' : len, 'abs' : abs, 'str' : str, 'lower' : lambda a: a.lower(), 'upper' : lambda a: a.upper(), 'date' : lambda a: Date.from_iso_8601(a), 'trunc' : lambda a: int(a), 'round' : lambda a: int(a+0.5), 'sgn' : lambda a: ( (a<0 and -1) or (a>0 and 1) or 0 ), 'isnone' : lambda a,b: a or b, 'getattr' : lambda a,b: getAttribute(a, [b]) } def evaluateStack(stack, variables, forObject=None): try: op = stack.pop() except AttributeError: op = stack if op in operators2: op1 = evaluateStack(stack, variables, forObject)
def _date_reviver(dct): if '__date__' in dct: return Date.from_iso_8601(dct['value']) return dct