# Path: supplement/tree.py
# class ReturnExtractor(ast.NodeVisitor):
#     def process(self, node):
#         self.result = []
#         self.generic_visit(node)
# 
#         return self.result
# 
#     def visit_Return(self, node):
#         if node.value:
#             self.result.append(node)
# 
# Path: supplement/common.py
# class Object(object):
#     def get_location(self):
#         raise NotImplementedError()
#         return None, None
# 
#     def get_names(self):
#         return set()
# 
#     def __contains__(self, name):
#         return name in self.get_names()
# 
#     def __getitem__(self, name):
#         return UnknownObject()
# 
#     def op_call(self, *args):
#         return UnknownObject()
# 
#     def op_getitem(self, idx):
#         return UnknownObject()
# 
#     def op_setitem(self, idx, value):
#         logging.getLogger(__name__).info('Try to set item on unknown object %s', self)
# 
#     def is_descriptor(self):
#         return False
# 
#     def get_assigned_attributes(self):
#         return {}
# 
#     def get_docstring(self):
#         return None
# 
#     def get_signature(self):
#         return None
# 
#     def get_scope(self):
#         return None
# 
#     def op_common_item(self):
#         return UnknownObject()
# 
# class UnknownObject(Object): pass
# 
# class GetObjectDelegate(object):
#     def get_names(self):
#         return self.get_object().get_names()
# 
#     def __getitem__(self, name):
#         return self.get_object()[name]
# 
#     def __contains__(self, name):
#         return name in self.get_object()
# 
#     def op_call(self, args):
#         return self.get_object().op_call(args)
# 
#     def op_getitem(self, idx):
#         return self.get_object().op_getitem(idx)
# 
#     def op_setitem(self, idx, value):
#         return self.get_object().op_setitem(idx, value)
# 
#     def get_location(self):
#         return self.get_object().get_location()
# 
#     def is_descriptor(self):
#         return self.get_object().is_descriptor()
# 
#     def get_assigned_attributes(self):
#         return self.get_object().get_assigned_attributes()
# 
#     def get_docstring(self):
#         return self.get_object().get_docstring()
# 
#     def get_signature(self):
#         return self.get_object().get_signature()
# 
#     def get_scope(self):
#         return self.get_object().get_scope()
# 
#     def op_common_item(self):
#         return self.get_object().op_common_item()
# 
# class Value(GetObjectDelegate):
#     def __init__(self, scope, value):
#         self.scope = scope
#         self.value = value
# 
#     def get_object(self):
#         try:
#             return self._object
#         except AttributeError:
#             pass
# 
#         self._object = self.scope.eval(self.value, False)
#         return self._object
# 
# class MethodObject(GetObjectDelegate):
#     def __init__(self, obj, func_obj):
#         self.object = obj
#         self.function = func_obj
# 
#     def get_scope(self):
#         return self.function.get_scope()
# 
#     def get_object(self):
#         return self.function
# 
#     def op_call(self, args):
#         return self.function.op_call([self.object] + args)
# 
#     def get_signature(self):
#         sig = self.function.get_signature()
#         if sig:
#             name, args, vararg, kwarg, defaults = sig
#             return name, args[1:], vararg, kwarg, defaults
#         else:
#             return None
# 
# def create_object_from_seq_item(scope, expr):
#     seq = scope.eval(expr, False)
#     return seq.op_common_item()
# 
# def get_indexes_for_target(target, result, idx):
#     if isinstance(target, (ast.Tuple, ast.List)):
#         idx.append(0)
#         for r in target.elts:
#             get_indexes_for_target(r, result, idx)
#         idx.pop()
# 
#     else:
#         result.append((target, idx[:]))
#         if idx:
#             idx[-1] += 1
# 
#     return result


import ast
import logging
from .tree import ReturnExtractor
from .common import Object, UnknownObject, GetObjectDelegate, Value, MethodObject, \
    create_object_from_seq_item, get_indexes_for_target
        from .objects import FakeInstanceObject
            from .objects import FakeInstanceObject
        from .objects import InstanceObject
        from .objects import InstanceObject
        if self._calling:
            raise RecursiveCallException(self)

        self._calling = True
        try:
            for rvalue in ReturnExtractor().process(self.node):
                try:
                    result = self.scope.get_call_scope(args).eval(rvalue, False)
                    if result and type(result) is not Object:
                        return result
                except RecursiveCallException, e:
                    if not e.is_called_by(self):
                        raise
        finally:
            self._calling = False

        return UnknownObject()

    def as_method_for(self, obj):
        return MethodObject(obj, self)

    def get_signature(self):
        self.scope.get_names()
        args = [self.scope.args[k] for k in sorted(self.scope.args.keys())]
        return (self.scope.name, args, self.scope.vararg, self.scope.kwarg, self.scope.defaults)

    def get_docstring(self):
        return ast.get_docstring(self.node)



# Path: supplement/tree.py
# class ReturnExtractor(ast.NodeVisitor):
#     def process(self, node):
#         self.result = []
#         self.generic_visit(node)
# 
#         return self.result
# 
#     def visit_Return(self, node):
#         if node.value:
#             self.result.append(node)
# 
# Path: supplement/common.py
# class Object(object):
#     def get_location(self):
#         raise NotImplementedError()
#         return None, None
# 
#     def get_names(self):
#         return set()
# 
#     def __contains__(self, name):
#         return name in self.get_names()
# 
#     def __getitem__(self, name):
#         return UnknownObject()
# 
#     def op_call(self, *args):
#         return UnknownObject()
# 
#     def op_getitem(self, idx):
#         return UnknownObject()
# 
#     def op_setitem(self, idx, value):
#         logging.getLogger(__name__).info('Try to set item on unknown object %s', self)
# 
#     def is_descriptor(self):
#         return False
# 
#     def get_assigned_attributes(self):
#         return {}
# 
#     def get_docstring(self):
#         return None
# 
#     def get_signature(self):
#         return None
# 
#     def get_scope(self):
#         return None
# 
#     def op_common_item(self):
#         return UnknownObject()
# 
# class UnknownObject(Object): pass
# 
# class GetObjectDelegate(object):
#     def get_names(self):
#         return self.get_object().get_names()
# 
#     def __getitem__(self, name):
#         return self.get_object()[name]
# 
#     def __contains__(self, name):
#         return name in self.get_object()
# 
#     def op_call(self, args):
#         return self.get_object().op_call(args)
# 
#     def op_getitem(self, idx):
#         return self.get_object().op_getitem(idx)
# 
#     def op_setitem(self, idx, value):
#         return self.get_object().op_setitem(idx, value)
# 
#     def get_location(self):
#         return self.get_object().get_location()
# 
#     def is_descriptor(self):
#         return self.get_object().is_descriptor()
# 
#     def get_assigned_attributes(self):
#         return self.get_object().get_assigned_attributes()
# 
#     def get_docstring(self):
#         return self.get_object().get_docstring()
# 
#     def get_signature(self):
#         return self.get_object().get_signature()
# 
#     def get_scope(self):
#         return self.get_object().get_scope()
# 
#     def op_common_item(self):
#         return self.get_object().op_common_item()
# 
# class Value(GetObjectDelegate):
#     def __init__(self, scope, value):
#         self.scope = scope
#         self.value = value
# 
#     def get_object(self):
#         try:
#             return self._object
#         except AttributeError:
#             pass
# 
#         self._object = self.scope.eval(self.value, False)
#         return self._object
# 
# class MethodObject(GetObjectDelegate):
#     def __init__(self, obj, func_obj):
#         self.object = obj
#         self.function = func_obj
# 
#     def get_scope(self):
#         return self.function.get_scope()
# 
#     def get_object(self):
#         return self.function
# 
#     def op_call(self, args):
#         return self.function.op_call([self.object] + args)
# 
#     def get_signature(self):
#         sig = self.function.get_signature()
#         if sig:
#             name, args, vararg, kwarg, defaults = sig
#             return name, args[1:], vararg, kwarg, defaults
#         else:
#             return None
# 
# def create_object_from_seq_item(scope, expr):
#     seq = scope.eval(expr, False)
#     return seq.op_common_item()
# 
# def get_indexes_for_target(target, result, idx):
#     if isinstance(target, (ast.Tuple, ast.List)):
#         idx.append(0)
#         for r in target.elts:
#             get_indexes_for_target(r, result, idx)
#         idx.pop()
# 
#     else:
#         result.append((target, idx[:]))
#         if idx:
#             idx[-1] += 1
# 
#     return result


# Path: supplement/names.py
import ast
import logging
from .tree import ReturnExtractor
from .common import Object, UnknownObject, GetObjectDelegate, Value, MethodObject, \
    create_object_from_seq_item, get_indexes_for_target
        from .objects import FakeInstanceObject
            from .objects import FakeInstanceObject
        from .objects import InstanceObject
        from .objects import InstanceObject

        if self._calling:
            raise RecursiveCallException(self)

        self._calling = True
        try:
            for rvalue in ReturnExtractor().process(self.node):
                try:
                    result = self.scope.get_call_scope(args).eval(rvalue, False)
                    if result and type(result) is not Object:
                        return result
                except RecursiveCallException, e:
                    if not e.is_called_by(self):
                        raise
        finally:
            self._calling = False

        return UnknownObject()

    def as_method_for(self, obj):
        return MethodObject(obj, self)

    def get_signature(self):
        self.scope.get_names()
        args = [self.scope.args[k] for k in sorted(self.scope.args.keys())]
        return (self.scope.name, args, self.scope.vararg, self.scope.kwarg, self.scope.defaults)

    def get_docstring(self):
        return ast.get_docstring(self.node)



class ClassName(NodeLocation, Object):