From 96a37a0266b3bf46491cc764e4096cc3bfeda6b3 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 14 Jul 2016 18:24:40 +0200 Subject: [PATCH] [1.10.x] Fixed #26897 -- Fixed makemessages crash on Python 2 with non-ASCII file names Thanks Tim Graham for the review. Backport of 3e71f6544feca490211e88db4f449dfdb7acce39 from master. --- django/core/management/commands/makemessages.py | 2 +- docs/releases/1.9.8.txt | 3 +++ tests/i18n/test_extraction.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py index c0f9d58f9dd..8e00c51dc3c 100644 --- a/django/core/management/commands/makemessages.py +++ b/django/core/management/commands/makemessages.py @@ -549,7 +549,7 @@ class Command(BaseCommand): input_files = [bf.work_path for bf in build_files] with NamedTemporaryFile(mode='w+') as input_files_list: - input_files_list.write('\n'.join(input_files)) + input_files_list.write(force_str('\n'.join(input_files), encoding=DEFAULT_LOCALE_ENCODING)) input_files_list.flush() args.extend(['--files-from', input_files_list.name]) args.extend(self.xgettext_options) diff --git a/docs/releases/1.9.8.txt b/docs/releases/1.9.8.txt index 7265e166b8a..8db5c3d01f6 100644 --- a/docs/releases/1.9.8.txt +++ b/docs/releases/1.9.8.txt @@ -12,3 +12,6 @@ Bugfixes * Fixed missing ``varchar/text_pattern_ops`` index on ``CharField`` and ``TextField`` respectively when using ``AddField`` on PostgreSQL (:ticket:`26889`). + +* Fixed ``makemessages`` crash on Python 2 with non-ASCII file names + (:ticket:`26897`). diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index bad7c23051b..0e4d7889fbc 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -256,6 +256,10 @@ class BasicExtractorTests(ExtractorTests): self.assertIn("UnicodeDecodeError: skipped file not_utf8.txt in .", force_text(out.getvalue())) + def test_unicode_file_name(self): + open(os.path.join(self.test_dir, 'vidéo.txt'), 'a').close() + management.call_command('makemessages', locale=[LOCALE], verbosity=0) + def test_extraction_warning(self): """test xgettext warning about multiple bare interpolation placeholders""" os.chdir(self.test_dir)