Merged _close_fp into close and __exit__

This commit is contained in:
Andrew Murray 2022-04-15 20:31:23 +10:00
parent 2ae52552f7
commit 4e075adcc5
11 changed files with 8 additions and 94 deletions

View File

@ -74,15 +74,6 @@ class DcxImageFile(PcxImageFile):
def tell(self): def tell(self):
return self.frame return self.frame
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
Image.register_open(DcxImageFile.format, DcxImageFile, _accept) Image.register_open(DcxImageFile.format, DcxImageFile, _accept)

View File

@ -153,15 +153,6 @@ class FliImageFile(ImageFile.ImageFile):
def tell(self): def tell(self):
return self.__frame return self.__frame
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
# #
# registry # registry

View File

@ -443,15 +443,6 @@ class GifImageFile(ImageFile.ImageFile):
def tell(self): def tell(self):
return self.__frame return self.__frame
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Write GIF files # Write GIF files

View File

@ -301,15 +301,6 @@ class ImImageFile(ImageFile.ImageFile):
def tell(self): def tell(self):
return self.frame return self.frame
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -544,8 +544,10 @@ class Image:
def __exit__(self, *args): def __exit__(self, *args):
if hasattr(self, "fp") and getattr(self, "_exclusive_fp", False): if hasattr(self, "fp") and getattr(self, "_exclusive_fp", False):
if hasattr(self, "_close_fp"): if getattr(self, "_fp", False):
self._close_fp() if self._fp != self.fp:
self._fp.close()
self._fp = None
if self.fp: if self.fp:
self.fp.close() self.fp.close()
self.fp = None self.fp = None
@ -563,8 +565,10 @@ class Image:
more information. more information.
""" """
try: try:
if hasattr(self, "_close_fp"): if getattr(self, "_fp", False):
self._close_fp() if self._fp != self.fp:
self._fp.close()
self._fp = None
if self.fp: if self.fp:
self.fp.close() self.fp.close()
self.fp = None self.fp = None

View File

@ -89,15 +89,6 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
def tell(self): def tell(self):
return self.frame return self.frame
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------

View File

@ -97,15 +97,6 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
def tell(self): def tell(self):
return self.__frame return self.__frame
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
@staticmethod @staticmethod
def adopt(jpeg_instance, mpheader=None): def adopt(jpeg_instance, mpheader=None):
""" """

View File

@ -1006,15 +1006,6 @@ class PngImageFile(ImageFile.ImageFile):
else {} else {}
) )
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# PNG writer # PNG writer

View File

@ -155,15 +155,6 @@ class PsdImageFile(ImageFile.ImageFile):
# return layer number (0=image, 1..max=layers) # return layer number (0=image, 1..max=layers)
return self.frame return self.frame
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
def _layerinfo(fp, ct_bytes): def _layerinfo(fp, ct_bytes):
# read layerinfo block # read layerinfo block

View File

@ -191,15 +191,6 @@ class SpiderImageFile(ImageFile.ImageFile):
return ImageTk.PhotoImage(self.convert2byte(), palette=256) return ImageTk.PhotoImage(self.convert2byte(), palette=256)
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Image series # Image series

View File

@ -1515,15 +1515,6 @@ class TiffImageFile(ImageFile.ImageFile):
self._tile_orientation = self.tag_v2.get(0x0112) self._tile_orientation = self.tag_v2.get(0x0112)
def _close_fp(self):
try:
if self._fp != self.fp:
self._fp.close()
except AttributeError:
pass
finally:
self._fp = None
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------