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


Python interface.InterfaceClass方法代码示例

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


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

示例1: __cmp

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def __cmp(self, other):
        # Yes, I did mean to name this __cmp, rather than __cmp__.
        # It is a private method used by __lt__ and __gt__.
        # This is based on, and compatible with, InterfaceClass.
        # (The two must be mutually comparable to be able to work in e.g., BTrees.)
        # Instances of this class generally don't have a __module__ other than
        # `zope.interface.declarations`, whereas they *do* have a __name__ that is the
        # fully qualified name of the object they are representing.

        # Note, though, that equality and hashing are still identity based. This
        # accounts for things like nested objects that have the same name (typically
        # only in tests) and is consistent with pickling. As far as comparisons to InterfaceClass
        # goes, we'll never have equal name and module to those, so we're still consistent there.
        # Instances of this class are essentially intended to be unique and are
        # heavily cached (note how our __reduce__ handles this) so having identity
        # based hash and eq should also work.
        if other is None:
            return -1

        n1 = (self.__name__, self.__module__)
        n2 = (getattr(other, '__name__', ''), getattr(other,  '__module__', ''))

        # This spelling works under Python3, which doesn't have cmp().
        return (n1 > n2) - (n1 < n2) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:declarations.py

示例2: _normalizeargs

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def _normalizeargs(sequence, output = None):
    """Normalize declaration arguments

    Normalization arguments might contain Declarions, tuples, or single
    interfaces.

    Anything but individial interfaces or implements specs will be expanded.
    """
    if output is None:
        output = []

    cls = sequence.__class__
    if InterfaceClass in cls.__mro__ or Implements in cls.__mro__:
        output.append(sequence)
    else:
        for v in sequence:
            _normalizeargs(v, output)

    return output 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:declarations.py

示例3: test___hash___missing_required_attrs

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test___hash___missing_required_attrs(self):
        import warnings
        try:
            from warnings import catch_warnings
        except ImportError:  # Python 2.5
            return
        class Derived(self._getTargetClass()):
            def __init__(self):
                pass # Don't call base class.
        derived = Derived()
        with catch_warnings(record=True) as warned:
            warnings.simplefilter('always') # see LP #825249 
            self.assertEqual(hash(derived), 1)
            self.assertEqual(len(warned), 1)
            self.assertTrue(warned[0].category is UserWarning)
            self.assertEqual(str(warned[0].message),
                             'Hashing uninitialized InterfaceClass instance') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_interface.py

示例4: test_sort

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_sort(self):
        from zope.interface.declarations import implementedBy
        class A(object):
            pass
        class B(object):
            pass
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass('IFoo')

        self.assertEqual(implementedBy(A), implementedBy(A))
        self.assertEqual(hash(implementedBy(A)), hash(implementedBy(A)))
        self.assertTrue(implementedBy(A) < None)
        self.assertTrue(None > implementedBy(A))
        self.assertTrue(implementedBy(A) < implementedBy(B))
        self.assertTrue(implementedBy(A) > IFoo)
        self.assertTrue(implementedBy(A) <= implementedBy(B))
        self.assertTrue(implementedBy(A) >= IFoo)
        self.assertTrue(implementedBy(A) != IFoo) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_declarations.py

示例5: test_w_existing_Implements_w_bases

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_w_existing_Implements_w_bases(self):
        from zope.interface.declarations import Implements
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass('IFoo')
        IBar = InterfaceClass('IBar')
        IBaz = InterfaceClass('IBaz', IFoo)
        b_impl = Implements(IBaz)
        impl = Implements(IFoo)
        impl.declared = (IFoo,)
        class Base1(object):
            __implemented__ = b_impl
        class Base2(object):
            __implemented__ = b_impl
        class Foo(Base1, Base2):
            __implemented__ = impl
        impl.inherit = Foo
        self._callFUT(Foo, IBar)
        # Same spec, now different values
        self.assertTrue(Foo.__implemented__ is impl)
        self.assertEqual(impl.inherit, Foo)
        self.assertEqual(impl.declared, (IFoo, IBar,))
        self.assertEqual(impl.__bases__, (IFoo, IBar, b_impl)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_declarations.py

示例6: test_oldstyle_class

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_oldstyle_class(self):
        # TODO Py3 story
        from zope.interface.declarations import ClassProvides
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass('IFoo')
        class Foo:
            pass
        decorator = self._makeOne(IFoo)
        returned = decorator(Foo)
        self.assertTrue(returned is Foo)
        spec = Foo.__implemented__
        self.assertEqual(spec.__name__,
                         'zope.interface.tests.test_declarations.Foo')
        self.assertTrue(spec.inherit is Foo)
        self.assertTrue(Foo.__implemented__ is spec)
        self.assertTrue(isinstance(Foo.__providedBy__, ClassProvides))
        self.assertTrue(isinstance(Foo.__provides__, ClassProvides))
        self.assertEqual(Foo.__provides__, Foo.__providedBy__) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_declarations.py

示例7: test_newstyle_class

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_newstyle_class(self):
        from zope.interface.declarations import ClassProvides
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass('IFoo')
        class Foo(object):
            pass
        decorator = self._makeOne(IFoo)
        returned = decorator(Foo)
        self.assertTrue(returned is Foo)
        spec = Foo.__implemented__
        self.assertEqual(spec.__name__,
                         'zope.interface.tests.test_declarations.Foo')
        self.assertTrue(spec.inherit is Foo)
        self.assertTrue(Foo.__implemented__ is spec)
        self.assertTrue(isinstance(Foo.__providedBy__, ClassProvides))
        self.assertTrue(isinstance(Foo.__provides__, ClassProvides))
        self.assertEqual(Foo.__provides__, Foo.__providedBy__) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_declarations.py

示例8: test_called_once_from_class_w_bases

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_called_once_from_class_w_bases(self):
        from zope.interface.declarations import implements
        from zope.interface.declarations import implementsOnly
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass("IFoo")
        IBar = InterfaceClass("IBar")
        globs = {'implements': implements,
                 'implementsOnly': implementsOnly,
                 'IFoo': IFoo,
                 'IBar': IBar,
                }
        locs = {}
        CODE = "\n".join([
            'class Foo(object):',
            '    implements(IFoo)',
            'class Bar(Foo):'
            '    implementsOnly(IBar)',
            ])
        if self._run_generated_code(CODE, globs, locs):
            Bar = locs['Bar']
            spec = Bar.__implemented__
            self.assertEqual(list(spec), [IBar]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:24,代码来源:test_declarations.py

示例9: test_called_from_function

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_called_from_function(self):
        import warnings
        from zope.interface.declarations import implements
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass("IFoo")
        globs = {'implements': implements, 'IFoo': IFoo}
        locs = {}
        CODE = "\n".join([
            'def foo():',
            '    implements(IFoo)'
            ])
        if self._run_generated_code(CODE, globs, locs, False):
            foo = locs['foo']
            with warnings.catch_warnings(record=True) as log:
                warnings.resetwarnings()
                self.assertRaises(TypeError, foo)
                self.assertEqual(len(log), 0) # no longer warn 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_declarations.py

示例10: test_w_classless_object

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_w_classless_object(self):
        from zope.interface.declarations import ProvidesClass
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass("IFoo")
        the_dict = {}
        class Foo(object):
            def __getattribute__(self, name):
                # Emulate object w/o any class
                if name == '__class__':
                    return None
                try:
                    return the_dict[name]
                except KeyError:
                    raise AttributeError(name)
            def __setattr__(self, name, value):
                the_dict[name] = value
        obj = Foo()
        self._callFUT(obj, IFoo)
        self.assertTrue(isinstance(the_dict['__provides__'], ProvidesClass))
        self.assertEqual(list(the_dict['__provides__']), [IFoo]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_declarations.py

示例11: test_called_twice_from_class

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_called_twice_from_class(self):
        import warnings
        from zope.interface.declarations import classProvides
        from zope.interface.interface import InterfaceClass
        from zope.interface._compat import PYTHON3
        IFoo = InterfaceClass("IFoo")
        IBar = InterfaceClass("IBar")
        globs = {'classProvides': classProvides, 'IFoo': IFoo, 'IBar': IBar}
        locs = {}
        CODE = "\n".join([
            'class Foo(object):',
            '    classProvides(IFoo)',
            '    classProvides(IBar)',
            ])
        with warnings.catch_warnings(record=True) as log:
            warnings.resetwarnings()
            try:
                exec(CODE, globs, locs)
            except TypeError:
                if not PYTHON3:
                    self.assertEqual(len(log), 0) # no longer warn
            else:
                self.fail("Didn't raise TypeError") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_declarations.py

示例12: test_called_once_from_class

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_called_once_from_class(self):
        from zope.interface.declarations import classProvides
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass("IFoo")
        globs = {'classProvides': classProvides, 'IFoo': IFoo}
        locs = {}
        CODE = "\n".join([
            'class Foo(object):',
            '    classProvides(IFoo)',
            ])
        if self._run_generated_code(CODE, globs, locs):
            Foo = locs['Foo']
            spec = Foo.__providedBy__
            self.assertEqual(list(spec), [IFoo])

# Test _classProvides_advice through classProvides, its only caller. 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_declarations.py

示例13: test_called_from_class

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_called_from_class(self):
        from zope.interface.declarations import moduleProvides
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass("IFoo")
        globs = {'__name__': 'zope.interface.tests.foo',
                 'moduleProvides': moduleProvides, 'IFoo': IFoo}
        locs = {}
        CODE = "\n".join([
            'class Foo(object):',
            '    moduleProvides(IFoo)',
            ])
        try:
            exec(CODE, globs, locs)
        except TypeError:
            pass
        else:
            assert False, 'TypeError not raised' 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_declarations.py

示例14: test_called_twice_from_module_scope

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_called_twice_from_module_scope(self):
        from zope.interface.declarations import moduleProvides
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass("IFoo")
        globs = {'__name__': 'zope.interface.tests.foo',
                 'moduleProvides': moduleProvides, 'IFoo': IFoo}
        locs = {}
        CODE = "\n".join([
            'moduleProvides(IFoo)',
            'moduleProvides(IFoo)',
            ])
        try:
            exec(CODE, globs)
        except TypeError:
            pass
        else:
            assert False, 'TypeError not raised' 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_declarations.py

示例15: test_remove_extendor

# 需要导入模块: from zope.interface import interface [as 别名]
# 或者: from zope.interface.interface import InterfaceClass [as 别名]
def test_remove_extendor(self):
        from zope.interface import Interface
        from zope.interface.interface import InterfaceClass
        IFoo = InterfaceClass('IFoo')
        IBar = InterfaceClass('IBar', IFoo)
        registry = self._makeRegistry(IFoo, IBar)
        alb = self._makeOne(registry)
        alb.remove_extendor(IFoo)
        self.assertEqual(sorted(alb._extendors.keys()),
                         sorted([IFoo, IBar, Interface]))
        self.assertEqual(alb._extendors[IFoo], [])
        self.assertEqual(alb._extendors[IBar], [IBar])
        self.assertEqual(sorted(alb._extendors[Interface]),
                         sorted([IBar]))

    # test '_subscribe' via its callers, '_uncached_lookup', etc. 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_adapter.py


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