def getPortalTypesByInterfaces(context, allowedIfaces): """Returns a list of portal type names of which the types implement any of the given interfaces. Note that allowedIfaces are strings, not Interfaces.""" value = [] tool = getToolByName(context, 'archetype_tool') for data in tool.listRegisteredTypes(): kifaces = data['klass'].__implements__ # We now flatten the interfaces and get their unqualified names, # e.g. <Products.FooBar.interfaces.ISpam> becomes "ISpam" kifaces = [ str(iface.__name__) for iface in Implements.flattenInterfaces((kifaces, )) ] if [iface for iface in allowedIfaces if iface in kifaces]: value.append(data['portal_type']) return value
def testInterfacesForIClerk(self): '''test interface compliance for class IClerk''' for iface in Implements.flattenInterfaces(getattr(testInterfaces,'__implements__',[])): self.failUnless(verifyClass(iface, IClerk))
def testInterfacesForIMemberOfParliament(self): '''test interface compliance for class IMemberOfParliament''' for iface in Implements.flattenInterfaces(getattr(testInterfaces,'__implements__',[])): self.failUnless(verifyClass(iface, IMemberOfParliament))
def testInterfacesForIClerk(self): '''test interface compliance for class IClerk''' for iface in Implements.flattenInterfaces( getattr(testInterfaces, '__implements__', [])): self.failUnless(verifyClass(iface, IClerk))
def testInterfacesForIMemberOfParliament(self): '''test interface compliance for class IMemberOfParliament''' for iface in Implements.flattenInterfaces( getattr(testInterfaces, '__implements__', [])): self.failUnless(verifyClass(iface, IMemberOfParliament))