From cbe1e3e5132dceeb96b57195579567d49928c00e Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 11 Nov 2014 18:36:28 +0100 Subject: (Hopefully) fix test_cmdline failures under Windows without colorama. --- pygments/cmdline.py | 4 ++-- pygments/util.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pygments/cmdline.py b/pygments/cmdline.py index 0dcda7ae..40c1a599 100644 --- a/pygments/cmdline.py +++ b/pygments/cmdline.py @@ -445,8 +445,8 @@ def main_inner(popts, args, usage): fmter.name in ('Terminal', 'Terminal256'): # pragma: no cover # unfortunately colorama doesn't support binary streams on Py3 if sys.version_info > (3,): - import io - outfile = io.TextIOWrapper(outfile, encoding=fmter.encoding) + from pygments.util import UnclosingTextIOWrapper + outfile = UnclosingTextIOWrapper(outfile, encoding=fmter.encoding) fmter.encoding = None try: import colorama.initialise diff --git a/pygments/util.py b/pygments/util.py index b5e5d0b6..22fab2fe 100644 --- a/pygments/util.py +++ b/pygments/util.py @@ -367,7 +367,12 @@ else: u_prefix = '' iteritems = dict.items itervalues = dict.values - from io import StringIO, BytesIO + from io import StringIO, BytesIO, TextIOWrapper + + class UnclosingTextIOWrapper(TextIOWrapper): + # Don't close underlying buffer on destruction. + def close(self): + pass def add_metaclass(metaclass): -- cgit v1.2.1