From a2b6b661d9d2292463969f4fa9f6b9b2c71b5e11 Mon Sep 17 00:00:00 2001 From: Dmitry Yantsen Date: Fri, 28 Aug 2015 14:59:29 +0500 Subject: [PATCH] Added check for flush method existense for file-like object in tiffplugin setup --- PIL/TiffImagePlugin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 30f33ab62..5a80c8b48 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -935,7 +935,9 @@ class TiffImageFile(ImageFile.ImageFile): # flush the file descriptor, prevents error on pypy 2.4+ # should also eliminate the need for fp.tell for py3 # in _seek - self.fp.flush() + # flush method may not exist for file-like object. + if hasattr(self.fp, 'flush'): + self.fp.flush() except IOError: # io.BytesIO have a fileno, but returns an IOError if # it doesn't use a file descriptor.