Skip to content

Commit

Permalink
Merge pull request #1 from radarhere/flush
Browse files Browse the repository at this point in the history
Improved consistency of checks for flush
  • Loading branch information
mrTable committed Sep 9, 2015
2 parents a2b6b66 + d214302 commit 8e7cd92
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 15 deletions.
6 changes: 4 additions & 2 deletions PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,15 @@ def close(self):
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()

#
# --------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions PIL/IcnsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 1 addition & 3 deletions PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,10 +493,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):
Expand Down
3 changes: 2 additions & 1 deletion PIL/PalmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


#
Expand Down
3 changes: 2 additions & 1 deletion PIL/PdfImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ def write(self, value):
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()

#
# --------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


# --------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,7 @@ def _setup(self):
# flush the file descriptor, prevents error on pypy 2.4+
# should also eliminate the need for fp.tell for py3
# in _seek
# flush method may not exist for file-like object.
if hasattr(self.fp, 'flush'):
if hasattr(self.fp, "flush"):
self.fp.flush()
except IOError:
# io.BytesIO have a fileno, but returns an IOError if
Expand Down

0 comments on commit 8e7cd92

Please sign in to comment.