Exemple #1
0
    def do_expression(cls, data, ctx=None):

        if ctx:
            for n in data:
                if isinstance(n, Variable):
                    n.ctx = ctx

        it = iter(data)
        first, res = next(it), next(it)
        while True:
            try:
                op = OPRT.get(res, None)
                if op:
                    second = next(it)
                    first = op(cls.prepare( first ), cls.prepare( second ))

                    if op == OPRT['and'] and not first:
                        raise StopIteration

                    elif op == OPRT['or'] and first:
                        raise StopIteration

                res = next(it)
            except StopIteration:
                break
        return first
Exemple #2
0
    def value(self):
        it = iter(self.data)
        try:
            first = next(it)
            while True:
                res = next(it)
                op = OPRT.get(res.strip(), None)
                if op:
                    second = next(it)
                    first = op(first, second)

                    if op == OPRT['and'] and not first:
                        raise StopIteration

                    elif op == OPRT['or'] and first:
                        raise StopIteration

        except StopIteration:
            while isinstance(first, Variable):
                first = first.value
            return first
Exemple #3
0
    def value(self):
        it = iter(self.data)
        try:
            first = next(it)
            while True:
                res = next(it)
                op = OPRT.get(res.strip(), None)
                if op:
                    second = next(it)
                    first = op(first, second)

                    if op == OPRT['and'] and not first:
                        raise StopIteration

                    elif op == OPRT['or'] and first:
                        raise StopIteration

        except StopIteration:
            while isinstance(first, Variable):
                first = first.value
            return first