當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。