Beispiel #1
0
    def calculate_children(evaluator, children):
        """
        Calculate a list of children with operators.
        """
        iterator = iter(children)
        types = evaluator.eval_element(next(iterator))
        for operator in iterator:
            try:# PATCH: Catches StopIteration error
                right = next(iterator)
                if tree.is_node(operator, 'comp_op'):  # not in / is not
                    operator = ' '.join(str(c.value) for c in operator.children)

                # handle lazy evaluation of and/or here.
                if operator in ('and', 'or'):
                    left_bools = set([left.py__bool__() for left in types])
                    if left_bools == set([True]):
                        if operator == 'and':
                            types = evaluator.eval_element(right)
                    elif left_bools == set([False]):
                        if operator != 'and':
                            types = evaluator.eval_element(right)
                    # Otherwise continue, because of uncertainty.
                else:
                    types = calculate(evaluator, types, operator,
                                      evaluator.eval_element(right))
            except StopIteration:
                debug.warning('calculate_children StopIteration %s', types)
        debug.dbg('calculate_children types %s', types)
        return types
Beispiel #2
0
        def calculate_children(evaluator, children):
            """
            Calculate a list of children with operators.
            """
            iterator = iter(children)
            types = evaluator.eval_element(next(iterator))
            for operator in iterator:
                try:  # PATCH: Catches StopIteration error
                    right = next(iterator)
                    if tree.is_node(operator, 'comp_op'):  # not in / is not
                        operator = ' '.join(str(c.value) for c in
                                            operator.children)

                    # handle lazy evaluation of and/or here.
                    if operator in ('and', 'or'):
                        left_bools = set([left.py__bool__() for left in types])
                        if left_bools == set([True]):
                            if operator == 'and':
                                types = evaluator.eval_element(right)
                        elif left_bools == set([False]):
                            if operator != 'and':
                                types = evaluator.eval_element(right)
                        # Otherwise continue, because of uncertainty.
                    else:
                        types = calculate(evaluator, types, operator,
                                          evaluator.eval_element(right))
                except StopIteration:
                    debug.warning('calculate_children StopIteration %s', types)
            debug.dbg('calculate_children types %s', types)
            return types