

def prepare_predicate(next, token):
    token = next()
    if (token[0] == '@'):
        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 = key[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/VarMisuse@166/185 `value`->`key`