close files after loading for some file types

This commit is contained in:
homm 2016-07-17 09:22:50 +03:00 committed by wiredfool
parent 091d0c400c
commit 58484db509
11 changed files with 12 additions and 3 deletions

View File

@ -58,6 +58,7 @@ class DcxImageFile(PcxImageFile):
self._offset.append(offset)
self.__fp = self.fp
self._exclusive_fp = False
self.seek(0)
@property

View File

@ -84,6 +84,7 @@ class FliImageFile(ImageFile.ImageFile):
# set things up to decode first frame
self.__frame = -1
self.__fp = self.fp
self._exclusive_fp = False
self.__rewind = self.fp.tell()
self._n_frames = None
self._is_animated = None

View File

@ -80,6 +80,7 @@ class GifImageFile(ImageFile.ImageFile):
break
self.__fp = self.fp # FIXME: hack
self._exclusive_fp = False
self.__rewind = self.fp.tell()
self._n_frames = None
self._is_animated = None

View File

@ -234,6 +234,7 @@ class ImImageFile(ImageFile.ImageFile):
self.__offset = offs = self.fp.tell()
self.__fp = self.fp # FIXME: hack
self._exclusive_fp = False
if self.rawmode[:2] == "F;":

View File

@ -2440,6 +2440,8 @@ def open(fp, mode="r"):
im = _open_core(fp, filename, prefix)
if im:
if getattr(im, '_exclusive_fp', 'undef') is None:
im._exclusive_fp = exclusive_fp
return im
if exclusive_fp:

View File

@ -93,7 +93,8 @@ class ImageFile(Image.Image):
# stream
self.fp = fp
self.filename = filename
self._exclusive_fp = False
# can be overridden
self._exclusive_fp = None
try:
self._open()

View File

@ -64,6 +64,7 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
raise SyntaxError("not an MIC file; no image entries")
self.__fp = self.fp
self._exclusive_fp = False
self.frame = 0
if len(self.images) > 1:

View File

@ -53,6 +53,7 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
assert self.__framecount == len(self.__mpoffsets)
del self.info['mpoffset'] # no longer needed
self.__fp = self.fp # FIXME: hack
self._exclusive_fp = False
self.__fp.seek(self.__mpoffsets[0]) # get ready to read first frame
self.__frame = 0
self.offset = 0

View File

@ -154,6 +154,7 @@ class SpiderImageFile(ImageFile.ImageFile):
("raw", (0, 0) + self.size, offset,
(self.rawmode, 0, 1))]
self.__fp = self.fp # FIXME: hack
self._exclusive_fp = False
@property
def n_frames(self):

View File

@ -901,6 +901,7 @@ class TiffImageFile(ImageFile.ImageFile):
self.__first = self.__next = self.tag_v2.next
self.__frame = -1
self.__fp = self.fp
self._exclusive_fp = False
self._frame_pos = []
self._n_frames = None
self._is_animated = None

View File

@ -116,8 +116,6 @@ class XpmImageFile(ImageFile.ImageFile):
for i in range(ysize):
s[i] = self.fp.readline()[1:xsize+1].ljust(xsize)
self.fp = None
return b"".join(s)
#