source: python/trunk/Lib/lib2to3/fixes/fix_numliterals.py

Last change on this file was 2, checked in by Yuri Dario, 15 years ago

Initial import for vendor code.

  • Property svn:eol-style set to native
File size: 773 bytes
Line 
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
7from ..pgen2 import token
8from .. import fixer_base
9from ..fixer_util import Number
10
11
12class FixNumliterals(fixer_base.BaseFix):
13 # This is so simple that we don't need the pattern compiler.
14
15 _accept_type = token.NUMBER
16
17 def match(self, node):
18 # Override
19 return (node.value.startswith(u"0") or node.value[-1] in u"Ll")
20
21 def transform(self, node, results):
22 val = node.value
23 if val[-1] in u'Ll':
24 val = val[:-1]
25 elif val.startswith(u'0') and val.isdigit() and len(set(val)) > 1:
26 val = u"0o" + val[1:]
27
28 return Number(val, prefix=node.prefix)
Note: See TracBrowser for help on using the repository browser.