New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gettext bug while parsing plural-forms metadata #62098
Comments
The gettext.py parser used by django (lib/python2.7/gettext.py), To reproduce the problem (see traceback, below), try parsing a .PO file containing two headers like this, with a comment header immediately following a plurals header. This example was created by calling msgcat to combine several .po files into a single .po file. Msgcat inserted the comment line. "Plural-Forms: nplurals=2; plural=(n != 1);\n" Parsing the first header binds the inner loop variables: Parsing the second header leaves k,v untouched, which then causes an improper Bug workaround: I use polib to read and immediately save the file. This reorders the metadata to avoid presenting the parser with something that will break it. Recommended bug fix: on each iteration over tmsg.splitlines, reset the values of k,v = (None, None) -------------------- Exception Type: AttributeError at / |
Does this bear any relationship to bpo-1475523? (And yes, I know it is...sad...that that issue hasn't been fixed yet.) |
There seem to be several bugs involving this particular inner loop in gettext._parse(), but I don't think they're equivalent. The present bug (bpo-17898) is that parsing a plural header breaks the following header when it happens to be a comment. bpo-1475523 seems to involve multi-line handling bpo-12425 seems to involve breaking when the plural-forms value is empty. Perhaps a useful design pattern to follow for code which executes this inner loop would be to have some initialization and loop invariants which are asserted true on each iteration. For example, properly initializing k and v on each iteration. |
Since the other two listed inner-loop issues apply to 3.x, I would guess that this does also. Steve, can you test with 3.3? And provide a *minimal* test case? |
Sorry, I haven't installed python 3.*, I just have default Mac OS python 2.7. Here's a minimal test case. Tar expands to $ ./test.py Traceback (most recent call last):
File "./test.py", line 28, in <module>
test()
File "./test.py", line 23, in test
gettext.install('messages', localedir=LOCALEDIR)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 494, in install
t = translation(domain, localedir, fallback=True, codeset=codeset)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 479, in translat\
ion
t = _translations.setdefault(key, class_(fp))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 180, in __init__
self._parse(fp)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/gettext.py", line 314, in _parse
v = v.split(';')
AttributeError: 'list' object has no attribute 'split' |
Proposed patch against 3.5. |
Adding a link to a bitbucket repo. |
I would apply this change to 3.4 and 3.5. Should I also backport it to 2.7? I think the same bug applies there, though I haven't verified this or tried my patch. |
LGTM. I think it should be backported to 2.7. |
New changeset c3d269c01671 by Andrew Kuchling in branch '2.7': |
New changeset 54df02192bfc by Andrew Kuchling in branch '3.4': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: