mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-27 17:30:40 +03:00
Do not assign new fp attribute to image when exiting context manager
This commit is contained in:
parent
04a4d54275
commit
5431b15bd2
|
@ -1015,6 +1015,11 @@ class TestImage:
|
|||
except OSError as e:
|
||||
assert str(e) == "buffer overrun when reading image file"
|
||||
|
||||
def test_exit_fp(self):
|
||||
with Image.new("L", (1, 1)) as im:
|
||||
pass
|
||||
assert not hasattr(im, "fp")
|
||||
|
||||
def test_close_graceful(self, caplog):
|
||||
with Image.open("Tests/images/hopper.jpg") as im:
|
||||
copy = im.copy()
|
||||
|
|
|
@ -528,14 +528,15 @@ class Image:
|
|||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
if hasattr(self, "fp") and getattr(self, "_exclusive_fp", False):
|
||||
if getattr(self, "_fp", False):
|
||||
if self._fp != self.fp:
|
||||
self._fp.close()
|
||||
self._fp = DeferredError(ValueError("Operation on closed image"))
|
||||
if self.fp:
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
if hasattr(self, "fp"):
|
||||
if getattr(self, "_exclusive_fp", False):
|
||||
if getattr(self, "_fp", False):
|
||||
if self._fp != self.fp:
|
||||
self._fp.close()
|
||||
self._fp = DeferredError(ValueError("Operation on closed image"))
|
||||
if self.fp:
|
||||
self.fp.close()
|
||||
self.fp = None
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user