## Python Imaging Library# $Id$## stuff to read simple, teragon-style palette files## History:# 97-08-23 fl Created## Copyright (c) Secret Labs AB 1997.# Copyright (c) Fredrik Lundh 1997.## See the README file for information on usage and redistribution.#from__future__importannotationsfromtypingimportIOfrom._binaryimporto8
[docs]classPaletteFile:"""File handler for Teragon-style palette files."""rawmode="RGB"def__init__(self,fp:IO[bytes])->None:palette=[o8(i)*3foriinrange(256)]whileTrue:s=fp.readline()ifnots:breakifs[:1]==b"#":continueiflen(s)>100:msg="bad palette file"raiseSyntaxError(msg)v=[int(x)forxins.split()]try:[i,r,g,b]=vexceptValueError:[i,r]=vg=b=rif0<=i<=255:palette[i]=o8(r)+o8(g)+o8(b)self.palette=b"".join(palette)