def prepare_predicate(next, token):
    # this one should probably be refactored...
    token = next()
    if token[0] == "@":
        # attribute
        token = next()
        if token[0]:
            raise SyntaxError("invalid attribute predicate")
        key = token[1]
        token = next()
        if token[0] == "]":
            def select(context, result):
                for elem in result:
                    if elem.get(key) is not None:
                        yield elem
        elif token[0] == "=":
            value = next()[0]
            if value[:1] == "'" or value[:1] > '"':
                value = value[1:-1]
            else:
                raise SyntaxError("invalid comparision target")
            token = next()
            def select(context, result):
                for elem in result:
                    if elem.get(key) == value:
                        yield elem
        if token[0] != "]":
            raise SyntaxError("invalid attribute predicate")
    elif not token[0]:
        tag = token[1]
        token = next()
        if token[0] != "]":
            raise SyntaxError("invalid node predicate")
        def select(context, result):
            for elem in result:
                if elem.find(tag) is not None:
                    yield elem
    else:
        raise SyntaxError("invalid predicate")
    return select
dataset/ETHPy150Open CollabQ/CollabQ/vendor/elementtree/ElementPath.py/prepare_predicate/operator `==` -> `>`