Merge pull request #2214 from jdufresne/eps-text-wrapper

Use TextIOWrapper.detach() instead of NoCloseStream
This commit is contained in:
Hugo 2018-09-26 15:34:24 +03:00 committed by GitHub
commit 9e54c14dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -356,22 +356,14 @@ def _save(im, fp, filename, eps=1):
else:
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
wrapped_fp = False
if fp != sys.stdout:
fp = NoCloseStream(fp)
if sys.version_info.major > 2:
fp = io.TextIOWrapper(fp, encoding='latin-1')
wrapped_fp = True
try:
if eps:
#
# write EPS header
@ -404,6 +396,9 @@ def _save(im, fp, filename, eps=1):
fp.write("grestore end\n")
if hasattr(fp, "flush"):
fp.flush()
finally:
if wrapped_fp:
fp.detach()
#
# --------------------------------------------------------------------