# Path: py3kwarn2to3/fixer_util.py
# def Name(name, prefix=None):
#     """Return a NAME leaf"""
#     return Leaf(token.NAME, name, prefix=prefix)
# 
# def attr_chain(obj, attr):
#     """Follow an attribute chain.
# 
#     If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
#     use this to iterate over all objects in the chain. Iteration is
#     terminated by getattr(x, attr) is None.
# 
#     Args:
#         obj: the starting object
#         attr: the name of the chaining attribute
# 
#     Yields:
#         Each successive object in the chain.
#     """
#     next = getattr(obj, attr)
#     while next:
#         yield next
#         next = getattr(next, attr)


from .. import fixer_base
from ..fixer_util import Name, attr_chain
    for module, replace in MAPPING.items():
        for old_attr, new_attr in replace.items():
            LOOKUP[(module, old_attr)] = new_attr
            #bare.add(module)
            #bare.add(old_attr)
            #yield """
            #      import_name< 'import' (module=%r
            #          | dotted_as_names< any* module=%r any* >) >
            #      """ % (module, module)
            yield """
                  import_from< 'from' module_name=%r 'import'
                      ( attr_name=%r | import_as_name< attr_name=%r 'as' any >) >
                  """ % (module, old_attr, old_attr)
            yield """
                  power< module_name=%r trailer< '.' attr_name=%r > any* >
                  """ % (module, old_attr)
    #yield """bare_name=%s""" % alternates(bare)


class FixRenames(fixer_base.BaseFix):
    BM_compatible = True
    PATTERN = "|".join(build_pattern())

    order = "pre" # Pre-order tree traversal

    # Don't match the node if it's within another match
    def match(self, node):
        match = super(FixRenames, self).match
        results = match(node)
        if results:

# Path: py3kwarn2to3/fixer_util.py
# def Name(name, prefix=None):
#     """Return a NAME leaf"""
#     return Leaf(token.NAME, name, prefix=prefix)
# 
# def attr_chain(obj, attr):
#     """Follow an attribute chain.
# 
#     If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
#     use this to iterate over all objects in the chain. Iteration is
#     terminated by getattr(x, attr) is None.
# 
#     Args:
#         obj: the starting object
#         attr: the name of the chaining attribute
# 
#     Yields:
#         Each successive object in the chain.
#     """
#     next = getattr(obj, attr)
#     while next:
#         yield next
#         next = getattr(next, attr)


# Path: py3kwarn2to3/fixes/fix_renames.py
from .. import fixer_base
from ..fixer_util import Name, attr_chain

    for module, replace in MAPPING.items():
        for old_attr, new_attr in replace.items():
            LOOKUP[(module, old_attr)] = new_attr
            #bare.add(module)
            #bare.add(old_attr)
            #yield """
            #      import_name< 'import' (module=%r
            #          | dotted_as_names< any* module=%r any* >) >
            #      """ % (module, module)
            yield """
                  import_from< 'from' module_name=%r 'import'
                      ( attr_name=%r | import_as_name< attr_name=%r 'as' any >) >
                  """ % (module, old_attr, old_attr)
            yield """
                  power< module_name=%r trailer< '.' attr_name=%r > any* >
                  """ % (module, old_attr)
    #yield """bare_name=%s""" % alternates(bare)


class FixRenames(fixer_base.BaseFix):
    BM_compatible = True
    PATTERN = "|".join(build_pattern())

    order = "pre" # Pre-order tree traversal

    # Don't match the node if it's within another match
    def match(self, node):
        match = super(FixRenames, self).match
        results = match(node)
        if results:

            if any(match(obj) for obj in attr_chain(node, "parent")):