def test_globalsearchInterface_delegates_to_globalUtility(self): foo = Foo("global bob") bar = Bar("global") baz = Baz("global baz") gsm = zapi.getGlobalSiteManager() gsm.provideUtility(IInterface, bar) gsm.provideUtility(IBaz, baz) gsm.provideUtility(IInterface, foo, name="bob") self.assertEqual(searchInterface(None, search_string="bob"), [foo])
def _getDirectMarkersOf(self, base): """Get empty interfaces directly inheriting from the given one. """ results = [] interfaces = searchInterface(None, base=base) for interface in interfaces: # There are things registered with the interface service # that are not interfaces. Yay! if not IInterface.providedBy(interface): continue if base in interface.__bases__ and not interface.names(): results.append(interface) results.sort() return tuple(results)
def interfaceToName(context, interface): if interface is None: return "None" items = searchInterface(context, base=interface) ids = [("%s.%s" % (iface.__module__, iface.__name__)) for iface in items if iface == interface] if not ids: # Do not fail badly, instead resort to the standard # way of getting the interface name, cause not all interfaces # may be registered as utilities. return interface.__module__ + "." + interface.__name__ assert len(ids) == 1, "Ambiguous interface names: %s" % ids return ids[0]
def getDirectMarkersOf(self, base): """Returns empty interfaces directly inheriting from the given one""" results = [] interfaces = searchInterface(self.context, base=base) for interface in interfaces: # There are things registered with the site manager # that are not interfaces. Duh! if not IInterface.providedBy(interface): continue if base in interface.__bases__ and not interface.names(): results.append(interface) results.sort() return tuple(results)
def test_localInterfaceitems_filters_accordingly(self): bar = Bar("global") baz = Baz("global baz") foo = Foo("global bob") gsm = zapi.getGlobalSiteManager() gsm.provideUtility(IInterface, foo, name="bob") gsm.provideUtility(IInterface, bar) gsm.provideUtility(IBaz, baz) ifaces = searchInterface(None) self.assert_(len(ifaces), 2) for pair in [(foo), (bar)]: self.assert_(pair in ifaces) iface_utilities = gsm.getUtilitiesFor(IInterface) ifaces = [iface for (name, iface) in iface_utilities] self.assert_(len(ifaces), 2) for pair in [(foo), (bar)]: self.assert_(pair in ifaces) for pair in [(foo), (bar)]: self.assert_(pair in ifaces)