mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 02:36:17 +03:00
Improved consistency of checks for flush
This commit is contained in:
parent
a2b6b661d9
commit
d21430234e
|
@ -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("[%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("{ currentfile buf readhexstring pop } bind\n")
|
||||||
fp.write(operator[2] + "\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)])
|
ImageFile._save(im, base_fp, [("eps", (0, 0)+im.size, 0, None)])
|
||||||
|
|
||||||
fp.write("\n%%%%EndBinary\n")
|
fp.write("\n%%%%EndBinary\n")
|
||||||
fp.write("grestore end\n")
|
fp.write("grestore end\n")
|
||||||
fp.flush()
|
if hasattr(fp, "flush"):
|
||||||
|
fp.flush()
|
||||||
|
|
||||||
#
|
#
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
|
@ -306,10 +306,8 @@ def _save(im, fp, filename):
|
||||||
|
|
||||||
OS X only.
|
OS X only.
|
||||||
"""
|
"""
|
||||||
try:
|
if hasattr(fp, "flush"):
|
||||||
fp.flush()
|
fp.flush()
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# create the temporary set of pngs
|
# create the temporary set of pngs
|
||||||
iconset = tempfile.mkdtemp('.iconset')
|
iconset = tempfile.mkdtemp('.iconset')
|
||||||
|
|
|
@ -493,10 +493,8 @@ def _save(im, fp, tile, bufsize=0):
|
||||||
if s < 0:
|
if s < 0:
|
||||||
raise IOError("encoder error %d when writing image file" % s)
|
raise IOError("encoder error %d when writing image file" % s)
|
||||||
e.cleanup()
|
e.cleanup()
|
||||||
try:
|
if hasattr(fp, "flush"):
|
||||||
fp.flush()
|
fp.flush()
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def _safe_read(fp, size):
|
def _safe_read(fp, size):
|
||||||
|
|
|
@ -227,7 +227,8 @@ def _save(im, fp, filename, check=0):
|
||||||
ImageFile._save(
|
ImageFile._save(
|
||||||
im, fp, [("raw", (0, 0)+im.size, 0, (rawmode, rowbytes, 1))])
|
im, fp, [("raw", (0, 0)+im.size, 0, (rawmode, rowbytes, 1))])
|
||||||
|
|
||||||
fp.flush()
|
if hasattr(fp, "flush"):
|
||||||
|
fp.flush()
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -226,7 +226,8 @@ def _save(im, fp, filename):
|
||||||
fp.write("%010d 00000 n \n" % x)
|
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("trailer\n<<\n/Size %d\n/Root 1 0 R\n>>\n" % len(xref))
|
||||||
fp.write("startxref\n%d\n%%%%EOF\n" % startxref)
|
fp.write("startxref\n%d\n%%%%EOF\n" % startxref)
|
||||||
fp.flush()
|
if hasattr(fp, "flush"):
|
||||||
|
fp.flush()
|
||||||
|
|
||||||
#
|
#
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
|
@ -762,10 +762,8 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
||||||
|
|
||||||
chunk(fp, b"IEND", b"")
|
chunk(fp, b"IEND", b"")
|
||||||
|
|
||||||
try:
|
if hasattr(fp, "flush"):
|
||||||
fp.flush()
|
fp.flush()
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
|
@ -935,8 +935,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
# flush the file descriptor, prevents error on pypy 2.4+
|
# flush the file descriptor, prevents error on pypy 2.4+
|
||||||
# should also eliminate the need for fp.tell for py3
|
# should also eliminate the need for fp.tell for py3
|
||||||
# in _seek
|
# in _seek
|
||||||
# flush method may not exist for file-like object.
|
if hasattr(self.fp, "flush"):
|
||||||
if hasattr(self.fp, 'flush'):
|
|
||||||
self.fp.flush()
|
self.fp.flush()
|
||||||
except IOError:
|
except IOError:
|
||||||
# io.BytesIO have a fileno, but returns an IOError if
|
# io.BytesIO have a fileno, but returns an IOError if
|
||||||
|
|
Loading…
Reference in New Issue
Block a user