

def kafka_versions(*versions):

    def version_str_to_list(s):
        return list(map(int, s.split('.')))

    def construct_lambda(s):
        if s[0].isdigit():
            op_str = '='
            v_str = s
        elif s[1].isdigit():
            op_str = s[0]
            v_str = s[1:]
        elif s[2].isdigit():
            op_str = s[0:2]
            v_str = s[2:]
        else:
            raise ValueError(('Unrecognized kafka version / operator: %s' % s))
        op_map = {
            '=': operator.eq,
            '!': operator.ne,
            '>': operator.gt,
            '<': operator.lt,
            '>=': operator.ge,
            '<=': operator.le,
        }
        op = op_map[op_str]
        version = version_str_to_list(v_str)
        return (lambda a: op(version_str_to_list(a), version))
    validators = map(construct_lambda, versions)

    def kafka_versions(func):

        @functools.wraps(func)
        def wrapper(self):
            kafka_version = os.environ.get('KAFKA_VERSION')
            if (not kafka_version):
                self.skipTest('no kafka version set in KAFKA_VERSION env var')
            for f in validators:
                if (not f(kafka_version)):
                    self.skipTest('unsupported kafka version')
            return func(self)
        return wrapper
    return kafka_versions

dataset/ETHPy150Open dpkp/kafka-python/test/testutil.py kafka_versions/original