~ubuntu-branches/ubuntu/maverick/python3.1/maverick

« back to all changes in this revision

Viewing changes to Lib/lib2to3/fixes/fix_numliterals.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-23 00:01:27 UTC
  • Revision ID: james.westby@ubuntu.com-20090323000127-5fstfxju4ufrhthq
Tags: upstream-3.1~a1+20090322
ImportĀ upstreamĀ versionĀ 3.1~a1+20090322

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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())