changeset: 95635:c3d269c01671 branch: 2.7 parent: 95632:86fbe140e395 user: Andrew Kuchling date: Tue Apr 14 10:03:35 2015 -0400 files: Lib/gettext.py Lib/test/test_gettext.py Misc/NEWS description: #17898: reset k and v so that the loop doesn't use an old value diff -r 86fbe140e395 -r c3d269c01671 Lib/gettext.py --- a/Lib/gettext.py Mon Apr 13 09:58:36 2015 -0400 +++ b/Lib/gettext.py Tue Apr 14 10:03:35 2015 -0400 @@ -296,11 +296,12 @@ # See if we're looking at GNU .mo conventions for metadata if mlen == 0: # Catalog description - lastk = k = None + lastk = None for item in tmsg.splitlines(): item = item.strip() if not item: continue + k = v = None if ':' in item: k, v = item.split(':', 1) k = k.strip().lower() diff -r 86fbe140e395 -r c3d269c01671 Lib/test/test_gettext.py --- a/Lib/test/test_gettext.py Mon Apr 13 09:58:36 2015 -0400 +++ b/Lib/test/test_gettext.py Tue Apr 14 10:03:35 2015 -0400 @@ -80,6 +80,12 @@ del self.env shutil.rmtree(os.path.split(LOCALEDIR)[0]) +GNU_MO_DATA_ISSUE_17898 = b'''\ +3hIElQAAAAABAAAAHAAAACQAAAAAAAAAAAAAAAAAAAAsAAAAggAAAC0AAAAAUGx1cmFsLUZvcm1z +OiBucGx1cmFscz0yOyBwbHVyYWw9KG4gIT0gMSk7CiMtIy0jLSMtIyAgbWVzc2FnZXMucG8gKEVk +WCBTdHVkaW8pICAjLSMtIy0jLSMKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PVVU +Ri04CgA= +''' class GettextTestCase1(GettextBaseTest): def setUp(self): @@ -291,6 +297,14 @@ # Test for a dangerous expression raises(ValueError, gettext.c2py, "os.chmod('/etc/passwd',0777)") +class GNUTranslationParsingTest(GettextBaseTest): + def test_plural_form_error_issue17898(self): + with open(MOFILE, 'wb') as fp: + fp.write(base64.decodestring(GNU_MO_DATA_ISSUE_17898)) + with open(MOFILE, 'rb') as fp: + # If this runs cleanly, the bug is fixed. + t = gettext.GNUTranslations(fp) + class UnicodeTranslationsTest(GettextBaseTest): def setUp(self): @@ -465,3 +479,16 @@ "Content-Transfer-Encoding: quoted-printable\n" "Generated-By: pygettext.py 1.3\n" ''' + +# +# messages.po, used for bug 17898 +# + +''' +# test file for http://bugs.python.org/issue17898 +msgid "" +msgstr "" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"#-#-#-#-# messages.po (EdX Studio) #-#-#-#-#\n" +"Content-Type: text/plain; charset=UTF-8\n" +''' diff -r 86fbe140e395 -r c3d269c01671 Misc/NEWS --- a/Misc/NEWS Mon Apr 13 09:58:36 2015 -0400 +++ b/Misc/NEWS Tue Apr 14 10:03:35 2015 -0400 @@ -21,6 +21,8 @@ Library ------- +- Issue #17898: Fix exception in gettext.py when parsing certain plural forms. + - Issue #23865: close() methods in multiple modules now are idempotent and more robust at shutdown. If needs to release multiple resources, they are released even if errors are occured.