当前位置: 首页>>代码示例>>Python>>正文


Python components.getAdapterFactory函数代码示例

本文整理汇总了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)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:29,代码来源:test_components.py

示例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)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:11,代码来源:test_components.py

示例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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:13,代码来源:test_components.py

示例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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:15,代码来源:test_components.py

示例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
开发者ID:perkinslr,项目名称:pypyjs-release,代码行数:7,代码来源:plugin.py

示例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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:8,代码来源:test_components.py

示例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)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:19,代码来源:test_components.py

示例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)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:11,代码来源:test_components.py

示例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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:14,代码来源:test_components.py

示例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)
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:24,代码来源:test_components.py

示例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)
开发者ID:cvangysel,项目名称:gitexd,代码行数:16,代码来源:ssh.py

示例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)
开发者ID:alfonsjose,项目名称:international-orders-app,代码行数:16,代码来源:test_components.py

示例13: registerIfNotRegistered

def registerIfNotRegistered(adapter, from_, to):
    if not components.getAdapterFactory(from_, to, None):
        components.registerAdapter(adapter, from_, to)
开发者ID:steder,项目名称:txtemplate,代码行数:3,代码来源:templates.py


注:本文中的twisted.python.components.getAdapterFactory函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。