def buildexec(self, target, schema, args, argschemas, newname, references, tonative):
predicates = args[:-1][0::3]
antipredicates = args[:-1][1::3]
consequents = args[:-1][2::3]
alternate = args[-1]
def isNone(expression):
if sys.version_info[0] <= 2:
return isinstance(expression, ast.Name) and expression.id == "None" and isinstance(expression.ctx, ast.Load)
else:
return isinstance(expression, ast.NameConstant) and expression.value is None
def replaceNone(expression):
return expression
if isNullInt(schema):
def replaceNone(expression):
if isNone(expression):
return ast.Num(Number._intNaN)
else:
return expression
elif isNullFloat(schema):
def replaceNone(expression):
if isNone(expression):
return ast.Num(Number._floatNaN)
else:
return expression
chain = statementsToAst("""
OUT = ALT
""", OUT = target, ALT = replaceNone(alternate))
for predicate, consequent in reversed(list(zip(predicates, consequents))):
next = statementsToAst("""
if PRED:
OUT = CONS
else:
REPLACEME
""", OUT = target, PRED = predicate, CONS = replaceNone(consequent))
next[0].orelse = [chain[0]] # replacing REPLACEME
chain = next
return chain
评论列表
文章目录