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 ESC[4;38;5;81mFixNumliterals(ESC[4;38;5;149mfixer_baseESC[4;38;5;149m.ESC[4;38;5;149mBaseFix):
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("0") or node.value[-1] in "Ll")
20
21 def transform(self, node, results):
22 val = node.value
23 if val[-1] in 'Ll':
24 val = val[:-1]
25 elif val.startswith('0') and val.isdigit() and len(set(val)) > 1:
26 val = "0o" + val[1:]
27
28 return Number(val, prefix=node.prefix)