mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 01:34:24 +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()
|
im2 = hopper()
|
||||||
self.assert_image_similar(im, im2, 4.8)
|
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):
|
def test_invalid_file(self):
|
||||||
invalid_file = "Tests/images/flower.jpg"
|
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)
|
self.tile = _maketile(self.fp, mode, (0, 0) + self.size, channels)
|
||||||
|
|
||||||
# keep the file open
|
# keep the file open
|
||||||
self._fp = self.fp
|
self.__fp = self.fp
|
||||||
self.frame = 1
|
self.frame = 1
|
||||||
self._min_frame = 1
|
self._min_frame = 1
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ class PsdImageFile(ImageFile.ImageFile):
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.tile = tile
|
self.tile = tile
|
||||||
self.frame = layer
|
self.frame = layer
|
||||||
self.fp = self._fp
|
self.fp = self.__fp
|
||||||
return name, bbox
|
return name, bbox
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise EOFError("no such layer")
|
raise EOFError("no such layer")
|
||||||
|
@ -168,6 +168,15 @@ class PsdImageFile(ImageFile.ImageFile):
|
||||||
if self.mode == "P":
|
if self.mode == "P":
|
||||||
Image.Image.load(self)
|
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):
|
def _layerinfo(file):
|
||||||
# read layerinfo block
|
# read layerinfo block
|
||||||
|
|
Loading…
Reference in New Issue
Block a user