def implements(cls, obj):
        """Returns 1 if obj implements interface cls, 0 otherwise."""
        #Check attributes.
        for attrib in cls.attributes():
            try:
                objattrib = getattr(obj, attrib)
            except AttributeError:
                return 0
            else:
                if callable(objattrib):
                    return 0
        #Check callables.
        for attrib in cls.callables():
            try:
                objattrib = getattr(obj, attrib)
            except AttributeError:
                return 0
            else:
                if not callable(objattrib):
                    return 0
        return 1
Returns 1 if obj implements interface cls, 0 otherwise.
recipes/Python/164901_Simplified_Interface_Framework/recipe-164901.py