'Return a collection of factories in play or specified for a
hierarchy.
Traverses the entire inheritance graph of a cls and returns a
collection of instrumentation factories for those classes. Factories
are extracted from active ClassManagers, if available, otherwise
instrumentation_finders is consulted.'

def _collect_management_factories_for(self, cls):

    hierarchy = util.class_hierarchy(cls)
    factories = set()
    for member in hierarchy:
        manager = self.manager_of_class(member)
        if (manager is not None):
            factories.add(manager.factory)
        else:
            for finder in instrumentation_finders:
                factory = finder(member)
                if (factory is not None):
                    break
            else:
                factory = None
            factories.add(factory)
    factories.discard(None)
    return factories
