Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Tests/images/hopper_unknown_pixel_mode.tif
Binary file not shown.
4 changes: 4 additions & 0 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ def test_32bit_float(self):
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],
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/DcxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def tell(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/FliImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def tell(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ def load_end(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/ImImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ def tell(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down
8 changes: 4 additions & 4 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,10 @@ def close(self):
: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)

Expand All @@ -611,12 +611,12 @@ def close(self):

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()
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/MicImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def tell(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/MpoImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def tell(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/SpiderImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ def tkPhotoImage(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,8 @@ def _setup(self):

def _close__fp(self):
try:
self.__fp.close()
if self.__fp != self.fp:
self.__fp.close()
except AttributeError:
pass
finally:
Expand Down