def getUtility(self, interface, name=''): """See IFiveUtilityRegistry interface """ c = self.queryUtility(interface, name) if c is not None: return c raise ComponentLookupError(interface, name)
def getLocalServices(context): """Returns the service manager that contains `context`. If `context` is a local service, returns the service manager that contains that service. If `context` is a service manager, returns `context`. Otherwise, raises ``ComponentLookupError('Services')`` Basically, this overrides the one in Zope X3 3.0 so that it uses acquisition instead of looking up __parent__. Monkey patching Zope 3 sucks, but X3 3.0 leaves us no choice, really. Fortunately, this will disappear in Zope 3.2, so we won't wet our pants about this now...""" # IMPORTANT # # This is not allowed to use any services to get its job done! while not (context is None or IServiceService.providedBy(context)): context = getattr(context, '__parent__', aq_parent(aq_inner(context))) if context is None: raise ComponentLookupError('Services') else: return context
def getUtility(self, interface, name=''): """See IUtilityService interface """ c = self.queryUtility(interface, name) if c is not None: return c raise ComponentLookupError(interface, name)
def serviceServiceAdapter(ob): """An adapter * -> IServiceService. This is registered in place of the one in Zope 3 so that we lookup using acquisition instead of ILocation. """ current = ob while True: if ISite.providedBy(current): return current.getSiteManager() current = getattr(current, '__parent__', aq_parent(aq_inner(current))) if current is None: raise ComponentLookupError("Could not adapt %r to" " IServiceService" % (ob, ))
def getLocalServices(context): """Returns the service manager that contains `context`. If `context` is a local service, returns the service manager that contains that service. If `context` is a service manager, returns `context`. Otherwise, raises ``ComponentLookupError('Services')`` XXX Basically, this overrides the one in Zope3 X3.0 so that it uses acquisition instead of looking up __parent__. """ # IMPORTANT # # This is not allowed to use any services to get its job done! while not (context is None or ISiteManager.providedBy(context)): context = aq_parent(aq_inner(context)) if context is None: raise ComponentLookupError('Services') else: return context
def getService(self, name): if name == 'dummy': return self.dummy_service raise ComponentLookupError(name)