Commit 0f6845ce authored by Neil's avatar Neil Committed by Toby Boyd
Browse files

Fix help print error when stdout/stderr not use utf-8 encoding (#7079)

parent f21337b1
...@@ -18,6 +18,7 @@ from __future__ import absolute_import ...@@ -18,6 +18,7 @@ from __future__ import absolute_import
from __future__ import division from __future__ import division
from __future__ import print_function from __future__ import print_function
import sys
import codecs import codecs
import functools import functools
...@@ -34,12 +35,19 @@ _help_wrap = functools.partial(flags.text_wrap, length=80, indent="", ...@@ -34,12 +35,19 @@ _help_wrap = functools.partial(flags.text_wrap, length=80, indent="",
# Pretty formatting causes issues when utf-8 is not installed on a system. # Pretty formatting causes issues when utf-8 is not installed on a system.
try: def _stdout_utf8():
try:
codecs.lookup("utf-8") codecs.lookup("utf-8")
except LookupError:
return False
return sys.stdout.encoding == "UTF-8"
if _stdout_utf8():
help_wrap = _help_wrap help_wrap = _help_wrap
except LookupError: else:
def help_wrap(text, *args, **kwargs): def help_wrap(text, *args, **kwargs):
return _help_wrap(text, *args, **kwargs).replace("\ufeff", "") return _help_wrap(text, *args, **kwargs).replace(u"\ufeff", u"")
# Replace None with h to also allow -h # Replace None with h to also allow -h
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment