From 1f6688b967aaac0a674a1c33512db1455ea6e712 Mon Sep 17 00:00:00 2001 From: balr0g Date: Sat, 26 Mar 2016 09:01:37 -0400 Subject: Bugfixes to msgfmt, charset parsing broken on Python 2.6 for inexplicable reasons but does not cause failure (nw) --- scripts/build/msgfmt.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'scripts/build/msgfmt.py') diff --git a/scripts/build/msgfmt.py b/scripts/build/msgfmt.py index 5b58bde0dd4..7b804504f05 100644 --- a/scripts/build/msgfmt.py +++ b/scripts/build/msgfmt.py @@ -140,10 +140,10 @@ def make(filename, outfile): section = None fuzzy = 0 empty = 0 + header_attempted = False # Start off assuming Latin-1, so everything decodes without failure, # until we know the exact encoding - charset = None encoding = 'latin-1' # Start off assuming Latin-1, so everything decodes without failure, @@ -207,11 +207,11 @@ def make(filename, outfile): if msgstr: msgstr += b'\0' # Separator of the various plural forms else: - if (l[6:].strip() == '""') and (empty == 1) and (not charset): + if (l[6:].strip() == '""') and (empty == 1) and (not header_attempted): header = "" # parse up until next empty line = end of header hdrno = lno - while(hdrno < len(lines)): + while(hdrno < len(lines)-1): # This is a roundabout way to strip non-ASCII unicode characters from the header. # As we are only parsing out the encoding, we don't need any unicode chars in it. l = lines[hdrno+1].decode('unicode_escape').encode('ascii','ignore').decode(encoding) @@ -221,10 +221,12 @@ def make(filename, outfile): break hdrno += 1 # See whether there is an encoding declaration - p = HeaderParser() - charset = p.parsestr(header).get_content_charset() - if charset: - encoding = charset + if(hdrno > lno): + p = HeaderParser() + charset = p.parsestr(header).get_content_charset() + header_attempted = 1 + if charset: + encoding = charset if is_plural: print('indexed msgstr required for plural on %s:%d' % (infile, lno), file=sys.stderr) -- cgit v1.2.3-70-g09d2