Index: roundup/backends/back_anydbm.py =================================================================== --- roundup/backends/back_anydbm.py (Revision 4543) +++ roundup/backends/back_anydbm.py (Arbeitskopie) @@ -49,6 +49,60 @@ def db_nuke(config): shutil.rmtree(config.DATABASE) +class Equals: + def __init__(self, x): + self.x = x + + def evaluate(self, v): + return self.x in v + +class Not: + def __init__(self, x): + self.x = x + + def evaluate(self, v): + return not self.x.evaluate(v) + +class Or: + def __init__(self, x, y): + self.x = x + self.y = y + + def evaluate(self, v): + return self.x.evaluate(v) or self.y.evaluate(v) + +class And: + def __init__(self, x, y): + self.x = x + self.y = y + + def evaluate(self, v): + return self.x.evaluate(v) and self.y.evaluate(v) + + +class Expression: + + def __init__(self, v): + try: + opcodes = [int(x) for x in v] + if min(opcodes) >= -1: raise ValueError() + + stack = [] + for opcode in opcodes: + if opcode == -2: # not + stack.append(Not(stack.pop())) + elif opcode == -3: # and + stack.append(And(stack.pop(), stack.pop())) + elif opcode == -4: # or + stack.append(Or(stack.pop(), stack.pop())) + else: # = + stack.append(Equals(opcode)) + + compiled = stack.pop() + self.evaluate = lambda x: compiled.evaluate([int(y) for y in x]) + except: + self.evaluate = lambda x: bool(set(x) & set(v)) + # # Now the database # @@ -1700,12 +1754,10 @@ if not v: match = not nv else: - # othewise, make sure this node has each of the + # otherwise, make sure this node has each of the # required values - for want in v: - if want in nv: - match = 1 - break + expr = Expression(v) + if expr.evaluate(nv): match = 1 elif t == STRING: if nv is None: nv = ''