def __call__(self, query, element, debug=False):
        """Tests the filter on the specified element, returns a boolean"""
        match = True
        if debug: print("[FQL EVALUATION DEBUG] Filter - Testing filter [" + str(self) + "] for ", repr(element),file=sys.stderr)
        for filter in self.filters:
            if isinstance(filter,tuple):
                modifier, selector, subfilter = filter
                if debug: print("[FQL EVALUATION DEBUG] Filter - Filter is a subfilter of type " + modifier + ", descending...",file=sys.stderr)
                #we have a subfilter, i.e. a HAS statement on a subelement
                match = False
                if modifier == "CHILD":
                    for subelement,_ in selector(query, [element], True, debug): #if there are multiple subelements, they are always treated disjunctly
                        if not subfilter:
                            match = True
                        else:
                            match = subfilter(query, subelement, debug)
                        if match: break #only one subelement has to match by definition, then the HAS statement is matched
                elif modifier == "PARENT":
                    match = selector.match(query, element.parent,debug)
                elif modifier == "NEXT":
                    neighbour = element.next()
                    if neighbour:
                        match = selector.match(query, neighbour,debug)
                elif modifier == "PREVIOUS":
                    neighbour = element.previous()
                    if neighbour:
                        match = selector.match(query, neighbour,debug)
                else:
                    raise NotImplementedError("Context keyword " + modifier + " not implemented yet")
            elif isinstance(filter, Filter):
                #we have a nested filter (parentheses)
                match = filter(query, element, debug)
            else:
                #we have a condition function we can evaluate
                match = filter(element)

            if self.negation:
                match = not match
            if match:
                if self.disjunction:
                    if debug: print("[FQL EVALUATION DEBUG] Filter returns True",file=sys.stderr)
                    return True
            else:
                if not self.disjunction: #implies conjunction
                    if debug: print("[FQL EVALUATION DEBUG] Filter returns False",file=sys.stderr)
                    return False

        if debug: print("[FQL EVALUATION DEBUG] Filter returns ", str(match),file=sys.stderr)
        return match
def __call__ ( self , query , element , debug = False ) : match = True if debug : print ( "[FQL EVALUATION DEBUG] Filter - Testing filter [" + str ( self ) + "] for " , repr ( element ) , file = sys . stderr ) for filter in self . filters : if isinstance ( filter , tuple ) : modifier , selector , subfilter = filter if debug : print ( "[FQL EVALUATION DEBUG] Filter - Filter is a subfilter of type " + modifier + ", descending..." , file = sys . stderr ) match = False if modifier == "CHILD" : for subelement , _ in selector ( query , [ element ] , True , debug ) : if not subfilter : match = True else : match = subfilter ( query , subelement , debug ) if match : break elif modifier == "PARENT" : match = selector . match ( query , element . parent , debug ) elif modifier == "NEXT" : neighbour = element . next ( ) if neighbour : match = selector . match ( query , neighbour , debug ) elif modifier == "PREVIOUS" : neighbour = element . previous ( ) if neighbour : match = selector . match ( query , neighbour , debug ) else : raise NotImplementedError ( "Context keyword " + modifier + " not implemented yet" ) elif isinstance ( filter , Filter ) : match = filter ( query , element , debug ) else : match = filter ( element ) if self . negation : match = not match if match : if self . disjunction : if debug : print ( "[FQL EVALUATION DEBUG] Filter returns True" , file = sys . stderr ) return True else : if not self . disjunction : if debug : print ( "[FQL EVALUATION DEBUG] Filter returns False" , file = sys . stderr ) return False if debug : print ( "[FQL EVALUATION DEBUG] Filter returns " , str ( match ) , file = sys . stderr ) return match
Tests the filter on the specified element, returns a boolean