コード例 #1
0
ファイル: interface.py プロジェクト: katerberg-zz/blockBox
    def providedBy(self, ob):
        """Is the interface implemented by an object

		  >>> from lib.zope.interface import *
		  >>> class I1(Interface):
		  ...	 pass
		  >>> class C(object):
		  ...	 implements(I1)
		  >>> c = C()
		  >>> class X(object):
		  ...	 pass
		  >>> x = X()
		  >>> I1.providedBy(x)
		  False
		  >>> I1.providedBy(C)
		  False
		  >>> I1.providedBy(c)
		  True
		  >>> directlyProvides(x, I1)
		  >>> I1.providedBy(x)
		  True
		  >>> directlyProvides(C, I1)
		  >>> I1.providedBy(C)
		  True

		"""
        spec = providedBy(ob)
        return self in spec._implied
コード例 #2
0
    def addComponent(self, component, ignoreClass=0):
        """
		Add a component to me, for all appropriate interfaces.

		In order to determine which interfaces are appropriate, the component's
		provided interfaces will be scanned.

		If the argument 'ignoreClass' is True, then all interfaces are
		considered appropriate.

		Otherwise, an 'appropriate' interface is one for which its class has
		been registered as an adapter for my class according to the rules of
		getComponent.

		@return: the list of appropriate interfaces
		"""
        for iface in declarations.providedBy(component):
            if (ignoreClass or (self.locateAdapterClass(
                    self.__class__, iface, None) == component.__class__)):
                self._adapterCache[reflect.qual(iface)] = component
コード例 #3
0
ファイル: components.py プロジェクト: TheArchives/blockBox
	def addComponent(self, component, ignoreClass=0):
		"""
		Add a component to me, for all appropriate interfaces.

		In order to determine which interfaces are appropriate, the component's
		provided interfaces will be scanned.

		If the argument 'ignoreClass' is True, then all interfaces are
		considered appropriate.

		Otherwise, an 'appropriate' interface is one for which its class has
		been registered as an adapter for my class according to the rules of
		getComponent.

		@return: the list of appropriate interfaces
		"""
		for iface in declarations.providedBy(component):
			if (ignoreClass or
				(self.locateAdapterClass(self.__class__, iface, None)
				 == component.__class__)):
				self._adapterCache[reflect.qual(iface)] = component
コード例 #4
0
def _hook(iface, ob, lookup=globalRegistry.lookup1):
    factory = lookup(declarations.providedBy(ob), iface)
    if factory is None:
        return None
    else:
        return factory(ob)
コード例 #5
0
ファイル: components.py プロジェクト: TheArchives/blockBox
def _hook(iface, ob, lookup=globalRegistry.lookup1):
	factory = lookup(declarations.providedBy(ob), iface)
	if factory is None:
		return None
	else:
		return factory(ob)