mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Only close __fp if not fp
This commit is contained in:
parent
41fba67fb0
commit
71b64dcf73
BIN
Tests/images/hopper_unknown_pixel_mode.tif
Normal file
BIN
Tests/images/hopper_unknown_pixel_mode.tif
Normal file
Binary file not shown.
|
@ -220,6 +220,10 @@ class TestFileTiff(PillowTestCase):
|
|||
self.assertEqual(
|
||||
im.getextrema(), (-3.140936851501465, 3.140684127807617))
|
||||
|
||||
def test_unknown_pixel_mode(self):
|
||||
self.assertRaises(
|
||||
IOError, Image.open, 'Tests/images/hopper_unknown_pixel_mode.tif')
|
||||
|
||||
def test_n_frames(self):
|
||||
for path, n_frames in [
|
||||
['Tests/images/multipage-lastframe.tif', 1],
|
||||
|
|
|
@ -83,7 +83,8 @@ class DcxImageFile(PcxImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -159,7 +159,8 @@ class FliImageFile(ImageFile.ImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -304,7 +304,8 @@ class GifImageFile(ImageFile.ImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -292,7 +292,8 @@ class ImImageFile(ImageFile.ImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -594,10 +594,10 @@ class Image(object):
|
|||
:ref:`file-handling` for more information.
|
||||
"""
|
||||
try:
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
if hasattr(self, "_close__fp"):
|
||||
self._close__fp()
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
except Exception as msg:
|
||||
logger.debug("Error closing: %s", msg)
|
||||
|
||||
|
@ -611,12 +611,12 @@ class Image(object):
|
|||
|
||||
if sys.version_info.major >= 3:
|
||||
def __del__(self):
|
||||
if hasattr(self, "_close__fp"):
|
||||
self._close__fp()
|
||||
if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp')
|
||||
and self.fp and self._exclusive_fp):
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
if hasattr(self, "_close__fp"):
|
||||
self._close__fp()
|
||||
|
||||
def _copy(self):
|
||||
self.load()
|
||||
|
|
|
@ -99,7 +99,8 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -86,7 +86,8 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -195,7 +195,8 @@ class SpiderImageFile(ImageFile.ImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
@ -1361,7 +1361,8 @@ class TiffImageFile(ImageFile.ImageFile):
|
|||
|
||||
def _close__fp(self):
|
||||
try:
|
||||
self.__fp.close()
|
||||
if self.__fp != self.fp:
|
||||
self.__fp.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
finally:
|
||||
|
|
Loading…
Reference in New Issue
Block a user