mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Merge pull request #2215 from jdufresne/img-palette-close
Close file after reading in ImagePalette.load()
This commit is contained in:
commit
2a74940817
|
@ -197,23 +197,23 @@ def load(filename):
|
||||||
|
|
||||||
# FIXME: supports GIMP gradients only
|
# FIXME: supports GIMP gradients only
|
||||||
|
|
||||||
fp = open(filename, "rb")
|
with open(filename, "rb") as fp:
|
||||||
|
|
||||||
for paletteHandler in [
|
for paletteHandler in [
|
||||||
GimpPaletteFile.GimpPaletteFile,
|
GimpPaletteFile.GimpPaletteFile,
|
||||||
GimpGradientFile.GimpGradientFile,
|
GimpGradientFile.GimpGradientFile,
|
||||||
PaletteFile.PaletteFile
|
PaletteFile.PaletteFile
|
||||||
]:
|
]:
|
||||||
try:
|
try:
|
||||||
fp.seek(0)
|
fp.seek(0)
|
||||||
lut = paletteHandler(fp).getpalette()
|
lut = paletteHandler(fp).getpalette()
|
||||||
if lut:
|
if lut:
|
||||||
break
|
break
|
||||||
except (SyntaxError, ValueError):
|
except (SyntaxError, ValueError):
|
||||||
# import traceback
|
# import traceback
|
||||||
# traceback.print_exc()
|
# traceback.print_exc()
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise IOError("cannot load palette")
|
raise IOError("cannot load palette")
|
||||||
|
|
||||||
return lut # data, rawmode
|
return lut # data, rawmode
|
||||||
|
|
Loading…
Reference in New Issue
Block a user