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
This commit is contained in:
Russell Keith-Magee 2010-04-19 11:52:56 +00:00
parent c3dbe9d509
commit 56eb340528
2 changed files with 31 additions and 7 deletions

View File

@ -185,7 +185,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
src = open(os.path.join(dirpath, file), "rU").read() src = open(os.path.join(dirpath, file), "rU").read()
src = pythonize_re.sub('\n#', src) src = pythonize_re.sub('\n#', src)
thefile = '%s.py' % file thefile = '%s.py' % file
open(os.path.join(dirpath, thefile), "w").write(src) f = open(os.path.join(dirpath, thefile), "w")
try:
f.write(src)
finally:
f.close()
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)) 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))
msgs, errors = _popen(cmd) msgs, errors = _popen(cmd)
if errors: if errors:
@ -199,7 +203,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
else: else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
if msgs: if msgs:
open(potfile, 'ab').write(msgs) f = open(potfile, 'ab')
try:
f.write(msgs)
finally:
f.close()
os.unlink(os.path.join(dirpath, thefile)) os.unlink(os.path.join(dirpath, thefile))
elif domain == 'django' and (file_ext == '.py' or file_ext in extensions): elif domain == 'django' and (file_ext == '.py' or file_ext in extensions):
thefile = file thefile = file
@ -207,7 +215,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
src = open(os.path.join(dirpath, file), "rU").read() src = open(os.path.join(dirpath, file), "rU").read()
thefile = '%s.py' % file thefile = '%s.py' % file
try: try:
open(os.path.join(dirpath, thefile), "w").write(templatize(src)) f = open(os.path.join(dirpath, thefile), "w")
try:
f.write(templatize(src))
finally:
f.close()
except SyntaxError, msg: except SyntaxError, msg:
msg = "%s (file: %s)" % (msg, os.path.join(dirpath, file)) msg = "%s (file: %s)" % (msg, os.path.join(dirpath, file))
raise SyntaxError(msg) raise SyntaxError(msg)
@ -229,7 +241,11 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
else: else:
msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8') msgs = msgs.replace('charset=CHARSET', 'charset=UTF-8')
if msgs: if msgs:
open(potfile, 'ab').write(msgs) f = open(potfile, 'ab')
try:
f.write(msgs)
finally:
f.close()
if thefile != file: if thefile != file:
os.unlink(os.path.join(dirpath, thefile)) os.unlink(os.path.join(dirpath, thefile))
@ -237,14 +253,22 @@ def make_messages(locale=None, domain='django', verbosity='1', all=False,
msgs, errors = _popen('msguniq --to-code=utf-8 "%s"' % potfile) msgs, errors = _popen('msguniq --to-code=utf-8 "%s"' % potfile)
if errors: if errors:
raise CommandError("errors happened while running msguniq\n%s" % errors) raise CommandError("errors happened while running msguniq\n%s" % errors)
open(potfile, 'w').write(msgs) f = open(potfile, 'w')
try:
f.write(msgs)
finally:
f.close()
if os.path.exists(pofile): if os.path.exists(pofile):
msgs, errors = _popen('msgmerge -q "%s" "%s"' % (pofile, potfile)) msgs, errors = _popen('msgmerge -q "%s" "%s"' % (pofile, potfile))
if errors: if errors:
raise CommandError("errors happened while running msgmerge\n%s" % errors) raise CommandError("errors happened while running msgmerge\n%s" % errors)
elif not invoked_for_django: elif not invoked_for_django:
msgs = copy_plural_forms(msgs, locale, domain, verbosity) msgs = copy_plural_forms(msgs, locale, domain, verbosity)
open(pofile, 'wb').write(msgs) f = open(pofile, 'wb')
try:
f.write(msgs)
finally:
f.close()
os.unlink(potfile) os.unlink(potfile)

View File

@ -12,7 +12,7 @@ tests = r"""
>>> olddate = datetime.date >>> olddate = datetime.date
>>> datetime.date = MockDate >>> datetime.date = MockDate
>>> datetime.date.today() >>> datetime.date.today()
MockDate(2008, 5, 14) ...MockDate(2008, 5, 14)
# SECountySelect ##################################################### # SECountySelect #####################################################