给定以下代码:
from zope.component import getGlobalSiteManager, adapts, subscribers
from zope.interface import Interface, implements
class A(object): pass
class B(object): pass
class C(B): pass
class AB(object):
implements(Interface)
adapts(A, B)
def __init__(self, a, b):
pass
class AC(object):
implements(Interface)
adapts(A, C)
def __init__(self, a, c):
pass
gsm = getGlobalSiteManager()
gsm.registerSubscriptionAdapter(AB)
gsm.registerSubscriptionAdapter(AC)
a = A()
c = C()
for adapter in subscribers([a, c], Interface):
print adapter
它产生的输出是:
<__main__.AB object at 0xb242290>
<__main__.AC object at 0xb2422d0>
为什么返回 AB 的实例?AB 只声明它适应 A 和 B。有没有一种方法可以实现只返回 AC 的行为?