Merge pull request #1398 from mrTable/master

Check flush method existence for file-like object
This commit is contained in:
wiredfool 2015-10-01 07:54:26 -07:00
commit 4a8a983e6a
7 changed files with 13 additions and 14 deletions

View File

@ -405,13 +405,15 @@ def _save(im, fp, filename, eps=1):
fp.write("[%d 0 0 -%d 0 %d]\n" % (im.size[0], im.size[1], im.size[1]))
fp.write("{ currentfile buf readhexstring pop } bind\n")
fp.write(operator[2] + "\n")
fp.flush()
if hasattr(fp, "flush"):
fp.flush()
ImageFile._save(im, base_fp, [("eps", (0, 0)+im.size, 0, None)])
fp.write("\n%%%%EndBinary\n")
fp.write("grestore end\n")
fp.flush()
if hasattr(fp, "flush"):
fp.flush()
#
# --------------------------------------------------------------------

View File

@ -306,10 +306,8 @@ def _save(im, fp, filename):
OS X only.
"""
try:
if hasattr(fp, "flush"):
fp.flush()
except:
pass
# create the temporary set of pngs
iconset = tempfile.mkdtemp('.iconset')

View File

@ -489,10 +489,8 @@ def _save(im, fp, tile, bufsize=0):
if s < 0:
raise IOError("encoder error %d when writing image file" % s)
e.cleanup()
try:
if hasattr(fp, "flush"):
fp.flush()
except:
pass
def _safe_read(fp, size):

View File

@ -227,7 +227,8 @@ def _save(im, fp, filename, check=0):
ImageFile._save(
im, fp, [("raw", (0, 0)+im.size, 0, (rawmode, rowbytes, 1))])
fp.flush()
if hasattr(fp, "flush"):
fp.flush()
#

View File

@ -244,7 +244,8 @@ def _save(im, fp, filename, save_all=False):
fp.write("%010d 00000 n \n" % x)
fp.write("trailer\n<<\n/Size %d\n/Root 1 0 R\n>>\n" % len(xref))
fp.write("startxref\n%d\n%%%%EOF\n" % startxref)
fp.flush()
if hasattr(fp, "flush"):
fp.flush()
#
# --------------------------------------------------------------------

View File

@ -762,10 +762,8 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
chunk(fp, b"IEND", b"")
try:
if hasattr(fp, "flush"):
fp.flush()
except:
pass
# --------------------------------------------------------------------

View File

@ -1048,7 +1048,8 @@ 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()
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.