Fixed bug in saving to fp-objects in Python >= 3.4

This commit is contained in:
Andrew Murray 2016-11-15 20:13:25 +11:00
parent 2a74940817
commit 38fd77ca7d
2 changed files with 13 additions and 1 deletions

View File

@ -1659,7 +1659,7 @@ class Image(object):
if isinstance(fp, Path):
filename = str(fp)
open_fp = True
elif hasattr(fp, "name") and isPath(fp.name):
if not filename and hasattr(fp, "name") and isPath(fp.name):
# only set the name for metadata purposes
filename = fp.name

View File

@ -63,6 +63,18 @@ class TestImage(PillowTestCase):
os.remove(temp_file)
im.save(Path(temp_file))
def test_fp_name(self):
temp_file = self.tempfile("temp.jpg")
class FP(object):
def write(a, b):
pass
fp = FP()
fp.name = temp_file
im = hopper()
im.save(fp)
def test_tempfile(self):
# see #1460, pathlib support breaks tempfile.TemporaryFile on py27
# Will error out on save on 3.0.0