Merge pull request #3540 from radarhere/fp

Only close __fp if not fp
This commit is contained in:
Hugo van Kemenade 2019-01-06 12:53:04 +02:00 committed by GitHub
commit 4d1be57256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 24 additions and 12 deletions

Binary file not shown.

View File

@ -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],

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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()

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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: