本文整理汇总了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')
示例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')
示例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')
示例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)
示例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')
示例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')
示例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')
示例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)
示例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')
示例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
示例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')
示例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')
示例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
示例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')