Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Tools/i18n/msgfmt.py

    r2 r391  
    2626"""
    2727
     28import os
    2829import sys
    29 import os
     30import ast
    3031import getopt
    3132import struct
     
    138139            continue
    139140        # Now we are in a msgid section, output previous section
    140         if l.startswith('msgid'):
     141        if l.startswith('msgid') and not l.startswith('msgid_plural'):
    141142            if section == STR:
    142143                add(msgid, msgstr, fuzzy)
     
    144145            l = l[5:]
    145146            msgid = msgstr = ''
     147            is_plural = False
     148        # This is a message with plural forms
     149        elif l.startswith('msgid_plural'):
     150            if section != ID:
     151                print >> sys.stderr, 'msgid_plural not preceded by msgid on %s:%d' %\
     152                    (infile, lno)
     153                sys.exit(1)
     154            l = l[12:]
     155            msgid += '\0' # separator of singular and plural
     156            is_plural = True
    146157        # Now we are in a msgstr section
    147158        elif l.startswith('msgstr'):
    148159            section = STR
    149             l = l[6:]
     160            if l.startswith('msgstr['):
     161                if not is_plural:
     162                    print >> sys.stderr, 'plural without msgid_plural on %s:%d' %\
     163                        (infile, lno)
     164                    sys.exit(1)
     165                l = l.split(']', 1)[1]
     166                if msgstr:
     167                    msgstr += '\0' # Separator of the various plural forms
     168            else:
     169                if is_plural:
     170                    print >> sys.stderr, 'indexed msgstr required for plural on  %s:%d' %\
     171                        (infile, lno)
     172                    sys.exit(1)
     173                l = l[6:]
    150174        # Skip empty lines
    151175        l = l.strip()
    152176        if not l:
    153177            continue
    154         # XXX: Does this always follow Python escape semantics?
    155         l = eval(l)
     178        l = ast.literal_eval(l)
    156179        if section == ID:
    157180            msgid += l
Note: See TracChangeset for help on using the changeset viewer.