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_numliterals.py < prev    next >
Encoding:
Python Source  |  2011-03-15  |  789 b   |  28 lines

  1. """Fixer that turns 1L into 1, 0755 into 0o755.
  2. """
  3. # Copyright 2007 Georg Brandl.
  4. # Licensed to PSF under a Contributor Agreement.
  5.  
  6. # Local imports
  7. from ..pgen2 import token
  8. from .. import fixer_base
  9. from ..fixer_util import Number
  10.  
  11.  
  12. class FixNumliterals(fixer_base.BaseFix):
  13.     # This is so simple that we don't need the pattern compiler.
  14.  
  15.     def match(self, node):
  16.         # Override
  17.         return (node.type == token.NUMBER and
  18.                 (node.value.startswith("0") or node.value[-1] in "Ll"))
  19.  
  20.     def transform(self, node, results):
  21.         val = node.value
  22.         if val[-1] in 'Ll':
  23.             val = val[:-1]
  24.         elif val.startswith('0') and val.isdigit() and len(set(val)) > 1:
  25.             val = "0o" + val[1:]
  26.  
  27.         return Number(val, prefix=node.get_prefix())
  28.