[1.8.x] Refs #24500 -- Avoided locale.getpreferredencoding in makemessages

Fixes a regression introduced in 53c2cf1e.
Backport of 3f4e77840 from master.
This commit is contained in:
Claude Paroz 2015-04-01 18:37:47 +02:00
parent 70c5031d56
commit 72de42cd40
1 changed files with 4 additions and 6 deletions

View File

@ -3,7 +3,6 @@ from __future__ import unicode_literals
import fnmatch import fnmatch
import glob import glob
import io import io
import locale
import os import os
import re import re
import sys import sys
@ -17,7 +16,7 @@ from django.core.management.utils import (
) )
from django.utils import six from django.utils import six
from django.utils._os import upath from django.utils._os import upath
from django.utils.encoding import force_str from django.utils.encoding import DEFAULT_LOCALE_ENCODING, force_str
from django.utils.functional import cached_property, total_ordering from django.utils.functional import cached_property, total_ordering
from django.utils.jslex import prepare_js_for_gettext from django.utils.jslex import prepare_js_for_gettext
from django.utils.text import get_text_list from django.utils.text import get_text_list
@ -38,14 +37,13 @@ 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) stdout, stderr, status_code = popen_wrapper(args, os_err_exc_type=os_err_exc_type)
preferred_encoding = locale.getpreferredencoding(False) if os.name == 'nt' and six.PY3 and stdout_encoding != DEFAULT_LOCALE_ENCODING:
if os.name == 'nt' and six.PY3 and stdout_encoding != preferred_encoding:
# This looks weird because it's undoing what # This looks weird because it's undoing what
# subprocess.Popen(universal_newlines=True).communicate() # subprocess.Popen(universal_newlines=True).communicate()
# does when capturing PO files contents from stdout of gettext command # does when capturing PO files contents from stdout of gettext command
# line programs. No need to do anything on Python 2 because it's # line programs. No need to do anything on Python 2 because it's
# already a byte-string there (#23271). # already a byte-string there (#23271).
stdout = stdout.encode(preferred_encoding).decode(stdout_encoding) stdout = stdout.encode(DEFAULT_LOCALE_ENCODING).decode(stdout_encoding)
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
@ -332,7 +330,7 @@ class Command(BaseCommand):
# when looking up the version. It's especially a problem on Windows. # when looking up the version. It's especially a problem on Windows.
out, err, status = gettext_popen_wrapper( out, err, status = gettext_popen_wrapper(
['xgettext', '--version'], ['xgettext', '--version'],
stdout_encoding=locale.getpreferredencoding(False), stdout_encoding=DEFAULT_LOCALE_ENCODING,
) )
m = re.search(r'(\d+)\.(\d+)\.?(\d+)?', out) m = re.search(r'(\d+)\.(\d+)\.?(\d+)?', out)
if m: if m: