# Path: py3kwarn2to3/fixer_util.py
# def Name(name, prefix=None):
#     """Return a NAME leaf"""
#     return Leaf(token.NAME, name, prefix=prefix)
# 
# Path: py3kwarn2to3/fixer_util.py
# def find_binding(name, node, package=None):
#     """ Returns the node which binds variable name, otherwise None.
#         If optional argument package is supplied, only imports will
#         be returned.
#         See test cases for examples."""
#     for child in node.children:
#         ret = None
#         if child.type == syms.for_stmt:
#             if _find(name, child.children[1]):
#                 return child
#             n = find_binding(name, make_suite(child.children[-1]), package)
#             if n: ret = n
#         elif child.type in (syms.if_stmt, syms.while_stmt):
#             n = find_binding(name, make_suite(child.children[-1]), package)
#             if n: ret = n
#         elif child.type == syms.try_stmt:
#             n = find_binding(name, make_suite(child.children[2]), package)
#             if n:
#                 ret = n
#             else:
#                 for i, kid in enumerate(child.children[3:]):
#                     if kid.type == token.COLON and kid.value == ":":
#                         # i+3 is the colon, i+4 is the suite
#                         n = find_binding(name, make_suite(child.children[i+4]), package)
#                         if n: ret = n
#         elif child.type in _def_syms and child.children[1].value == name:
#             ret = child
#         elif _is_import_binding(child, name, package):
#             ret = child
#         elif child.type == syms.simple_stmt:
#             ret = find_binding(name, child, package)
#         elif child.type == syms.expr_stmt:
#             if _find(name, child.children[0]):
#                 ret = child
# 
#         if ret:
#             if not package:
#                 return ret
#             if is_import(ret):
#                 return ret
#     return None


from .. import fixer_base
from ..fixer_util import Name
from ..fixer_util import find_binding
"""Fixer that changes raw_input(...) into input(...)."""
# Author: Andre Roberge


class FixRawInput(fixer_base.BaseFix):

    BM_compatible = True
    PATTERN = """
              power< name='raw_input' trailer< '(' [any] ')' > any* >
              """

    def start_tree(self, tree, filename):
        super(FixRawInput, self).start_tree(tree, filename)

# Path: py3kwarn2to3/fixer_util.py
# def Name(name, prefix=None):
#     """Return a NAME leaf"""
#     return Leaf(token.NAME, name, prefix=prefix)
# 
# Path: py3kwarn2to3/fixer_util.py
# def find_binding(name, node, package=None):
#     """ Returns the node which binds variable name, otherwise None.
#         If optional argument package is supplied, only imports will
#         be returned.
#         See test cases for examples."""
#     for child in node.children:
#         ret = None
#         if child.type == syms.for_stmt:
#             if _find(name, child.children[1]):
#                 return child
#             n = find_binding(name, make_suite(child.children[-1]), package)
#             if n: ret = n
#         elif child.type in (syms.if_stmt, syms.while_stmt):
#             n = find_binding(name, make_suite(child.children[-1]), package)
#             if n: ret = n
#         elif child.type == syms.try_stmt:
#             n = find_binding(name, make_suite(child.children[2]), package)
#             if n:
#                 ret = n
#             else:
#                 for i, kid in enumerate(child.children[3:]):
#                     if kid.type == token.COLON and kid.value == ":":
#                         # i+3 is the colon, i+4 is the suite
#                         n = find_binding(name, make_suite(child.children[i+4]), package)
#                         if n: ret = n
#         elif child.type in _def_syms and child.children[1].value == name:
#             ret = child
#         elif _is_import_binding(child, name, package):
#             ret = child
#         elif child.type == syms.simple_stmt:
#             ret = find_binding(name, child, package)
#         elif child.type == syms.expr_stmt:
#             if _find(name, child.children[0]):
#                 ret = child
# 
#         if ret:
#             if not package:
#                 return ret
#             if is_import(ret):
#                 return ret
#     return None


# Path: py3kwarn2to3/fixes/fix_raw_input.py
from .. import fixer_base
from ..fixer_util import Name
from ..fixer_util import find_binding

"""Fixer that changes raw_input(...) into input(...)."""
# Author: Andre Roberge


class FixRawInput(fixer_base.BaseFix):

    BM_compatible = True
    PATTERN = """
              power< name='raw_input' trailer< '(' [any] ')' > any* >
              """

    def start_tree(self, tree, filename):
        super(FixRawInput, self).start_tree(tree, filename)

        self.skip = find_binding('raw_input', tree)