def __b85_encode(data, lut, byte_order, special_values=None):
    """Encodes the given string data in to Base85 using the given LUT

    :param str data: A string which contains a string to be encoded in Base85
    :param dict lut: The lut to be used in encoding
    :param str byte_order: The byte order character for struct.unpack
    :param dict special_values: If given, pre defined special values are going
      to be replaced with corresponding special characters
    :returns: str
    """
    # pad data
    padding = (4 - len(data) % 4) % 4
    data = ''.join([data, '\0' * padding])
    parts = []
    parts_append = parts.append
    number_of_chunks = len(data) // 4
    byte_format = '%s%sI' % (byte_order, number_of_chunks)
    unpack = struct.unpack
    for x in unpack(byte_format, data):
        # network order (big endian), 32-bit unsigned integer
        # note: x86 is little endian
        parts_append(lut[(x // 52200625)])
        parts_append(lut[(x // 614125) % 85])
        parts_append(lut[(x // 7225) % 85])
        parts_append(lut[(x // 85) % 85])
        parts_append(lut[x % 85])
    return_val = ''.join(parts)
    if special_values:
        for key in special_values.keys():
            return_val = return_val.replace(key, special_values[key])
            #return_val = special_values[key].join(return_val.split(key))
    return return_val
dataset/ETHPy150Open eoyilmaz/anima/anima/render/arnold/base85.py/__b85_encode/original