# Path: quilt/utils.py
# class _EqBase(object):
#     """ Helpers for defining __eq__ in Python < 3
# 
#     This class prevents inheriting the default Python 2 hashing
#     implementation, which would give different hashes for different but
#     equivalent objects. This avoids a DeprecationWarning and imitates how
#     Python 3 disables hashing whenever __eq__ is overridden.
#     """
#     __hash__ = None
# 
#     def __ne__(self, other):
#         """ Defers to __eq__, imitating Python 3 """
#         return not self.__eq__(other)


import weakref
from quilt.utils import _EqBase
# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:

# python-quilt - A Python implementation of the quilt patch system
#
# Copyright (C) 2012 - 2017 Björn Ricks <bjoern.ricks@gmail.com>
#
# See LICENSE comming with the source of python-quilt for details.




class MethodRef(_EqBase):

    """ May be compared for equality, but cannot be hashed, stored as a
        dictionary key, etc. """

    def __init__(self, func):
        if hasattr(func, "im_self"):
            # it's a method
            self.func = func.im_func
            self.obj = weakref.ref(func.im_self)
        elif hasattr(func, "__self__"):
            # it's a python >= 2.6 method
            self.func = func.__func__
            self.obj = weakref.ref(func.__self__)
        else:
            # it should be a function

# Path: quilt/utils.py
# class _EqBase(object):
#     """ Helpers for defining __eq__ in Python < 3
# 
#     This class prevents inheriting the default Python 2 hashing
#     implementation, which would give different hashes for different but
#     equivalent objects. This avoids a DeprecationWarning and imitates how
#     Python 3 disables hashing whenever __eq__ is overridden.
#     """
#     __hash__ = None
# 
#     def __ne__(self, other):
#         """ Defers to __eq__, imitating Python 3 """
#         return not self.__eq__(other)


# Path: quilt/signals.py
import weakref
from quilt.utils import _EqBase

# vim: fileencoding=utf-8 et sw=4 ts=4 tw=80:

# python-quilt - A Python implementation of the quilt patch system
#
# Copyright (C) 2012 - 2017 Björn Ricks <bjoern.ricks@gmail.com>
#
# See LICENSE comming with the source of python-quilt for details.




class MethodRef(_EqBase):

    """ May be compared for equality, but cannot be hashed, stored as a
        dictionary key, etc. """

    def __init__(self, func):
        if hasattr(func, "im_self"):
            # it's a method
            self.func = func.im_func
            self.obj = weakref.ref(func.im_self)
        elif hasattr(func, "__self__"):
            # it's a python >= 2.6 method
            self.func = func.__func__
            self.obj = weakref.ref(func.__self__)
        else:
            # it should be a function

            self.func = weakref.ref(func)