Invert logic for py3 print detection, to avoid confusion created by the future package

This commit is contained in:
Matt Martz 2017-04-11 10:18:42 -05:00
parent 9806e401e0
commit 824c584658
1 changed files with 23 additions and 21 deletions

View File

@ -141,8 +141,30 @@ except ImportError:
BytesIO = None BytesIO = None
try: try:
import builtins import __builtin__
except ImportError: except ImportError:
import builtins
class _Py3Utf8Stdout(TextIOWrapper):
def __init__(self, **kwargs):
buf = FileIO(sys.stdout.fileno(), 'w')
super(_Py3Utf8Stdout, self).__init__(
buf,
encoding='utf8',
errors='strict'
)
def write(self, s):
super(_Py3Utf8Stdout, self).write(s)
self.flush()
_py3_print = getattr(builtins, 'print')
_py3_utf8_stdout = _Py3Utf8Stdout()
def print_(*args, **kwargs):
kwargs['file'] = _py3_utf8_stdout
_py3_print(*args, **kwargs)
else:
def print_(*args, **kwargs): def print_(*args, **kwargs):
"""The new-style print function for Python 2.4 and 2.5. """The new-style print function for Python 2.4 and 2.5.
@ -202,26 +224,6 @@ except ImportError:
write(sep) write(sep)
write(arg) write(arg)
write(end) write(end)
else:
class _Py3Utf8Stdout(TextIOWrapper):
def __init__(self, **kwargs):
buf = FileIO(sys.stdout.fileno(), 'w')
super(_Py3Utf8Stdout, self).__init__(
buf,
encoding='utf8',
errors='strict'
)
def write(self, s):
super(_Py3Utf8Stdout, self).write(s)
self.flush()
_py3_print = getattr(builtins, 'print')
_py3_utf8_stdout = _Py3Utf8Stdout()
def print_(*args, **kwargs):
kwargs['file'] = _py3_utf8_stdout
_py3_print(*args, **kwargs)
# Exception "constants" to support Python 2 through Python 3 # Exception "constants" to support Python 2 through Python 3