'Attaches a palette to this image.  The image must be a "P" or
"L" image, and the palette sequence must contain 768 integer
values, where each group of three values represent the red,
green, and blue values for the corresponding pixel
index. Instead of an integer sequence, you can use an 8-bit
string.
:param data: A palette sequence (either a list or a string).'

def putpalette(self, data, rawmode='RGB'):

    from . import ImagePalette
    if (self.mode not in ('L', 'P')):
        raise ValueError('illegal    image    mode')
    self.load()
    if isinstance(data, ImagePalette.ImagePalette):
        palette = ImagePalette.raw(data.rawmode, data.palette)
    else:
        if (not isinstance(data, bytes)):
            if (bytes is str):
                data = ''.join((chr(x) for x in data))
            else:
                data = bytes(data)
        palette = ImagePalette.raw(rawmode, data)
    self.mode = 'P'
    self.palette = palette
    self.palette.mode = 'RGB'
    self.load()
