Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Ensured that `makemessages` doesn't leave any temporary file over if …

…the parsing of a template file fails. Refs #8536.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17240 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 45e3dff5ac697f16829697bc2a899eaeac8986ea 1 parent 39109b0
Julien Phalip authored
3  django/core/management/commands/makemessages.py
@@ -229,9 +229,10 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
229 229
                 if file_ext in extensions:
230 230
                     src = open(orig_file, "rU").read()
231 231
                     thefile = '%s.py' % file
  232
+                    content = templatize(src, orig_file[2:])
232 233
                     f = open(os.path.join(dirpath, thefile), "w")
233 234
                     try:
234  
-                        f.write(templatize(src, orig_file[2:]))
  235
+                        f.write(content)
235 236
                     finally:
236 237
                         f.close()
237 238
                 if verbosity > 1:
12  tests/regressiontests/i18n/commands/extraction.py
@@ -108,16 +108,14 @@ def test_extraction_error(self):
108 108
         os.chdir(self.test_dir)
109 109
         shutil.copyfile('./templates/template_with_error.tpl', './templates/template_with_error.html')
110 110
         self.assertRaises(SyntaxError, management.call_command, 'makemessages', locale=LOCALE, verbosity=0)
111  
-        try:
  111
+        with self.assertRaises(SyntaxError) as context_manager:
112 112
             management.call_command('makemessages', locale=LOCALE, verbosity=0)
113  
-        except SyntaxError, e:
114  
-            self.assertRegexpMatches(
115  
-                str(e),
  113
+        self.assertRegexpMatches(str(context_manager.exception),
116 114
                 r'Translation blocks must not include other block tags: blocktrans \(file templates[/\\]template_with_error\.html, line 3\)'
117 115
             )
118  
-        finally:
119  
-            os.remove('./templates/template_with_error.html')
120  
-            os.remove('./templates/template_with_error.html.py') # Waiting for #8536 to be fixed
  116
+        os.remove('./templates/template_with_error.html')
  117
+        # Check that the temporary file was cleaned up
  118
+        self.assertFalse(os.path.exists('./templates/template_with_error.html.py'))
121 119
 
122 120
     def test_template_message_context_extractor(self):
123 121
         """

0 notes on commit 45e3dff

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