[Python-checkins] python/dist/src/Lib gettext.py,1.16,1.17

loewis@users.sourceforge.net loewis@users.sourceforge.net
Mon, 10 Mar 2003 08:01:46 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv10742

Modified Files:
	gettext.py 
Log Message:
Patch #700839: Fix bugs in the plural handling.

Index: gettext.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/gettext.py,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** gettext.py	21 Nov 2002 21:45:32 -0000	1.16
--- gettext.py	10 Mar 2003 16:01:43 -0000	1.17
***************
*** 33,37 ****
  # module.
  #
! # J. David Ibanez implemented plural forms.
  #
  # TODO:
--- 33,37 ----
  # module.
  #
! # J. David Ibanez implemented plural forms. Bruno Haible fixed some bugs.
  #
  # TODO:
***************
*** 81,87 ****
      import token, tokenize
      tokens = tokenize.generate_tokens(StringIO(plural).readline)
!     danger = [ x for x in tokens if x[0] == token.NAME and x[1] != 'n' ]
!     if danger:
!         raise ValueError, 'dangerous expression'
  
      # Replace some C operators by their Python equivalents
--- 81,92 ----
      import token, tokenize
      tokens = tokenize.generate_tokens(StringIO(plural).readline)
!     try:
!         danger = [ x for x in tokens if x[0] == token.NAME and x[1] != 'n' ]
!     except tokenize.TokenError:
!         raise ValueError, \
!               'plural forms expression error, maybe unbalanced parenthesis'
!     else:
!         if danger:
!             raise ValueError, 'plural forms expression could be dangerous'
  
      # Replace some C operators by their Python equivalents
***************
*** 89,94 ****
      plural = plural.replace('||', ' or ')
  
!     expr = re.compile(r'\![^=]')
!     plural = expr.sub(' not ', plural)
  
      # Regular expression and replacement function used to transform
--- 94,99 ----
      plural = plural.replace('||', ' or ')
  
!     expr = re.compile(r'\!([^=])')
!     plural = expr.sub(' not \\1', plural)
  
      # Regular expression and replacement function used to transform
***************
*** 105,109 ****
              stack.append('')
          elif c == ')':
!             if len(stack) == 0:
                  raise ValueError, 'unbalanced parenthesis in plural form'
              s = expr.sub(repl, stack.pop())
--- 110,117 ----
              stack.append('')
          elif c == ')':
!             if len(stack) == 1:
!                 # Actually, we never reach this code, because unbalanced
!                 # parentheses get caught in the security check at the
!                 # beginning.
                  raise ValueError, 'unbalanced parenthesis in plural form'
              s = expr.sub(repl, stack.pop())
***************
*** 226,229 ****
--- 234,238 ----
          # bit words.
          self._catalog = catalog = {}
+         self.plural = lambda n: int(n != 1) # germanic plural by default
          buf = fp.read()
          buflen = len(buf)
***************
*** 259,263 ****
                  raise IOError(0, 'File is corrupt', filename)
              # See if we're looking at GNU .mo conventions for metadata
!             if mlen == 0 and tmsg.lower().startswith('project-id-version:'):
                  # Catalog description
                  for item in tmsg.split('\n'):
--- 268,272 ----
                  raise IOError(0, 'File is corrupt', filename)
              # See if we're looking at GNU .mo conventions for metadata
!             if mlen == 0:
                  # Catalog description
                  for item in tmsg.split('\n'):