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


Python interface.Method方法代码示例

本文整理汇总了Python中zope.interface.interface.Method方法的典型用法代码示例。如果您正苦于以下问题:Python interface.Method方法的具体用法?Python interface.Method怎么用?Python interface.Method使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zope.interface.interface的用法示例。


在下文中一共展示了interface.Method方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_namesAndDescriptions_simple

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_namesAndDescriptions_simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface
        

        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        name_values = sorted(ISimple.namesAndDescriptions())

        self.assertEqual(len(name_values), 2)
        self.assertEqual(name_values[0][0], 'attr')
        self.assertTrue(isinstance(name_values[0][1], Attribute))
        self.assertEqual(name_values[0][1].__name__, 'attr')
        self.assertEqual(name_values[0][1].__doc__, 'My attr')
        self.assertEqual(name_values[1][0], 'method')
        self.assertTrue(isinstance(name_values[1][1], Method))
        self.assertEqual(name_values[1][1].__name__, 'method')
        self.assertEqual(name_values[1][1].__doc__, 'My method') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_interface.py

示例2: test_getDescriptionFor_simple

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_getDescriptionFor_simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface
        

        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        a_desc = ISimple.getDescriptionFor('attr')
        self.assertTrue(isinstance(a_desc, Attribute))
        self.assertEqual(a_desc.__name__, 'attr')
        self.assertEqual(a_desc.__doc__, 'My attr')

        m_desc = ISimple.getDescriptionFor('method')
        self.assertTrue(isinstance(m_desc, Method))
        self.assertEqual(m_desc.__name__, 'method')
        self.assertEqual(m_desc.__doc__, 'My method') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_interface.py

示例3: test___getitem__simple

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test___getitem__simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface
        

        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        a_desc = ISimple['attr']
        self.assertTrue(isinstance(a_desc, Attribute))
        self.assertEqual(a_desc.__name__, 'attr')
        self.assertEqual(a_desc.__doc__, 'My attr')

        m_desc = ISimple['method']
        self.assertTrue(isinstance(m_desc, Method))
        self.assertEqual(m_desc.__name__, 'method')
        self.assertEqual(m_desc.__doc__, 'My method') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_interface.py

示例4: test_w_callable_non_func_method

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_w_callable_non_func_method(self):
        from zope.interface.interface import Method
        from zope.interface import Interface
        from zope.interface import implementer

        class QuasiMethod(Method):
            def __call__(self, *args, **kw):
                pass

        class QuasiCallable(object):
            def __call__(self, *args, **kw):
                pass

        class ICurrent(Interface):
            attr = QuasiMethod('This is callable')

        @implementer(ICurrent)
        class Current:
            attr = QuasiCallable()

        self._callFUT(ICurrent, Current) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_verify.py

示例5: test_namesAndDescriptions_simple

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_namesAndDescriptions_simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface


        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        name_values = sorted(ISimple.namesAndDescriptions())

        self.assertEqual(len(name_values), 2)
        self.assertEqual(name_values[0][0], 'attr')
        self.assertTrue(isinstance(name_values[0][1], Attribute))
        self.assertEqual(name_values[0][1].__name__, 'attr')
        self.assertEqual(name_values[0][1].__doc__, 'My attr')
        self.assertEqual(name_values[1][0], 'method')
        self.assertTrue(isinstance(name_values[1][1], Method))
        self.assertEqual(name_values[1][1].__name__, 'method')
        self.assertEqual(name_values[1][1].__doc__, 'My method') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:25,代码来源:test_interface.py

示例6: test_getDescriptionFor_simple

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_getDescriptionFor_simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface


        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        a_desc = ISimple.getDescriptionFor('attr')
        self.assertTrue(isinstance(a_desc, Attribute))
        self.assertEqual(a_desc.__name__, 'attr')
        self.assertEqual(a_desc.__doc__, 'My attr')

        m_desc = ISimple.getDescriptionFor('method')
        self.assertTrue(isinstance(m_desc, Method))
        self.assertEqual(m_desc.__name__, 'method')
        self.assertEqual(m_desc.__doc__, 'My method') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_interface.py

示例7: test___getitem__simple

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test___getitem__simple(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface


        class ISimple(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        a_desc = ISimple['attr']
        self.assertTrue(isinstance(a_desc, Attribute))
        self.assertEqual(a_desc.__name__, 'attr')
        self.assertEqual(a_desc.__doc__, 'My attr')

        m_desc = ISimple['method']
        self.assertTrue(isinstance(m_desc, Method))
        self.assertEqual(m_desc.__name__, 'method')
        self.assertEqual(m_desc.__doc__, 'My method') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_interface.py

示例8: test_w_callable_non_func_method

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_w_callable_non_func_method(self):
        from zope.interface.interface import Method
        from zope.interface import Interface
        from zope.interface import implementer

        class QuasiMethod(Method):
            def __call__(self, *args, **kw):
                raise NotImplementedError()

        class QuasiCallable(object):
            def __call__(self, *args, **kw):
                raise NotImplementedError()

        class ICurrent(Interface):
            attr = QuasiMethod('This is callable')

        @implementer(ICurrent)
        class Current:
            attr = QuasiCallable()

        self._callFUT(ICurrent, Current) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_verify.py

示例9: test_getDescriptionFor_derived

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_getDescriptionFor_derived(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface
        

        class IBase(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        class IDerived(IBase):
            attr2 = Attribute(u'My attr2')

            def method():
                "My method, overridden"

            def method2():
                "My method2"

        a_desc = IDerived.getDescriptionFor('attr')
        self.assertTrue(isinstance(a_desc, Attribute))
        self.assertEqual(a_desc.__name__, 'attr')
        self.assertEqual(a_desc.__doc__, 'My attr')

        m_desc = IDerived.getDescriptionFor('method')
        self.assertTrue(isinstance(m_desc, Method))
        self.assertEqual(m_desc.__name__, 'method')
        self.assertEqual(m_desc.__doc__, 'My method, overridden')

        a2_desc = IDerived.getDescriptionFor('attr2')
        self.assertTrue(isinstance(a2_desc, Attribute))
        self.assertEqual(a2_desc.__name__, 'attr2')
        self.assertEqual(a2_desc.__doc__, 'My attr2')

        m2_desc = IDerived.getDescriptionFor('method2')
        self.assertTrue(isinstance(m2_desc, Method))
        self.assertEqual(m2_desc.__name__, 'method2')
        self.assertEqual(m2_desc.__doc__, 'My method2') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:42,代码来源:test_interface.py

示例10: _getTargetClass

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def _getTargetClass(self):
        from zope.interface.interface import Method
        return Method 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:5,代码来源:test_interface.py

示例11: test_getDescriptionFor_derived

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_getDescriptionFor_derived(self):
        from zope.interface import Attribute
        from zope.interface.interface import Method
        from zope.interface import Interface


        class IBase(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        class IDerived(IBase):
            attr2 = Attribute(u'My attr2')

            def method():
                "My method, overridden"

            def method2():
                "My method2"

        a_desc = IDerived.getDescriptionFor('attr')
        self.assertTrue(isinstance(a_desc, Attribute))
        self.assertEqual(a_desc.__name__, 'attr')
        self.assertEqual(a_desc.__doc__, 'My attr')

        m_desc = IDerived.getDescriptionFor('method')
        self.assertTrue(isinstance(m_desc, Method))
        self.assertEqual(m_desc.__name__, 'method')
        self.assertEqual(m_desc.__doc__, 'My method, overridden')

        a2_desc = IDerived.getDescriptionFor('attr2')
        self.assertTrue(isinstance(a2_desc, Attribute))
        self.assertEqual(a2_desc.__name__, 'attr2')
        self.assertEqual(a2_desc.__doc__, 'My attr2')

        m2_desc = IDerived.getDescriptionFor('method2')
        self.assertTrue(isinstance(m2_desc, Method))
        self.assertEqual(m2_desc.__name__, 'method2')
        self.assertEqual(m2_desc.__doc__, 'My method2') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:42,代码来源:test_interface.py

示例12: test_namesAndDescriptions_derived

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_namesAndDescriptions_derived(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        from zope.interface.interface import Method
        

        class IBase(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        class IDerived(IBase):
            attr2 = Attribute(u'My attr2')

            def method():
                "My method, overridden"

            def method2():
                "My method2"

        name_values = sorted(IDerived.namesAndDescriptions())

        self.assertEqual(len(name_values), 3)
        self.assertEqual(name_values[0][0], 'attr2')
        self.assertTrue(isinstance(name_values[0][1], Attribute))
        self.assertEqual(name_values[0][1].__name__, 'attr2')
        self.assertEqual(name_values[0][1].__doc__, 'My attr2')
        self.assertEqual(name_values[1][0], 'method')
        self.assertTrue(isinstance(name_values[1][1], Method))
        self.assertEqual(name_values[1][1].__name__, 'method')
        self.assertEqual(name_values[1][1].__doc__, 'My method, overridden')
        self.assertEqual(name_values[2][0], 'method2')
        self.assertTrue(isinstance(name_values[2][1], Method))
        self.assertEqual(name_values[2][1].__name__, 'method2')
        self.assertEqual(name_values[2][1].__doc__, 'My method2')

        name_values = sorted(IDerived.namesAndDescriptions(all=True))

        self.assertEqual(len(name_values), 4)
        self.assertEqual(name_values[0][0], 'attr')
        self.assertTrue(isinstance(name_values[0][1], Attribute))
        self.assertEqual(name_values[0][1].__name__, 'attr')
        self.assertEqual(name_values[0][1].__doc__, 'My attr')
        self.assertEqual(name_values[1][0], 'attr2')
        self.assertTrue(isinstance(name_values[1][1], Attribute))
        self.assertEqual(name_values[1][1].__name__, 'attr2')
        self.assertEqual(name_values[1][1].__doc__, 'My attr2')
        self.assertEqual(name_values[2][0], 'method')
        self.assertTrue(isinstance(name_values[2][1], Method))
        self.assertEqual(name_values[2][1].__name__, 'method')
        self.assertEqual(name_values[2][1].__doc__, 'My method, overridden')
        self.assertEqual(name_values[3][0], 'method2')
        self.assertTrue(isinstance(name_values[3][1], Method))
        self.assertEqual(name_values[3][1].__name__, 'method2')
        self.assertEqual(name_values[3][1].__doc__, 'My method2') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:58,代码来源:test_interface.py

示例13: interface_decorator

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def interface_decorator(decorator_name, interface, method_decorator,
                        *args, **kwargs):
    """
    Create a class decorator which applies a method decorator to each method of
    an interface.

    Sample Usage::
        class IDummy(Interface):
            def return_method():
                pass

        @implementer(IDummy)
        class Dummy():
            def return_method(self):
                pass

        def method_decorator(method_name, original_name):
            def _run_with_logging(self):
                Log()
            return _run_with_logging

        logged_dummy = interface_decorator("decorator", IDummy,
                                           method_decorator, _dummy=Dummy())

    :param str decorator_name: A human-meaningful name for the class decorator
        that will be returned by this function.
    :param zope.interface.InterfaceClass interface: The interface from which to
        take methods.
    :param method_decorator: A callable which will decorate a method from the
        interface.  It will be called with the name of the method as the first
        argument and any additional positional and keyword arguments passed to
        ``_interface_decorator``.

    :return: The class decorator.
    """
    for method_name in interface.names():
        if not isinstance(interface[method_name], Method):
            raise TypeError(
                "{} does not support interfaces with non-methods "
                "attributes".format(decorator_name)
            )

    def class_decorator(cls):
        for name in interface.names():
            setattr(cls, name, method_decorator(name, *args, **kwargs))
        return cls
    return class_decorator 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:49,代码来源:_interface.py

示例14: test_namesAndDescriptions_derived

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import Method [as 别名]
def test_namesAndDescriptions_derived(self):
        from zope.interface import Attribute
        from zope.interface import Interface
        from zope.interface.interface import Method


        class IBase(Interface):
            attr = Attribute(u'My attr')

            def method():
                "My method"

        class IDerived(IBase):
            attr2 = Attribute(u'My attr2')

            def method():
                "My method, overridden"

            def method2():
                "My method2"

        name_values = sorted(IDerived.namesAndDescriptions())

        self.assertEqual(len(name_values), 3)
        self.assertEqual(name_values[0][0], 'attr2')
        self.assertTrue(isinstance(name_values[0][1], Attribute))
        self.assertEqual(name_values[0][1].__name__, 'attr2')
        self.assertEqual(name_values[0][1].__doc__, 'My attr2')
        self.assertEqual(name_values[1][0], 'method')
        self.assertTrue(isinstance(name_values[1][1], Method))
        self.assertEqual(name_values[1][1].__name__, 'method')
        self.assertEqual(name_values[1][1].__doc__, 'My method, overridden')
        self.assertEqual(name_values[2][0], 'method2')
        self.assertTrue(isinstance(name_values[2][1], Method))
        self.assertEqual(name_values[2][1].__name__, 'method2')
        self.assertEqual(name_values[2][1].__doc__, 'My method2')

        name_values = sorted(IDerived.namesAndDescriptions(all=True))

        self.assertEqual(len(name_values), 4)
        self.assertEqual(name_values[0][0], 'attr')
        self.assertTrue(isinstance(name_values[0][1], Attribute))
        self.assertEqual(name_values[0][1].__name__, 'attr')
        self.assertEqual(name_values[0][1].__doc__, 'My attr')
        self.assertEqual(name_values[1][0], 'attr2')
        self.assertTrue(isinstance(name_values[1][1], Attribute))
        self.assertEqual(name_values[1][1].__name__, 'attr2')
        self.assertEqual(name_values[1][1].__doc__, 'My attr2')
        self.assertEqual(name_values[2][0], 'method')
        self.assertTrue(isinstance(name_values[2][1], Method))
        self.assertEqual(name_values[2][1].__name__, 'method')
        self.assertEqual(name_values[2][1].__doc__, 'My method, overridden')
        self.assertEqual(name_values[3][0], 'method2')
        self.assertTrue(isinstance(name_values[3][1], Method))
        self.assertEqual(name_values[3][1].__name__, 'method2')
        self.assertEqual(name_values[3][1].__doc__, 'My method2') 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:58,代码来源:test_interface.py


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