mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Close internal fp when closing and deleting
This commit is contained in:
parent
ea02e28adb
commit
e1e35cc819
|
@ -17,6 +17,12 @@ class TestImagePsd(PillowTestCase):
|
|||
im2 = hopper()
|
||||
self.assert_image_similar(im, im2, 4.8)
|
||||
|
||||
def test_unclosed_file(self):
|
||||
def open():
|
||||
im = Image.open(test_file)
|
||||
im.load()
|
||||
self.assert_warning(None, open)
|
||||
|
||||
def test_invalid_file(self):
|
||||
invalid_file = "Tests/images/flower.jpg"
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ class PsdImageFile(ImageFile.ImageFile):
|
|||
self.tile = _maketile(self.fp, mode, (0, 0) + self.size, channels)
|
||||
|
||||
# keep the file open
|
||||
self._fp = self.fp
|
||||
self.__fp = self.fp
|
||||
self.frame = 1
|
||||
self._min_frame = 1
|
||||
|
||||
|
@ -151,7 +151,7 @@ class PsdImageFile(ImageFile.ImageFile):
|
|||
self.mode = mode
|
||||
self.tile = tile
|
||||
self.frame = layer
|
||||
self.fp = self._fp
|
||||
self.fp = self.__fp
|
||||
return name, bbox
|
||||
except IndexError:
|
||||
raise EOFError("no such layer")
|
||||
|
@ -168,6 +168,15 @@ class PsdImageFile(ImageFile.ImageFile):
|
|||
if self.mode == "P":
|
||||
Image.Image.load(self)
|
||||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
self.__fp = None
|
||||
|
||||
|
||||
def _layerinfo(file):
|
||||
# read layerinfo block
|
||||
|
|
Loading…
Reference in New Issue
Block a user