This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author straz
Recipients straz
Date 2013-05-03.18:19:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
The parser used by django (lib/python2.7/,
GNUTranslations._parse(), around line 313 does not use clean values for k,v on each
iteration ("for item in tmsg.splitlines():")

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"
"#-#-#-#-#  messages.po (EdX Studio)  #-#-#-#-#\n"

Parsing the first header binds the inner loop variables:
  k= plural-forms v= ['nplurals=2', ' plural=(n != 1)', '']

Parsing the second header leaves k,v untouched, which then causes an improper
attempt to parse (since it's a comment, no further parsing of k,v should occur)
 v = v.split(';')

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)

File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/core/handlers/" in get_response
89.                     response = middleware_method(request)
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/middleware/" in process_request
24.         translation.activate(language)
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/utils/translation/" in activate
105.     return _trans.activate(language)
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/utils/translation/" in activate
201.     _active.value = translation(language)
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/utils/translation/" in translation
191.     current_translation = _fetch(language, fallback=default_translation)
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/utils/translation/" in _fetch
180.                 res = _merge(localepath)
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/utils/translation/" in _merge
156.             t = _translation(path)
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/utils/translation/" in _translation
138.                 t = gettext_module.translation('django', path, [loc], DjangoTranslation)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/" in translation
480.                 t = _translations.setdefault(key, class_(fp))
File "/Users/sstrassmann/src/mitx_all/python/lib/python2.7/site-packages/django/utils/translation/" in __init__
76.         gettext_module.GNUTranslations.__init__(self, *args, **kw)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/" in __init__
180.             self._parse(fp)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/" in _parse
315.                         v = v.split(';')

Exception Type: AttributeError at /
Exception Value: 'list' object has no attribute 'split'
Date User Action Args
2013-05-03 18:19:46strazsetrecipients: + straz
2013-05-03 18:19:46strazsetmessageid: <>
2013-05-03 18:19:46strazlinkissue17898 messages
2013-05-03 18:19:45strazcreate