mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-10 00:20:57 +03:00
Merge pull request #2214 from jdufresne/eps-text-wrapper
Use TextIOWrapper.detach() instead of NoCloseStream
This commit is contained in:
commit
9e54c14dfa
|
@ -356,22 +356,14 @@ def _save(im, fp, filename, eps=1):
|
||||||
else:
|
else:
|
||||||
raise ValueError("image mode is not supported")
|
raise ValueError("image mode is not supported")
|
||||||
|
|
||||||
class NoCloseStream(object):
|
|
||||||
def __init__(self, fp):
|
|
||||||
self.fp = fp
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
return getattr(self.fp, name)
|
|
||||||
|
|
||||||
def close(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
base_fp = fp
|
base_fp = fp
|
||||||
|
wrapped_fp = False
|
||||||
if fp != sys.stdout:
|
if fp != sys.stdout:
|
||||||
fp = NoCloseStream(fp)
|
|
||||||
if sys.version_info.major > 2:
|
if sys.version_info.major > 2:
|
||||||
fp = io.TextIOWrapper(fp, encoding='latin-1')
|
fp = io.TextIOWrapper(fp, encoding='latin-1')
|
||||||
|
wrapped_fp = True
|
||||||
|
|
||||||
|
try:
|
||||||
if eps:
|
if eps:
|
||||||
#
|
#
|
||||||
# write EPS header
|
# write EPS header
|
||||||
|
@ -404,6 +396,9 @@ def _save(im, fp, filename, eps=1):
|
||||||
fp.write("grestore end\n")
|
fp.write("grestore end\n")
|
||||||
if hasattr(fp, "flush"):
|
if hasattr(fp, "flush"):
|
||||||
fp.flush()
|
fp.flush()
|
||||||
|
finally:
|
||||||
|
if wrapped_fp:
|
||||||
|
fp.detach()
|
||||||
|
|
||||||
#
|
#
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue
Block a user