home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 July / maximum-cd-2011-07.iso / DiscContents / LibO_3.3.2_Win_x86_install_multi.exe / libreoffice1.cab / fix_long.py < prev    next >
Encoding:
Python Source  |  2011-03-15  |  937 b   |  36 lines

  1. # Copyright 2006 Google, Inc. All Rights Reserved.
  2. # Licensed to PSF under a Contributor Agreement.
  3.  
  4. """Fixer that turns 'long' into 'int' everywhere.
  5.  
  6. This also strips the trailing 'L' or 'l' from long loterals.
  7. """
  8.  
  9. # Local imports
  10. from .. import pytree
  11. from .. import fixer_base
  12. from ..fixer_util import Name, Number
  13.  
  14.  
  15. class FixLong(fixer_base.BaseFix):
  16.  
  17.     PATTERN = """
  18.     (long_type = 'long' | number = NUMBER)
  19.     """
  20.  
  21.     static_long = Name("long")
  22.     static_int = Name("int")
  23.  
  24.     def transform(self, node, results):
  25.         long_type = results.get("long_type")
  26.         number = results.get("number")
  27.         new = None
  28.         if long_type:
  29.             assert node == self.static_long, node
  30.             new = self.static_int.clone()
  31.         if number and node.value[-1] in ("l", "L"):
  32.             new = Number(node.value[:-1])
  33.         if new is not None:
  34.             new.set_prefix(node.get_prefix())
  35.             return new
  36.