def match_asterisk(pattern, data):
    """Match data against a pattern

    The difference to fnmatch is that this function only accepts patterns with a single
    asterisk and that it returns a "closeness" number, which is larger the better the match.
    Zero indicates no match at all.
    """
    if '*' not in pattern:
        return 1 if pattern == data else 0
    parts = pattern.split('*')
    if len(parts) > 2:
        raise ValueError(
            'Only patterns with a single asterisk are supported, %s is invalid'
             % pattern)
    if not data.startswith(parts[0]):
        return 0
    if not data.endswith(parts[1]):
        return 0
    matched = len(pattern)
    total = len(data) + 1
    return matched * 1.0 / total
