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


Python interface.implements方法代码示例

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


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

示例1: test_classImplement_on_deeply_nested_classes

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def test_classImplement_on_deeply_nested_classes():
    """This test is in response to a bug found, which is why it's a bit
    contrived

    >>> from zope.interface import *
    >>> class B1(object):
    ...     pass
    >>> class B2(B1):
    ...     pass
    >>> class B3(B2):
    ...     pass
    >>> class D(object):
    ...     implements()
    >>> class S(B3, D):
    ...     implements()

    This failed due to a bug in the code for finding __providedBy__
    descriptors for old-style classes.

    """ 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test_declarations.py

示例2: test_classProvides_before_implements

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def test_classProvides_before_implements():
    """Special descriptor for class __provides__

    The descriptor caches the implementedBy info, so that
    we can get declarations for objects without instance-specific
    interfaces a bit quicker.

        For example::

          >>> from zope.interface import Interface, classProvides
          >>> class IFooFactory(Interface):
          ...     pass
          >>> class IFoo(Interface):
          ...     pass
          >>> class C(object):
          ...     classProvides(IFooFactory)
          ...     implements(IFoo)
          >>> [i.getName() for i in C.__provides__]
          ['IFooFactory']

          >>> [i.getName() for i in C().__provides__]
          ['IFoo']
    """ 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:25,代码来源:test_declarations.py

示例3: isSecure

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def isSecure(self):
        """
        Return True if this request is using a secure transport.

        Normally this method returns True if this request's HTTPChannel
        instance is using a transport that implements ISSLTransport.

        This will also return True if setHost() has been called
        with ssl=True.

        @returns: True if this request is secure
        @rtype: C{bool}
        """
        if self._forceSSL:
            return True
        transport = getattr(getattr(self, 'channel', None), 'transport', None)
        if interfaces.ISSLTransport(transport, None) is not None:
            return True
        return False 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:http.py

示例4: requestAvatarId

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def requestAvatarId(credentials):
        """
        @param credentials: something which implements one of the interfaces in
        self.credentialInterfaces.

        @return: a Deferred which will fire a string which identifies an
        avatar, an empty tuple to specify an authenticated anonymous user
        (provided as checkers.ANONYMOUS) or fire a Failure(UnauthorizedLogin).
        Alternatively, return the result itself.

        @see: L{twisted.cred.credentials}
        """



# A note on anonymity - We do not want None as the value for anonymous
# because it is too easy to accidentally return it.  We do not want the
# empty string, because it is too easy to mistype a password file.  For
# example, an .htpasswd file may contain the lines: ['hello:asdf',
# 'world:asdf', 'goodbye', ':world'].  This misconfiguration will have an
# ill effect in any case, but accidentally granting anonymous access is a
# worse failure mode than simply granting access to an untypeable
# username.  We do not want an instance of 'object', because that would
# create potential problems with persistence. 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:26,代码来源:checkers.py

示例5: addListener

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def addListener(self, listener):
        """
        Add a listener to the listeners queue.
        The server adds itself as a listener when there is a SELECT,
        so it can send EXIST commands.

        :param listener: listener to add
        :type listener: an object that implements IMailboxListener
        """

        listeners = self.listeners
        self.log.debug('Adding mailbox listener: %s. Total: %s' % (
                       listener, len(listeners)))
        listeners.add(listener) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:16,代码来源:mailbox.py

示例6: removeListener

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def removeListener(self, listener):
        """
        Remove a listener from the listeners queue.

        :param listener: listener to remove
        :type listener: an object that implements IMailboxListener
        """
        self.listeners.remove(listener) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:10,代码来源:mailbox.py

示例7: register_processor

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def register_processor(self, processor):
        """Add a new class which implements the `MessageProcessor` interface."""
        if verifyObject(MessageProcessor, processor):
            self.processors.append(processor) 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:6,代码来源:wireprotocol.py

示例8: implements

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def implements(f):
        pass 
开发者ID:omererdem,项目名称:honeything,代码行数:4,代码来源:twisted_test.py

示例9: test_backward_compat

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

        class C1(object): __implemented__ = I1
        class C2(C1): __implemented__ = I2, I5
        class C3(C2): __implemented__ = I3, C2.__implemented__

        self.assert_(C3.__implemented__.__class__ is tuple)

        self.assertEqual(
            [i.getName() for i in providedBy(C3())],
            ['I3', 'I2', 'I5'],
            )

        class C4(C3):
            implements(I4)

        self.assertEqual(
            [i.getName() for i in providedBy(C4())],
            ['I4', 'I3', 'I2', 'I5'],
            )

        self.assertEqual(
            [i.getName() for i in C4.__implemented__],
            ['I4', 'I3', 'I2', 'I5'],
            )

        # Note that C3.__implemented__ should now be a sequence of interfaces
        self.assertEqual(
            [i.getName() for i in C3.__implemented__],
            ['I3', 'I2', 'I5'],
            )
        self.failIf(C3.__implemented__.__class__ is tuple) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:34,代码来源:test_declarations.py

示例10: test_builtins

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def test_builtins(self):
        # Setup

        intspec = implementedBy(int)
        olddeclared = intspec.declared

        classImplements(int, I1)
        class myint(int):
            implements(I2)

        x = 42
        self.assertEqual([i.getName() for i in providedBy(x)],
                         ['I1'])

        x = myint(42)
        directlyProvides(x, I3)
        self.assertEqual([i.getName() for i in providedBy(x)],
                         ['I3', 'I2', 'I1'])

        # cleanup
        intspec.declared = olddeclared
        classImplements(int)

        x = 42
        self.assertEqual([i.getName() for i in providedBy(x)],
                         []) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:28,代码来源:test_declarations.py

示例11: test_classImplements_after_classImplementsOnly_issue_402

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def test_classImplements_after_classImplementsOnly_issue_402():
    """http://www.zope.org/Collectors/Zope3-dev/402

>>> from zope.interface import *
>>> class I1(Interface):
...     pass
>>> class I2(Interface):
...     pass
>>> class C:
...     implements(I1)
>>> class C2:
...     implementsOnly(I2)
>>> class I3(Interface):
...     pass

>>> [i.__name__ for i in providedBy(C2()).__iro__]
['I2', 'Interface']

>>> classImplements(C2, I3)
>>> [i.__name__ for i in providedBy(C2()).__iro__]
['I2', 'I3', 'Interface']

>>> class I4(Interface):
...     pass
>>> classImplements(C2, I4)
>>> [i.__name__ for i in providedBy(C2()).__iro__]
['I2', 'I3', 'I4', 'Interface']


""" 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:32,代码来源:test_declarations.py

示例12: test_picklability_of_implements_specifications

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def test_picklability_of_implements_specifications():
    """

    Sometimes, we need to pickle implements specs.  We should be able
    to do so as long as the class is picklable.

    >>> import pickle
    >>> pickle.loads(pickle.dumps(implementedBy(C))) is implementedBy(C)
    True


    """ 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:14,代码来源:test_declarations.py

示例13: test_interface

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def test_interface(self):
        """
        L{BasicCredentialFactory} implements L{ICredentialFactory}.
        """
        self.assertTrue(
            verifyObject(ICredentialFactory, self.credentialFactory)) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:8,代码来源:test_httpauth.py

示例14: test_holderImplementsITestCase

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def test_holderImplementsITestCase(self):
        """
        L{runner.TestHolder} implements L{ITestCase}.
        """
        self.assertIdentical(self.holder, ITestCase(self.holder))
        self.assertTrue(
            verifyObject(ITestCase, self.holder),
            "%r claims to provide %r but does not do so correctly."
            % (self.holder, ITestCase)) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:11,代码来源:test_runner.py

示例15: __init__

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import implements [as 别名]
def __init__(self, protoClass, bucketFilter):
        """Tell me what to wrap and where to get buckets.

        @param protoClass: The class of Protocol I will generate
          wrapped instances of.
        @type protoClass: L{Protocol<twisted.internet.interfaces.IProtocol>}
          class
        @param bucketFilter: The filter which will determine how
          traffic is shaped.
        @type bucketFilter: L{HierarchicalBucketFilter}.
        """
        # More precisely, protoClass can be any callable that will return
        # instances of something that implements IProtocol.
        self.protocol = protoClass
        self.bucketFilter = bucketFilter 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:17,代码来源:htb.py


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