Skip to content

Commit 19ddaf6

Browse files
committed
Merge from 3.4
2 parents 467a546 + b3c30d9 commit 19ddaf6

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

Lib/gettext.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,12 @@ def _parse(self, fp):
275275
# See if we're looking at GNU .mo conventions for metadata
276276
if mlen == 0:
277277
# Catalog description
278-
lastk = k = None
278+
lastk = None
279279
for b_item in tmsg.split('\n'.encode("ascii")):
280280
item = b_item.decode().strip()
281281
if not item:
282282
continue
283+
k = v = None
283284
if ':' in item:
284285
k, v = item.split(':', 1)
285286
k = k.strip().lower()

Lib/test/test_gettext.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ def tearDown(self):
134134
del self.env
135135
support.rmtree(os.path.split(LOCALEDIR)[0])
136136

137+
GNU_MO_DATA_ISSUE_17898 = b'''\
138+
3hIElQAAAAABAAAAHAAAACQAAAAAAAAAAAAAAAAAAAAsAAAAggAAAC0AAAAAUGx1cmFsLUZvcm1z
139+
OiBucGx1cmFscz0yOyBwbHVyYWw9KG4gIT0gMSk7CiMtIy0jLSMtIyAgbWVzc2FnZXMucG8gKEVk
140+
WCBTdHVkaW8pICAjLSMtIy0jLSMKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PVVU
141+
Ri04CgA=
142+
'''
137143

138144
class GettextTestCase1(GettextBaseTest):
139145
def setUp(self):
@@ -360,6 +366,14 @@ def test_security(self):
360366
# Test for a dangerous expression
361367
raises(ValueError, gettext.c2py, "os.chmod('/etc/passwd',0777)")
362368

369+
class GNUTranslationParsingTest(GettextBaseTest):
370+
def test_plural_form_error_issue17898(self):
371+
with open(MOFILE, 'wb') as fp:
372+
fp.write(base64.decodebytes(GNU_MO_DATA_ISSUE_17898))
373+
with open(MOFILE, 'rb') as fp:
374+
# If this runs cleanly, the bug is fixed.
375+
t = gettext.GNUTranslations(fp)
376+
363377

364378
class UnicodeTranslationsTest(GettextBaseTest):
365379
def setUp(self):
@@ -535,3 +549,16 @@ def test_main():
535549
"Content-Transfer-Encoding: quoted-printable\n"
536550
"Generated-By: pygettext.py 1.3\n"
537551
'''
552+
553+
#
554+
# messages.po, used for bug 17898
555+
#
556+
557+
'''
558+
# test file for http://bugs.python.org/issue17898
559+
msgid ""
560+
msgstr ""
561+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
562+
"#-#-#-#-# messages.po (EdX Studio) #-#-#-#-#\n"
563+
"Content-Type: text/plain; charset=UTF-8\n"
564+
'''

Misc/NEWS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ Library
4747
- Issue #21859: Added Python implementation of io.FileIO.
4848

4949
- Issue #23865: close() methods in multiple modules now are idempotent and more
50-
robust at shutdown. If needs to release multiple resources, they are released
51-
even if errors are occured.
50+
robust at shutdown. If they need to release multiple resources, all are
51+
released even if errors occur.
5252

5353
- Issue #23400: Raise same exception on both Python 2 and 3 if sem_open is not
5454
available. Patch by Davin Potts.

0 commit comments

Comments
 (0)