# 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 Call(func_name, args=None, prefix=None):
#     """A function call"""
#     node = Node(syms.power, [func_name, ArgList(args)])
#     if prefix is not None:
#         node.prefix = prefix
#     return node
# 
# Path: py3kwarn2to3/fixer_util.py
# def Dot():
#     """A period (.) leaf"""
#     return Leaf(token.DOT, u".")


from .. import pytree
from .. import patcomp
from .. import fixer_base
from ..fixer_util import Name
from ..fixer_util import Call
from ..fixer_util import Dot
from .. import fixer_util
iter_exempt = fixer_util.consuming_calls | set(["iter"])


class FixDict(fixer_base.BaseFix):
    BM_compatible = True

    PATTERN = """
    power< head=any+
         trailer< '.' method=('iterkeys'|'iteritems'|'itervalues'|
                              'viewkeys'|'viewitems'|'viewvalues') >
         parens=trailer< '(' ')' >
         tail=any*
    >
    """

    def transform(self, node, results):
        head = results["head"]
        method = results["method"][0] # Extract node for method name
        tail = results["tail"]
        syms = self.syms
        method_name = method.value
        isiter = method_name.startswith(u"iter")
        isview = method_name.startswith(u"view")
        if isiter or isview:
            method_name = method_name[4:]
        assert method_name in (u"keys", u"items", u"values"), repr(method)
        head = [n.clone() for n in head]
        tail = [n.clone() for n in tail]
        special = not tail and self.in_special_context(node, isiter)
        args = head + [pytree.Node(syms.trailer,

# 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 Call(func_name, args=None, prefix=None):
#     """A function call"""
#     node = Node(syms.power, [func_name, ArgList(args)])
#     if prefix is not None:
#         node.prefix = prefix
#     return node
# 
# Path: py3kwarn2to3/fixer_util.py
# def Dot():
#     """A period (.) leaf"""
#     return Leaf(token.DOT, u".")


# Path: py3kwarn2to3/fixes/fix_dict.py
from .. import pytree
from .. import patcomp
from .. import fixer_base
from ..fixer_util import Name
from ..fixer_util import Call
from ..fixer_util import Dot
from .. import fixer_util

iter_exempt = fixer_util.consuming_calls | set(["iter"])


class FixDict(fixer_base.BaseFix):
    BM_compatible = True

    PATTERN = """
    power< head=any+
         trailer< '.' method=('iterkeys'|'iteritems'|'itervalues'|
                              'viewkeys'|'viewitems'|'viewvalues') >
         parens=trailer< '(' ')' >
         tail=any*
    >
    """

    def transform(self, node, results):
        head = results["head"]
        method = results["method"][0] # Extract node for method name
        tail = results["tail"]
        syms = self.syms
        method_name = method.value
        isiter = method_name.startswith(u"iter")
        isview = method_name.startswith(u"view")
        if isiter or isview:
            method_name = method_name[4:]
        assert method_name in (u"keys", u"items", u"values"), repr(method)
        head = [n.clone() for n in head]
        tail = [n.clone() for n in tail]
        special = not tail and self.in_special_context(node, isiter)
        args = head + [pytree.Node(syms.trailer,

                                   [Dot(),