mirror of
https://github.com/python/cpython.git
synced 2025-07-21 02:05:20 +00:00

svn+ssh://pythondev@svn.python.org/python/trunk ........ r61596 | martin.v.loewis | 2008-03-18 23:43:46 -0500 (Di, 18 Mär 2008) | 2 lines Import lib2to3. ........ r61597 | martin.v.loewis | 2008-03-18 23:58:04 -0500 (Di, 18 Mär 2008) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-61595" from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........
27 lines
779 B
Python
27 lines
779 B
Python
"""Fixer that turns 1L into 1, 0755 into 0o755.
|
|
"""
|
|
# Copyright 2007 Georg Brandl.
|
|
# Licensed to PSF under a Contributor Agreement.
|
|
|
|
# Local imports
|
|
from ..pgen2 import token
|
|
from .import basefix
|
|
from .util import Number, set
|
|
|
|
|
|
class FixNumliterals(basefix.BaseFix):
|
|
# This is so simple that we don't need the pattern compiler.
|
|
|
|
def match(self, node):
|
|
# Override
|
|
return (node.type == token.NUMBER and
|
|
(node.value.startswith("0") or node.value[-1] in "Ll"))
|
|
|
|
def transform(self, node, results):
|
|
val = node.value
|
|
if val[-1] in 'Ll':
|
|
val = val[:-1]
|
|
elif val.startswith('0') and val.isdigit() and len(set(val)) > 1:
|
|
val = "0o" + val[1:]
|
|
|
|
return Number(val, prefix=node.get_prefix())
|