|
@@ -36,14 +36,17 @@ def gettext_popen_wrapper(args, os_err_exc_type=CommandError, stdout_encoding="u
|
|
|
"""
|
|
|
Makes sure text obtained from stdout of gettext utilities is Unicode.
|
|
|
"""
|
|
|
- stdout, stderr, status_code = popen_wrapper(args, os_err_exc_type=os_err_exc_type)
|
|
|
- if os.name == 'nt' and six.PY3 and stdout_encoding != DEFAULT_LOCALE_ENCODING:
|
|
|
- # This looks weird because it's undoing what
|
|
|
- # subprocess.Popen(universal_newlines=True).communicate()
|
|
|
- # does when capturing PO files contents from stdout of gettext command
|
|
|
- # line programs. No need to do anything on Python 2 because it's
|
|
|
- # already a byte-string there (#23271).
|
|
|
- stdout = stdout.encode(DEFAULT_LOCALE_ENCODING).decode(stdout_encoding)
|
|
|
+ # This both decodes utf-8 and cleans line endings. Simply using
|
|
|
+ # popen_wrapper(universal_newlines=True) doesn't properly handle the
|
|
|
+ # encoding. This goes back to popen's flaky support for encoding:
|
|
|
+ # https://bugs.python.org/issue6135. This is a solution for #23271, #21928.
|
|
|
+ # No need to do anything on Python 2 because it's already a byte-string there.
|
|
|
+ manual_io_wrapper = six.PY3 and stdout_encoding != DEFAULT_LOCALE_ENCODING
|
|
|
+
|
|
|
+ stdout, stderr, status_code = popen_wrapper(args, os_err_exc_type=os_err_exc_type,
|
|
|
+ universal_newlines=not manual_io_wrapper)
|
|
|
+ if manual_io_wrapper:
|
|
|
+ stdout = io.TextIOWrapper(io.BytesIO(stdout), encoding=stdout_encoding).read()
|
|
|
if six.PY2:
|
|
|
stdout = stdout.decode(stdout_encoding)
|
|
|
return stdout, stderr, status_code
|