def __init__(self, fp):

        self.palette = map(lambda i: (i, i, i), range(256))

        while 1:

            s = fp.readline()

            if not s:
                break
            if s[0] == "#":
                continue
            if len(s) > 100:
                raise SyntaxError, "bad palette file"

            v = map(int, string.split(s))
            try:
                [i, r, g, b] = v
            except ValueError:
                [i, r] = v
                g = b = r

            if 0 <= i <= 255:
                self.palette[i] = chr(r) + chr(g) + chr(b)

        self.palette = string.join(self.palette, "")
dataset/ETHPy150Open kleientertainment/ds_mod_tools/pkg/win32/Python27/Lib/site-packages/PIL/PaletteFile.py/PaletteFile.__init__/original