Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13374 -- Corrected some more minor issues causing problems for…

… PyPy. Thanks to Alex Gaynor for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12998 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 56eb340528d392612f3229b4bd8b7416553c3b15 1 parent c3dbe9d
Russell Keith-Magee authored April 19, 2010
36  django/core/management/commands/makemessages.py
@@ -185,7 +185,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
185 185
                 src = open(os.path.join(dirpath, file), "rU").read()
186 186
                 src = pythonize_re.sub('\n#', src)
187 187
                 thefile = '%s.py' % file
188  
-                open(os.path.join(dirpath, thefile), "w").write(src)
  188
+                f = open(os.path.join(dirpath, thefile), "w")
  189
+                try:
  190
+                    f.write(src)
  191
+                finally:
  192
+                    f.close()
189 193
                 cmd = 'xgettext -d %s -L Perl --keyword=gettext_noop --keyword=gettext_lazy --keyword=ngettext_lazy:1,2 --from-code UTF-8 -o - "%s"' % (domain, os.path.join(dirpath, thefile))
190 194
                 msgs, errors = _popen(cmd)
191 195
                 if errors:
@@ -199,7 +203,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
199 203
                 else:
200 204
                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
201 205
                 if msgs:
202  
-                    open(potfile, 'ab').write(msgs)
  206
+                    f = open(potfile, 'ab')
  207
+                    try:
  208
+                        f.write(msgs)
  209
+                    finally:
  210
+                        f.close()
203 211
                 os.unlink(os.path.join(dirpath, thefile))
204 212
             elif domain == 'django' and (file_ext == '.py' or file_ext in extensions):
205 213
                 thefile = file
@@ -207,7 +215,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
207 215
                     src = open(os.path.join(dirpath, file), "rU").read()
208 216
                     thefile = '%s.py' % file
209 217
                     try:
210  
-                        open(os.path.join(dirpath, thefile), "w").write(templatize(src))
  218
+                        f = open(os.path.join(dirpath, thefile), "w")
  219
+                        try:
  220
+                            f.write(templatize(src))
  221
+                        finally:
  222
+                            f.close()
211 223
                     except SyntaxError, msg:
212 224
                         msg = "%s (file: %s)" % (msg, os.path.join(dirpath, file))
213 225
                         raise SyntaxError(msg)
@@ -229,7 +241,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
229 241
                 else:
230 242
                     msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
231 243
                 if msgs:
232  
-                    open(potfile, 'ab').write(msgs)
  244
+                    f = open(potfile, 'ab')
  245
+                    try:
  246
+                        f.write(msgs)
  247
+                    finally:
  248
+                        f.close()
233 249
                 if thefile != file:
234 250
                     os.unlink(os.path.join(dirpath, thefile))
235 251
 
@@ -237,14 +253,22 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
237 253
             msgs, errors = _popen('msguniq --to-code=utf-8 "%s"' % potfile)
238 254
             if errors:
239 255
                 raise CommandError("errors happened while running msguniq\n%s" % errors)
240  
-            open(potfile, 'w').write(msgs)
  256
+            f = open(potfile, 'w')
  257
+            try:
  258
+                f.write(msgs)
  259
+            finally:
  260
+                f.close()
241 261
             if os.path.exists(pofile):
242 262
                 msgs, errors = _popen('msgmerge -q "%s" "%s"' % (pofile, potfile))
243 263
                 if errors:
244 264
                     raise CommandError("errors happened while running msgmerge\n%s" % errors)
245 265
             elif not invoked_for_django:
246 266
                 msgs = copy_plural_forms(msgs, locale, domain, verbosity)
247  
-            open(pofile, 'wb').write(msgs)
  267
+            f = open(pofile, 'wb')
  268
+            try:
  269
+                f.write(msgs)
  270
+            finally:
  271
+                f.close()
248 272
             os.unlink(potfile)
249 273
 
250 274
 
2  tests/regressiontests/forms/localflavor/se.py
@@ -12,7 +12,7 @@
12 12
 >>> olddate = datetime.date
13 13
 >>> datetime.date = MockDate
14 14
 >>> datetime.date.today()
15  
-MockDate(2008, 5, 14)
  15
+...MockDate(2008, 5, 14)
16 16
 
17 17
 
18 18
 # SECountySelect #####################################################

0 notes on commit 56eb340

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