'Return a dictionary of events on this object.
Args:
obj (Object): the connected object.
Returns:
A dictionary of the object\'s events.
Note:
Events would define what the object can have as
callbacks.  Note, however, that chained callbacks will not
appear in events and are handled separately.'

def get_events(self, obj):

    events = {}
    all_events = self.ndb.events
    classes = Queue()
    classes.put(type(obj))
    invalid = []
    while (not classes.empty()):
        typeclass = classes.get()
        typeclass_name = ((typeclass.__module__ + '.') + typeclass.__name__)
        for (key, etype) in all_events.get(typeclass_name, {}).items():
            if (key in invalid):
                continue
            if (etype[0] is None):
                invalid.append(key)
                continue
            if (key not in events):
                events[key] = etype
        for parent in typeclass.__bases__:
            classes.put(parent)
    return events
