示例#1
0
 def getUtility(self, interface, name=''):
     """See IFiveUtilityRegistry interface
     """
     c = self.queryUtility(interface, name)
     if c is not None:
         return c
     raise ComponentLookupError(interface, name)
示例#2
0
文件: monkey.py 项目: bendavis78/zope
    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
示例#3
0
 def getUtility(self, interface, name=''):
     """See IUtilityService interface
     """
     c = self.queryUtility(interface, name)
     if c is not None:
         return c
     raise ComponentLookupError(interface, name)
示例#4
0
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, ))
示例#5
0
文件: monkey.py 项目: bendavis78/zope
    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
示例#6
0
 def getService(self, name):
     if name == 'dummy':
         return self.dummy_service
     raise ComponentLookupError(name)