Message 27754 - Python tracker (original) (raw)

See http://bugzilla.gnome.org/show_bug.cgi?id=334256

The problem is a PO file like the following:

test.po: msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "#-#-#-#-# plo.po (PACKAGE VERSION) #-#-#-#-#\n"

(these kinds of entries are sometimes inserted by msgmerge, so they're somewhat common)

Any Python program trying to access this breaks:

$ python test.py Traceback (most recent call last): File "test.py", line 7, in ? gt = gettext.GNUTranslations(file) File "/usr/lib/python2.4/gettext.py", line 177, in init self._parse(fp) File "/usr/lib/python2.4/gettext.py", line 300, in _parse v = v.split(';') AttributeError: 'list' object has no attribute 'split'

test.py is simple: #!/usr/bin/env python import gettext file = open("test.mo", "rb") if file: gt = gettext.GNUTranslations(file)

The problem is the corner-case: plural-forms precedes this kind of comment, so "v" is split (v=v.split(";")). In the next instance, lastk is "plural-forms", yet the entry doesn't contain ":", so it tries to set plural forms to v.split(";") again, which fails since v is already a list.

The attached simple patch fixes this.