예제 #1
0
파일: core.py 프로젝트: tkouts/porcupine
    "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:
예제 #2
0
        '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)
예제 #3
0
}

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)
예제 #4
0
def _date_reviver(dct):
    if '__date__' in dct:
        return Date.from_iso_8601(dct['value'])
    return dct
예제 #5
0
def _date_reviver(dct):
    if '__date__' in dct:
        return Date.from_iso_8601(dct['value'])
    return dct