本文整理匯總了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')