本文整理汇总了Python中twisted.python.components.getAdapterFactory函数的典型用法代码示例。如果您正苦于以下问题:Python getAdapterFactory函数的具体用法?Python getAdapterFactory怎么用?Python getAdapterFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getAdapterFactory函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _duplicateAdapterForClassOrInterfaceAllowed
def _duplicateAdapterForClassOrInterfaceAllowed(self, original):
"""
Verify that when C{components.ALLOW_DUPLICATES} is set to C{True}, new
adapter registrations for a particular from-type/interface and
to-interface pair replace older registrations.
"""
firstAdapter = lambda o: False
secondAdapter = lambda o: True
class TheInterface(Interface):
pass
components.registerAdapter(firstAdapter, original, TheInterface)
components.ALLOW_DUPLICATES = True
try:
components.registerAdapter(secondAdapter, original, TheInterface)
self.assertIs(
components.getAdapterFactory(original, TheInterface, None),
secondAdapter)
finally:
components.ALLOW_DUPLICATES = False
# It should be rejected again at this point
self.assertRaises(
ValueError,
components.registerAdapter,
firstAdapter, original, TheInterface)
self.assertIs(
components.getAdapterFactory(original, TheInterface, None),
secondAdapter)
示例2: _multipleInterfacesForClassOrInterface
def _multipleInterfacesForClassOrInterface(self, original):
"""
Verify that an adapter can be registered for multiple to-interfaces at a
time.
"""
adapter = lambda o: None
components.registerAdapter(adapter, original, ITest, ITest2)
self.assertIs(
components.getAdapterFactory(original, ITest, None), adapter)
self.assertIs(
components.getAdapterFactory(original, ITest2, None), adapter)
示例3: _multipleInterfacesForClassOrInterface
def _multipleInterfacesForClassOrInterface(self, original):
adapter = lambda o: None
class FirstInterface(Interface):
pass
class SecondInterface(Interface):
pass
components.registerAdapter(adapter, original, FirstInterface, SecondInterface)
self.assertIdentical(
components.getAdapterFactory(original, FirstInterface, None),
adapter)
self.assertIdentical(
components.getAdapterFactory(original, SecondInterface, None),
adapter)
示例4: _subclassAdapterRegistrationForClassOrInterface
def _subclassAdapterRegistrationForClassOrInterface(self, original):
firstAdapter = lambda o: True
secondAdapter = lambda o: False
class TheSubclass(original):
pass
class TheInterface(Interface):
pass
components.registerAdapter(firstAdapter, original, TheInterface)
components.registerAdapter(secondAdapter, TheSubclass, TheInterface)
self.assertIdentical(
components.getAdapterFactory(original, TheInterface, None),
firstAdapter)
self.assertIdentical(
components.getAdapterFactory(TheSubclass, TheInterface, None),
secondAdapter)
示例5: __conform__
def __conform__(self, interface, registry=None, default=None):
for providedInterface in self.provided:
if providedInterface.isOrExtends(interface):
return self.load()
if getAdapterFactory(providedInterface, interface, None) is not None:
return interface(self.load(), default)
return default
示例6: _registerAdapterForClassOrInterface
def _registerAdapterForClassOrInterface(self, original):
adapter = lambda o: None
class TheInterface(Interface):
pass
components.registerAdapter(adapter, original, TheInterface)
self.assertIdentical(
components.getAdapterFactory(original, TheInterface, None),
adapter)
示例7: _subclassAdapterRegistrationForClassOrInterface
def _subclassAdapterRegistrationForClassOrInterface(self, original):
"""
Verify that a new adapter can be registered for a particular
to-interface from a subclass of a type or interface which already has an
adapter registered to that interface and that the subclass adapter takes
precedence over the base class adapter.
"""
firstAdapter = lambda o: True
secondAdapter = lambda o: False
class TheSubclass(original):
pass
components.registerAdapter(firstAdapter, original, ITest)
components.registerAdapter(secondAdapter, TheSubclass, ITest)
self.assertIs(
components.getAdapterFactory(original, ITest, None),
firstAdapter)
self.assertIs(
components.getAdapterFactory(TheSubclass, ITest, None),
secondAdapter)
示例8: _registerAdapterForClassOrInterface
def _registerAdapterForClassOrInterface(self, original):
"""
Register an adapter with L{components.registerAdapter} for the given
class or interface and verify that the adapter can be looked up with
L{components.getAdapterFactory}.
"""
adapter = lambda o: None
components.registerAdapter(adapter, original, ITest)
self.assertIs(
components.getAdapterFactory(original, ITest, None),
adapter)
示例9: _duplicateAdapterForClassOrInterface
def _duplicateAdapterForClassOrInterface(self, original):
firstAdapter = lambda o: False
secondAdapter = lambda o: True
class TheInterface(Interface):
pass
components.registerAdapter(firstAdapter, original, TheInterface)
self.assertRaises(
ValueError,
components.registerAdapter,
secondAdapter, original, TheInterface)
# Make sure that the original adapter is still around as well
self.assertIdentical(
components.getAdapterFactory(original, TheInterface, None),
firstAdapter)
示例10: _duplicateAdapterForClassOrInterfaceAllowed
def _duplicateAdapterForClassOrInterfaceAllowed(self, original):
firstAdapter = lambda o: False
secondAdapter = lambda o: True
class TheInterface(Interface):
pass
components.registerAdapter(firstAdapter, original, TheInterface)
components.ALLOW_DUPLICATES = True
try:
components.registerAdapter(secondAdapter, original, TheInterface)
self.assertIdentical(
components.getAdapterFactory(original, TheInterface, None),
secondAdapter)
finally:
components.ALLOW_DUPLICATES = False
# It should be rejected again at this point
self.assertRaises(
ValueError,
components.registerAdapter,
firstAdapter, original, TheInterface)
self.assertIdentical(
components.getAdapterFactory(original, TheInterface, None),
secondAdapter)
示例11: __init__
def __init__(self, portal, config):
assert isinstance(portal, Portal)
assert isinstance(config, ConfigParser)
self.portal = portal
self.privateKeys = {
'ssh-rsa': keys.Key.fromFile(config.get("DEFAULT", "privateKeyLocation"))
}
self.publicKeys = {
'ssh-rsa': keys.Key.fromFile(config.get("DEFAULT", "publicKeyLocation"))
}
if components.getAdapterFactory(ConchUser, ISession, None) is None:
components.registerAdapter(Session, ConchUser, ISession)
示例12: _duplicateAdapterForClassOrInterface
def _duplicateAdapterForClassOrInterface(self, original):
"""
Verify that L{components.registerAdapter} raises L{ValueError} if the
from-type/interface and to-interface pair is not unique.
"""
firstAdapter = lambda o: False
secondAdapter = lambda o: True
components.registerAdapter(firstAdapter, original, ITest)
self.assertRaises(
ValueError,
components.registerAdapter,
secondAdapter, original, ITest)
# Make sure that the original adapter is still around as well
self.assertIs(
components.getAdapterFactory(original, ITest, None),
firstAdapter)
示例13: registerIfNotRegistered
def registerIfNotRegistered(adapter, from_, to):
if not components.getAdapterFactory(from_, to, None):
components.registerAdapter(adapter, from_, to)