# 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 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
# 
# def Name(name, prefix=None):
#     """Return a NAME leaf"""
#     return Leaf(token.NAME, name, prefix=prefix)
# 
# def String(string, prefix=None):
#     """A string leaf"""
#     return Leaf(token.STRING, string, prefix=prefix)
# 
# 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))


import collections
import sys
from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import Call, Name, String, touch_import
        obj = results["obj"]
        args = [obj.clone(), String(u", "), String(u"'__call__'")]
        return Call(Name(u"hasattr"), args, prefix=node.prefix)

    @invocation("operator.mul(%s)")
    def _repeat(self, node, results):
        return self._handle_rename(node, results, u"mul")

    @invocation("operator.imul(%s)")
    def _irepeat(self, node, results):
        return self._handle_rename(node, results, u"imul")

    @invocation("isinstance(%s, collections.Sequence)")
    def _isSequenceType(self, node, results):
        return self._handle_type2abc(node, results, u"collections", u"Sequence")

    @invocation("isinstance(%s, collections.Mapping)")
    def _isMappingType(self, node, results):
        return self._handle_type2abc(node, results, u"collections", u"Mapping")

    @invocation("isinstance(%s, numbers.Number)")
    def _isNumberType(self, node, results):
        return self._handle_type2abc(node, results, u"numbers", u"Number")

    def _handle_rename(self, node, results, name):
        method = results["method"][0]
        method.value = name
        method.changed()

    def _handle_type2abc(self, node, results, module, abc):

# 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 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
# 
# def Name(name, prefix=None):
#     """Return a NAME leaf"""
#     return Leaf(token.NAME, name, prefix=prefix)
# 
# def String(string, prefix=None):
#     """A string leaf"""
#     return Leaf(token.STRING, string, prefix=prefix)
# 
# 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_operator.py
import collections
import sys
from py3kwarn2to3 import fixer_base
from py3kwarn2to3.fixer_util import Call, Name, String, touch_import

        obj = results["obj"]
        args = [obj.clone(), String(u", "), String(u"'__call__'")]
        return Call(Name(u"hasattr"), args, prefix=node.prefix)

    @invocation("operator.mul(%s)")
    def _repeat(self, node, results):
        return self._handle_rename(node, results, u"mul")

    @invocation("operator.imul(%s)")
    def _irepeat(self, node, results):
        return self._handle_rename(node, results, u"imul")

    @invocation("isinstance(%s, collections.Sequence)")
    def _isSequenceType(self, node, results):
        return self._handle_type2abc(node, results, u"collections", u"Sequence")

    @invocation("isinstance(%s, collections.Mapping)")
    def _isMappingType(self, node, results):
        return self._handle_type2abc(node, results, u"collections", u"Mapping")

    @invocation("isinstance(%s, numbers.Number)")
    def _isNumberType(self, node, results):
        return self._handle_type2abc(node, results, u"numbers", u"Number")

    def _handle_rename(self, node, results, name):
        method = results["method"][0]
        method.value = name
        method.changed()

    def _handle_type2abc(self, node, results, module, abc):

        touch_import(None, module, node)