~malept/ubuntu/lucid/python2.6/dev-dependency-fix

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-13 12:51:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090213125100-uufgcb9yeqzujpqw
Tags: upstream-2.6.1
ImportĀ upstreamĀ versionĀ 2.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Fix bound method attributes (method.im_? -> method.__?__).
 
2
"""
 
3
# Author: Christian Heimes
 
4
 
 
5
# Local imports
 
6
from .. import fixer_base
 
7
from ..fixer_util import Name
 
8
 
 
9
MAP = {
 
10
    "im_func" : "__func__",
 
11
    "im_self" : "__self__",
 
12
    "im_class" : "__self__.__class__"
 
13
    }
 
14
 
 
15
class FixMethodattrs(fixer_base.BaseFix):
 
16
    PATTERN = """
 
17
    power< any+ trailer< '.' attr=('im_func' | 'im_self' | 'im_class') > any* >
 
18
    """
 
19
 
 
20
    def transform(self, node, results):
 
21
        attr = results["attr"][0]
 
22
        new = MAP[attr.value]
 
23
        attr.replace(Name(new, prefix=attr.get_prefix()))