diff --git a/src/PIL/DcxImagePlugin.py b/src/PIL/DcxImagePlugin.py index d5c748226..aeed1e7c7 100644 --- a/src/PIL/DcxImagePlugin.py +++ b/src/PIL/DcxImagePlugin.py @@ -74,15 +74,6 @@ class DcxImageFile(PcxImageFile): def tell(self): 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) diff --git a/src/PIL/FliImagePlugin.py b/src/PIL/FliImagePlugin.py index 7df301904..e13b1779c 100644 --- a/src/PIL/FliImagePlugin.py +++ b/src/PIL/FliImagePlugin.py @@ -153,15 +153,6 @@ class FliImageFile(ImageFile.ImageFile): def tell(self): return self.__frame - def _close_fp(self): - try: - if self._fp != self.fp: - self._fp.close() - except AttributeError: - pass - finally: - self._fp = None - # # registry diff --git a/src/PIL/GifImagePlugin.py b/src/PIL/GifImagePlugin.py index cfb6c0355..33c76586b 100644 --- a/src/PIL/GifImagePlugin.py +++ b/src/PIL/GifImagePlugin.py @@ -443,15 +443,6 @@ class GifImageFile(ImageFile.ImageFile): def tell(self): 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 diff --git a/src/PIL/ImImagePlugin.py b/src/PIL/ImImagePlugin.py index 3c5739f3d..ee95a94cb 100644 --- a/src/PIL/ImImagePlugin.py +++ b/src/PIL/ImImagePlugin.py @@ -301,15 +301,6 @@ class ImImageFile(ImageFile.ImageFile): def tell(self): return self.frame - def _close_fp(self): - try: - if self._fp != self.fp: - self._fp.close() - except AttributeError: - pass - finally: - self._fp = None - # # -------------------------------------------------------------------- diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 16fad61c1..1409a20d2 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -544,8 +544,10 @@ class Image: def __exit__(self, *args): if hasattr(self, "fp") and getattr(self, "_exclusive_fp", False): - if hasattr(self, "_close_fp"): - self._close_fp() + if getattr(self, "_fp", False): + if self._fp != self.fp: + self._fp.close() + self._fp = None if self.fp: self.fp.close() self.fp = None @@ -563,8 +565,10 @@ class Image: more information. """ try: - if hasattr(self, "_close_fp"): - self._close_fp() + if getattr(self, "_fp", False): + if self._fp != self.fp: + self._fp.close() + self._fp = None if self.fp: self.fp.close() self.fp = None diff --git a/src/PIL/MicImagePlugin.py b/src/PIL/MicImagePlugin.py index 324c8eff4..0de37cf37 100644 --- a/src/PIL/MicImagePlugin.py +++ b/src/PIL/MicImagePlugin.py @@ -89,15 +89,6 @@ class MicImageFile(TiffImagePlugin.TiffImageFile): def tell(self): return self.frame - def _close_fp(self): - try: - if self._fp != self.fp: - self._fp.close() - except AttributeError: - pass - finally: - self._fp = None - # # -------------------------------------------------------------------- diff --git a/src/PIL/MpoImagePlugin.py b/src/PIL/MpoImagePlugin.py index 0d61746b7..fc3f8556f 100644 --- a/src/PIL/MpoImagePlugin.py +++ b/src/PIL/MpoImagePlugin.py @@ -97,15 +97,6 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile): def tell(self): return self.__frame - def _close_fp(self): - try: - if self._fp != self.fp: - self._fp.close() - except AttributeError: - pass - finally: - self._fp = None - @staticmethod def adopt(jpeg_instance, mpheader=None): """ diff --git a/src/PIL/PngImagePlugin.py b/src/PIL/PngImagePlugin.py index 313090e8d..856c21802 100644 --- a/src/PIL/PngImagePlugin.py +++ b/src/PIL/PngImagePlugin.py @@ -1006,15 +1006,6 @@ class PngImageFile(ImageFile.ImageFile): else {} ) - def _close_fp(self): - try: - if self._fp != self.fp: - self._fp.close() - except AttributeError: - pass - finally: - self._fp = None - # -------------------------------------------------------------------- # PNG writer diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py index 3be9aa290..9622e648a 100644 --- a/src/PIL/PsdImagePlugin.py +++ b/src/PIL/PsdImagePlugin.py @@ -155,15 +155,6 @@ class PsdImageFile(ImageFile.ImageFile): # return layer number (0=image, 1..max=layers) 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): # read layerinfo block diff --git a/src/PIL/SpiderImagePlugin.py b/src/PIL/SpiderImagePlugin.py index 0a65c286c..154008c08 100644 --- a/src/PIL/SpiderImagePlugin.py +++ b/src/PIL/SpiderImagePlugin.py @@ -191,15 +191,6 @@ class SpiderImageFile(ImageFile.ImageFile): 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 diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index ee737cb59..c871072ad 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1515,15 +1515,6 @@ class TiffImageFile(ImageFile.ImageFile): 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 - # # --------------------------------------------------------------------