# Path: py3kwarn2to3/fixer_base.py
# class BaseFix(object):
# class ConditionalFix(BaseFix):
#     PATTERN = None  # Most subclasses should override with a string literal
#             PC = PatternCompiler()
#     def __init__(self, options, log):
#     def compile_pattern(self):
#     def set_filename(self, filename):
#     def match(self, node):
#     def transform(self, node, results):
#     def new_name(self, template=u"xxx_todo_changeme"):
#     def log_message(self, message):
#     def cannot_convert(self, node, reason=None):
#     def warning(self, node, reason):
#     def start_tree(self, tree, filename):
#     def finish_tree(self, tree, filename):
#     def start_tree(self, *args):
#     def should_skip(self, node):
# 
# Path: py3kwarn2to3/fixer_util.py
# def touch_import(package, name, node):
#     """ Works like `does_tree_import` but adds an import statement
#         if it was not imported. """
#     def is_import_stmt(node):
#         return (node.type == syms.simple_stmt and node.children and
#                 is_import(node.children[0]))
# 
#     root = find_root(node)
# 
#     if does_tree_import(package, name, root):
#         return
# 
#     # figure out where to insert the new import.  First try to find
#     # the first import and then skip to the last one.
#     insert_pos = offset = 0
#     for idx, node in enumerate(root.children):
#         if not is_import_stmt(node):
#             continue
#         for offset, node2 in enumerate(root.children[idx:]):
#             if not is_import_stmt(node2):
#                 break
#         insert_pos = idx + offset
#         break
# 
#     # if there are no imports where we can insert, find the docstring.
#     # if that also fails, we stick to the beginning of the file
#     if insert_pos == 0:
#         for idx, node in enumerate(root.children):
#             if (node.type == syms.simple_stmt and node.children and
#                node.children[0].type == token.STRING):
#                 insert_pos = idx + 1
#                 break
# 
#     if package is None:
#         import_ = Node(syms.import_name, [
#             Leaf(token.NAME, u"import"),
#             Leaf(token.NAME, name, prefix=u" ")
#         ])
#     else:
#         import_ = FromImport(package, [Leaf(token.NAME, name, prefix=u" ")])
# 
#     children = [import_, Newline()]
#     root.insert_child(insert_pos, Node(syms.simple_stmt, children))


from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import touch_import
# Licensed to PSF under a Contributor Agreement.

"""Fixer for reduce().

Makes sure reduce() is imported from the functools module if reduce is
used in that module.
"""



class FixReduce(fixer_base.BaseFix):

    BM_compatible = True
    order = "pre"

    PATTERN = """
    power< 'reduce'
        trailer< '('
            arglist< (
                (not(argument<any '=' any>) any ','
                 not(argument<any '=' any>) any) |
                (not(argument<any '=' any>) any ','
                 not(argument<any '=' any>) any ','
                 not(argument<any '=' any>) any)
            ) >
        ')' >
    >
    """

    def transform(self, node, results):

# Path: py3kwarn2to3/fixer_base.py
# class BaseFix(object):
# class ConditionalFix(BaseFix):
#     PATTERN = None  # Most subclasses should override with a string literal
#             PC = PatternCompiler()
#     def __init__(self, options, log):
#     def compile_pattern(self):
#     def set_filename(self, filename):
#     def match(self, node):
#     def transform(self, node, results):
#     def new_name(self, template=u"xxx_todo_changeme"):
#     def log_message(self, message):
#     def cannot_convert(self, node, reason=None):
#     def warning(self, node, reason):
#     def start_tree(self, tree, filename):
#     def finish_tree(self, tree, filename):
#     def start_tree(self, *args):
#     def should_skip(self, node):
# 
# Path: py3kwarn2to3/fixer_util.py
# def touch_import(package, name, node):
#     """ Works like `does_tree_import` but adds an import statement
#         if it was not imported. """
#     def is_import_stmt(node):
#         return (node.type == syms.simple_stmt and node.children and
#                 is_import(node.children[0]))
# 
#     root = find_root(node)
# 
#     if does_tree_import(package, name, root):
#         return
# 
#     # figure out where to insert the new import.  First try to find
#     # the first import and then skip to the last one.
#     insert_pos = offset = 0
#     for idx, node in enumerate(root.children):
#         if not is_import_stmt(node):
#             continue
#         for offset, node2 in enumerate(root.children[idx:]):
#             if not is_import_stmt(node2):
#                 break
#         insert_pos = idx + offset
#         break
# 
#     # if there are no imports where we can insert, find the docstring.
#     # if that also fails, we stick to the beginning of the file
#     if insert_pos == 0:
#         for idx, node in enumerate(root.children):
#             if (node.type == syms.simple_stmt and node.children and
#                node.children[0].type == token.STRING):
#                 insert_pos = idx + 1
#                 break
# 
#     if package is None:
#         import_ = Node(syms.import_name, [
#             Leaf(token.NAME, u"import"),
#             Leaf(token.NAME, name, prefix=u" ")
#         ])
#     else:
#         import_ = FromImport(package, [Leaf(token.NAME, name, prefix=u" ")])
# 
#     children = [import_, Newline()]
#     root.insert_child(insert_pos, Node(syms.simple_stmt, children))


# Path: py3kwarn2to3/fixes/fix_reduce.py
from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import touch_import

# Licensed to PSF under a Contributor Agreement.

"""Fixer for reduce().

Makes sure reduce() is imported from the functools module if reduce is
used in that module.
"""



class FixReduce(fixer_base.BaseFix):

    BM_compatible = True
    order = "pre"

    PATTERN = """
    power< 'reduce'
        trailer< '('
            arglist< (
                (not(argument<any '=' any>) any ','
                 not(argument<any '=' any>) any) |
                (not(argument<any '=' any>) any ','
                 not(argument<any '=' any>) any ','
                 not(argument<any '=' any>) any)
            ) >
        ')' >
    >
    """

    def transform(self, node, results):

        touch_import(u'functools', u'reduce', node)