mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 10:56:18 +03:00
Close file after finished reading in ImageFont._load_pilfont()
Fixes some "ResourceWarning: unclosed file ..." when running tests with warnings enabled.
This commit is contained in:
parent
17d38d0905
commit
85ec6eb251
|
@ -62,23 +62,22 @@ class ImageFont(object):
|
||||||
|
|
||||||
def _load_pilfont(self, filename):
|
def _load_pilfont(self, filename):
|
||||||
|
|
||||||
fp = open(filename, "rb")
|
with open(filename, "rb") as fp:
|
||||||
|
for ext in (".png", ".gif", ".pbm"):
|
||||||
for ext in (".png", ".gif", ".pbm"):
|
try:
|
||||||
try:
|
fullname = os.path.splitext(filename)[0] + ext
|
||||||
fullname = os.path.splitext(filename)[0] + ext
|
image = Image.open(fullname)
|
||||||
image = Image.open(fullname)
|
except:
|
||||||
except:
|
pass
|
||||||
pass
|
else:
|
||||||
|
if image and image.mode in ("1", "L"):
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
if image and image.mode in ("1", "L"):
|
raise IOError("cannot find glyph data file")
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise IOError("cannot find glyph data file")
|
|
||||||
|
|
||||||
self.file = fullname
|
self.file = fullname
|
||||||
|
|
||||||
return self._load_pilfont_data(fp, image)
|
return self._load_pilfont_data(fp, image)
|
||||||
|
|
||||||
def _load_pilfont_data(self, file, image):
|
def _load_pilfont_data(self, file, image):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user