after looking the zope.component API I realized that there is a function
to get all the factories for an interface but there is no such thing for
an object.

Usually an object provides one or more interfaces, and one interface can
have a lot of factories registered for it. Merging this information I
want the factories that implements *all* the interfaces an object

Basically I want to know how (e.g. what factory was used) an object was
created by introspection.

I wrote this small function:

def getFactoriesForObject(obj):
    factories = []
    ifaces = tuple(zope.interface.providedBy(obj))
    for iface in ifaces:
        for name, factory in zope.component.getFactoriesFor(iface):
            factoryIfaces = tuple(factory.getInterfaces())
            if ifaces == factoryIfaces and name not in factories:
    return factories

I works quite well for content types objects (the ones I'm interested
in) but I'm curious about why this function return two factories in many

>>> folder = zope.app.folder.folder.Folder()
>>> getFactoriesForObject(folder)

Is that because the <browser:addMenuItem> ZCML directive adding always a
factory for its class attribute?

I'm curious about what zope gurus thing about my function and if anybody
think if could be useful in zope.component.

Best regards


Zope3-users mailing list

Reply via email to