Fixed #23271 -- Fixed makemessages crash/test failure for some locales.
This commit is contained in:
parent
be66173ad7
commit
57202a112a
|
@ -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.
|
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)
|
# This both decodes utf-8 and cleans line endings. Simply using
|
||||||
if os.name == 'nt' and six.PY3 and stdout_encoding != DEFAULT_LOCALE_ENCODING:
|
# popen_wrapper(universal_newlines=True) doesn't properly handle the
|
||||||
# This looks weird because it's undoing what
|
# encoding. This goes back to popen's flaky support for encoding:
|
||||||
# subprocess.Popen(universal_newlines=True).communicate()
|
# https://bugs.python.org/issue6135. This is a solution for #23271, #21928.
|
||||||
# does when capturing PO files contents from stdout of gettext command
|
# No need to do anything on Python 2 because it's already a byte-string there.
|
||||||
# line programs. No need to do anything on Python 2 because it's
|
manual_io_wrapper = six.PY3 and stdout_encoding != DEFAULT_LOCALE_ENCODING
|
||||||
# already a byte-string there (#23271).
|
|
||||||
stdout = stdout.encode(DEFAULT_LOCALE_ENCODING).decode(stdout_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:
|
if six.PY2:
|
||||||
stdout = stdout.decode(stdout_encoding)
|
stdout = stdout.decode(stdout_encoding)
|
||||||
return stdout, stderr, status_code
|
return stdout, stderr, status_code
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.utils.encoding import DEFAULT_LOCALE_ENCODING, force_text
|
||||||
from .base import CommandError
|
from .base import CommandError
|
||||||
|
|
||||||
|
|
||||||
def popen_wrapper(args, os_err_exc_type=CommandError):
|
def popen_wrapper(args, os_err_exc_type=CommandError, universal_newlines=True):
|
||||||
"""
|
"""
|
||||||
Friendly wrapper around Popen.
|
Friendly wrapper around Popen.
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ def popen_wrapper(args, os_err_exc_type=CommandError):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
p = Popen(args, shell=False, stdout=PIPE, stderr=PIPE,
|
p = Popen(args, shell=False, stdout=PIPE, stderr=PIPE,
|
||||||
close_fds=os.name != 'nt', universal_newlines=True)
|
close_fds=os.name != 'nt', universal_newlines=universal_newlines)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
strerror = force_text(e.strerror, DEFAULT_LOCALE_ENCODING,
|
strerror = force_text(e.strerror, DEFAULT_LOCALE_ENCODING,
|
||||||
strings_only=True)
|
strings_only=True)
|
||||||
|
|
|
@ -78,6 +78,8 @@ Bugfixes
|
||||||
* Removed flushing of the test database with :djadminopt:`--keepdb`, which
|
* Removed flushing of the test database with :djadminopt:`--keepdb`, which
|
||||||
prevented apps with data migrations from using the option (:ticket:`24729`).
|
prevented apps with data migrations from using the option (:ticket:`24729`).
|
||||||
|
|
||||||
|
* Fixed ``makemessages`` crash in some locales (:ticket:`23271`).
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue