From 72b3e6819d9256ee2bf60c6d7504dc2406e6a3d6 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sat, 19 Aug 2017 22:18:55 -0700 Subject: [PATCH] Image._dump: Rewrite for clarity and type-safety. --- PIL/Image.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 056474ddf..96bd66b2e 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -583,21 +583,27 @@ class Image(object): def _dump(self, file=None, format=None, **options): import tempfile + suffix = '' if format: suffix = '.'+format + if not file: - f, file = tempfile.mkstemp(suffix) + f, filename = tempfile.mkstemp(suffix) os.close(f) + else: + filename = file + if not filename.endswith(suffix): + filename = filename + suffix self.load() + if not format or format == "PPM": - self.im.save_ppm(file) + self.im.save_ppm(filename) else: - if not file.endswith(format): - file = file + "." + format - self.save(file, format, **options) - return file + self.save(filename, format, **options) + + return filename def __eq__(self, other): return (self.__class__.__name__ == other.__class__.__name__ and