# Path: infi/pyutils/functors/identity.py
# class _Identity(Functor):
#     def __call__(self, obj):
#     def __repr__(self):
# 
# Path: infi/pyutils/python_compat.py
# def get_underlying_function(f):
#     if _IS_BELOW_PYTHON_2_7 and (isinstance(f, classmethod) or isinstance(f, staticmethod)):
#         return _get_underlying_classmethod_function(f)
#     return f.__func__
# 
# Path: infi/pyutils/python_compat.py
# def create_bound_method(func, self):
#     return types.MethodType(func, self, type(self))


import functools
import platform
from .functors import Identity
from .python_compat import get_underlying_function
from .python_compat import create_bound_method

class MethodMap(object):
    def __init__(self, decorator=Identity):
        super(MethodMap, self).__init__()
        self._map = {}
        self._decorate = decorator
    def registering(self, key):
        return functools.partial(self.register, key)
    def register(self, key, value):
        self._map[key] = self._decorate(value)
        return value
    def __get__(self, instance, owner):
        return Binder(self._map, instance)

_NOTHING = object()

class Binder(object):
    def __init__(self, map, instance):
        super(Binder, self).__init__()
        self._map = map
        self._instance = instance
    def get(self, key, default=None):
        if key not in self._map:
            return default
        function = self._map[key]
        if isinstance(function, staticmethod):
            return get_underlying_function(function)
        if isinstance(function, classmethod):
            returned_self = self._instance

# Path: infi/pyutils/functors/identity.py
# class _Identity(Functor):
#     def __call__(self, obj):
#     def __repr__(self):
# 
# Path: infi/pyutils/python_compat.py
# def get_underlying_function(f):
#     if _IS_BELOW_PYTHON_2_7 and (isinstance(f, classmethod) or isinstance(f, staticmethod)):
#         return _get_underlying_classmethod_function(f)
#     return f.__func__
# 
# Path: infi/pyutils/python_compat.py
# def create_bound_method(func, self):
#     return types.MethodType(func, self, type(self))


# Path: infi/pyutils/method_map.py
import functools
import platform
from .functors import Identity
from .python_compat import get_underlying_function
from .python_compat import create_bound_method


class MethodMap(object):
    def __init__(self, decorator=Identity):
        super(MethodMap, self).__init__()
        self._map = {}
        self._decorate = decorator
    def registering(self, key):
        return functools.partial(self.register, key)
    def register(self, key, value):
        self._map[key] = self._decorate(value)
        return value
    def __get__(self, instance, owner):
        return Binder(self._map, instance)

_NOTHING = object()

class Binder(object):
    def __init__(self, map, instance):
        super(Binder, self).__init__()
        self._map = map
        self._instance = instance
    def get(self, key, default=None):
        if key not in self._map:
            return default
        function = self._map[key]
        if isinstance(function, staticmethod):
            return get_underlying_function(function)
        if isinstance(function, classmethod):
            returned_self = self._instance

            function = get_underlying_function(function)