diff --git a/src/PIL/Image.py b/src/PIL/Image.py index b690006b5..e34c25487 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -578,8 +578,7 @@ class Image(object): return self def __exit__(self, *args): - if (hasattr(self, 'fp') and hasattr(self, '_exclusive_fp') - and self._exclusive_fp): + if hasattr(self, 'fp') and getattr(self, '_exclusive_fp', False): if hasattr(self, "_close__fp"): self._close__fp() if self.fp: diff --git a/src/PIL/WebPImagePlugin.py b/src/PIL/WebPImagePlugin.py index 212e6b4c7..25557326b 100644 --- a/src/PIL/WebPImagePlugin.py +++ b/src/PIL/WebPImagePlugin.py @@ -186,7 +186,7 @@ def _save_all(im, fp, filename): # will preserve non-alpha modes total = 0 for ims in [im]+append_images: - total += 1 if not hasattr(ims, "n_frames") else ims.n_frames + total += getattr(ims, "n_frames", 1) if total == 1: _save(im, fp, filename) return @@ -254,10 +254,7 @@ def _save_all(im, fp, filename): try: for ims in [im]+append_images: # Get # of frames in this image - if not hasattr(ims, "n_frames"): - nfr = 1 - else: - nfr = ims.n_frames + nfr = getattr(ims, "n_frames", 1) for idx in range(nfr): ims.seek(idx)