def parse_limit(val):
    """Convert a textual representation of a number of bytes into an integer

    NOTE: If val is None then None is returned

    Args:
        val (str): number of bytes
                   Format: <num><unit> where
                           <num> - is a float
                           <unit> is one of K, M, G, T, P for
                           kilobytes, megabytes, gigabytes, terabytes, petabytes

    Returns:
        int: Number of bytes
    """
    if val is None:
        return None

    num, unit = val[:-1], val[-1]
    val = float(num) * {
        'K': 1024,
        'M': 1024 * 1024,
        'G': 1024 * 1024 * 1024,
        'T': 1024 * 1024 * 1024 * 1024,
        'P': 1024 * 1024 * 1024 * 1024 * 1024,
    }[unit.upper()]

    return int(val)