mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
close files after loading for some file types
This commit is contained in:
parent
091d0c400c
commit
58484db509
|
@ -58,6 +58,7 @@ class DcxImageFile(PcxImageFile):
|
|||
self._offset.append(offset)
|
||||
|
||||
self.__fp = self.fp
|
||||
self._exclusive_fp = False
|
||||
self.seek(0)
|
||||
|
||||
@property
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;":
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue
Block a user