__init__.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:ITAP-django 作者: krivers 项目源码 文件源码
def specialFunctions(cv, old, new):
    if type(old) == type(new) == list:
        log("individualize\tspecialFunctions\tWhy are we comparing lists?: " + str(cv) + ";" + printFunction(old) + ";" + printFunction(new), "bug")
        return cv
    rev = neg = False
    if (hasattr(old, "reversed") and old.reversed and (not hasattr(old, "multCompFixed"))):
        rev = True

    if (hasattr(old, "negated") and old.negated):
        neg = True

    if rev and neg:
        (old, new) = (negate(undoReverse(old)), negate(undoReverse(new)))
    elif rev:
        (old, new) = (undoReverse(old), undoReverse(new))
    elif neg:
        (old, new) = (negate(old), negate(new))
        if type(old) == ast.UnaryOp and type(old.op) == ast.Not and \
            type(new) == ast.UnaryOp and type(new.op) == ast.Not:
            # Just get rid of them
            old = old.operand
            new = new.operand

    if hasattr(old, "num_negated") and old.num_negated:
        origNew = deepcopy(new)
        (old, new) = (num_negate(old), num_negate(new))
        if new == None: # couldn't reverse the new operator
            # To get here, we must have a binary operator. Go up a level and negate the right side
            cvCopy = cv.deepcopy()
            parentSpot = deepcopy(cvCopy.traverseTree(cvCopy.start))
            if type(parentSpot) == ast.BinOp:
                cvCopy.path = cvCopy.path[1:]
                cvCopy.oldSubtree = parentSpot
                cvCopy.newSubtree = deepcopy(parentSpot)
                cvCopy.newSubtree.op = origNew
                cvCopy.newSubtree.right = num_negate(cvCopy.newSubtree.right)
                cvCopy = orderedBinOpSpecialFunction(cvCopy) # just in case
                return cvCopy
            else:
                log("individualize\tspecialFunctions\tWhere are we? " + str(type(parentSpot)), "bug")

    #if (hasattr(old, "inverted") and old.inverted):
    #   (old, new) = (invert(old), invert(new))
    cv.oldSubtree = old
    cv.newSubtree = new
    return cv
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号