mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 21:50:54 +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:
|
||||
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()
|
||||
|
||||
#
|
||||
# --------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user