Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix #20058: Make compilemessages use stdout instead of stderr.

  • Loading branch information...
commit d5683bd06bdac923f73954020c760a4adb496be8 1 parent 0122a98
Baptiste Mispelon authored March 16, 2013
6  django/core/management/commands/compilemessages.py
@@ -15,7 +15,7 @@ def has_bom(fn):
15 15
             sample.startswith(codecs.BOM_UTF16_LE) or \
16 16
             sample.startswith(codecs.BOM_UTF16_BE)
17 17
 
18  
-def compile_messages(stderr, locale=None):
  18
+def compile_messages(stdout, locale=None):
19 19
     program = 'msgfmt'
20 20
     if find_command(program) is None:
21 21
         raise CommandError("Can't find %s. Make sure you have GNU gettext tools 0.15 or newer installed." % program)
@@ -41,7 +41,7 @@ def compile_messages(stderr, locale=None):
41 41
                 for f in filenames:
42 42
                     if not f.endswith('.po'):
43 43
                         continue
44  
-                    stderr.write('processing file %s in %s\n' % (f, dirpath))
  44
+                    stdout.write('processing file %s in %s\n' % (f, dirpath))
45 45
                     fn = os.path.join(dirpath, f)
46 46
                     if has_bom(fn):
47 47
                         raise CommandError("The %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM." % fn)
@@ -68,4 +68,4 @@ class Command(BaseCommand):
68 68
 
69 69
     def handle(self, **options):
70 70
         locale = options.get('locale')
71  
-        compile_messages(self.stderr, locale=locale)
  71
+        compile_messages(self.stdout, locale=locale)
12  tests/i18n/commands/compilation.py
@@ -29,7 +29,7 @@ class PoFileTests(MessageCompilationTests):
29 29
 
30 30
     def test_bom_rejection(self):
31 31
         with self.assertRaises(CommandError) as cm:
32  
-            call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
  32
+            call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
33 33
         self.assertIn("file has a BOM (Byte Order Mark)", cm.exception.args[0])
34 34
         self.assertFalse(os.path.exists(self.MO_FILE))
35 35
 
@@ -45,7 +45,7 @@ def setUp(self):
45 45
         self.addCleanup(os.unlink, os.path.join(test_dir, self.MO_FILE))
46 46
 
47 47
     def test_percent_symbol_in_po_file(self):
48  
-        call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
  48
+        call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
49 49
         self.assertTrue(os.path.exists(self.MO_FILE))
50 50
 
51 51
 
@@ -63,7 +63,7 @@ def setUp(self):
63 63
     @override_settings(LOCALE_PATHS=(os.path.join(test_dir, 'locale'),))
64 64
     def test_percent_symbol_escaping(self):
65 65
         from django.template import Template, Context
66  
-        call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
  66
+        call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())
67 67
         with translation.override(self.LOCALE):
68 68
             t = Template('{% load i18n %}{% trans "Looks like a str fmt spec %% o but shouldn\'t be interpreted as such" %}')
69 69
             rendered = t.render(Context({}))
@@ -88,12 +88,12 @@ def setUp(self):
88 88
         self.addCleanup(self.rmfile, os.path.join(localedir, self.MO_FILE_FR))
89 89
 
90 90
     def test_one_locale(self):
91  
-        call_command('compilemessages', locale='hr', stderr=StringIO())
  91
+        call_command('compilemessages', locale='hr', stdout=StringIO())
92 92
 
93 93
         self.assertTrue(os.path.exists(self.MO_FILE_HR))
94 94
 
95 95
     def test_multiple_locales(self):
96  
-        call_command('compilemessages', locale=['hr', 'fr'], stderr=StringIO())
  96
+        call_command('compilemessages', locale=['hr', 'fr'], stdout=StringIO())
97 97
 
98 98
         self.assertTrue(os.path.exists(self.MO_FILE_HR))
99 99
         self.assertTrue(os.path.exists(self.MO_FILE_FR))
@@ -110,4 +110,4 @@ def setUp(self):
110 110
 
111 111
     def test_error_reported_by_msgfmt(self):
112 112
         with self.assertRaises(CommandError):
113  
-            call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
  113
+            call_command('compilemessages', locale=self.LOCALE, stdout=StringIO())

0 notes on commit d5683bd

Please sign in to comment.
Something went wrong with that request. Please try again.