import re


def parse_size(s):
    """
    Parses a human-readable size to a number of bytes.
    Only accepts kilos and megs because seriously, there's no point in other units (not for ics files anyway).
    """
    sizes = {
        'K': 1024,
        'M': 1024 * 1024,
    }

    pattern = re.compile('^(\d+)([Kk]|M)[Bb]?$')
    match = pattern.match(s)
    if not match:
        raise ValueError("Cannot understand size specification {}".format(s))

    v, u = match.groups()
    return int(v) * sizes[u.upper()]