• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python components.getAdapterFactory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python components.proxyForInterface函数代码示例发布时间:2022-05-27
下一篇:
Python components.backwardsCompatImplements函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap