Merge pull request #2215 from jdufresne/img-palette-close

Close file after reading in ImagePalette.load()
This commit is contained in:
wiredfool 2016-11-14 22:12:08 +00:00 committed by GitHub
commit 2a74940817

View File

@ -197,23 +197,23 @@ def load(filename):
# FIXME: supports GIMP gradients only
fp = open(filename, "rb")
with open(filename, "rb") as fp:
for paletteHandler in [
GimpPaletteFile.GimpPaletteFile,
GimpGradientFile.GimpGradientFile,
PaletteFile.PaletteFile
]:
try:
fp.seek(0)
lut = paletteHandler(fp).getpalette()
if lut:
break
except (SyntaxError, ValueError):
# import traceback
# traceback.print_exc()
pass
else:
raise IOError("cannot load palette")
for paletteHandler in [
GimpPaletteFile.GimpPaletteFile,
GimpGradientFile.GimpGradientFile,
PaletteFile.PaletteFile
]:
try:
fp.seek(0)
lut = paletteHandler(fp).getpalette()
if lut:
break
except (SyntaxError, ValueError):
# import traceback
# traceback.print_exc()
pass
else:
raise IOError("cannot load palette")
return lut # data, rawmode