Merge pull request #2227 from radarhere/fpname

Fixed bug in saving to fp-objects in Python >= 3.4
This commit is contained in:
wiredfool 2016-11-22 12:03:25 +00:00 committed by GitHub
commit 87b8d2894a
2 changed files with 13 additions and 1 deletions

View File

@ -1659,7 +1659,7 @@ class Image(object):
if isinstance(fp, Path): if isinstance(fp, Path):
filename = str(fp) filename = str(fp)
open_fp = True 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 # only set the name for metadata purposes
filename = fp.name filename = fp.name

View File

@ -63,6 +63,18 @@ class TestImage(PillowTestCase):
os.remove(temp_file) os.remove(temp_file)
im.save(Path(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): def test_tempfile(self):
# see #1460, pathlib support breaks tempfile.TemporaryFile on py27 # see #1460, pathlib support breaks tempfile.TemporaryFile on py27
# Will error out on save on 3.0.0 # Will error out on save on 3.0.0