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


Python interface.providedBy方法代码示例

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


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

示例1: test_classImplements_base_not_derived

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def test_classImplements_base_not_derived(self):
        from zope.interface import Interface
        from zope.interface import implementedBy
        from zope.interface import providedBy
        class IBase(Interface):
            def method():
                pass
        class IDerived(IBase):
            pass
        class Current():
            __implemented__ = IBase
            def method(self):
                pass
        current = Current()

        self.assertTrue(IBase.implementedBy(Current))
        self.assertFalse(IDerived.implementedBy(Current))
        self.assertTrue(IBase in implementedBy(Current))
        self.assertFalse(IDerived in implementedBy(Current))
        self.assertTrue(IBase in providedBy(current))
        self.assertFalse(IDerived in providedBy(current)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_interface.py

示例2: makeConnection

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def makeConnection(self, transport):
        """
        Connect this wrapper to the given transport and initialize the
        necessary L{OpenSSL.SSL.Connection} with a memory BIO.
        """
        self._tlsConnection = self.factory._createConnection(self)
        self._appSendBuffer = []

        # Add interfaces provided by the transport we are wrapping:
        for interface in providedBy(transport):
            directlyProvides(self, interface)

        # Intentionally skip ProtocolWrapper.makeConnection - it might call
        # wrappedProtocol.makeConnection, which we want to make conditional.
        Protocol.makeConnection(self, transport)
        self.factory.registerProtocol(self)
        if self._connectWrapped:
            # Now that the TLS layer is initialized, notify the application of
            # the connection.
            ProtocolWrapper.makeConnection(self, transport)

        # Now that we ourselves have a transport (initialized by the
        # ProtocolWrapper.makeConnection call above), kick off the TLS
        # handshake.
        self._checkHandshakeStatus() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:27,代码来源:tls.py

示例3: _checkHandshakeStatus

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def _checkHandshakeStatus(self):
        """
        Ask OpenSSL to proceed with a handshake in progress.

        Initially, this just sends the ClientHello; after some bytes have been
        stuffed in to the C{Connection} object by C{dataReceived}, it will then
        respond to any C{Certificate} or C{KeyExchange} messages.
        """
        # The connection might already be aborted (eg. by a callback during
        # connection setup), so don't even bother trying to handshake in that
        # case.
        if self._aborted:
            return
        try:
            self._tlsConnection.do_handshake()
        except WantReadError:
            self._flushSendBIO()
        except Error:
            self._tlsShutdownFinished(Failure())
        else:
            self._handshakeDone = True
            if IHandshakeListener.providedBy(self.wrappedProtocol):
                self.wrappedProtocol.handshakeCompleted() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:tls.py

示例4: requestAvatarId

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def requestAvatarId(self, credentials):
        """
        Part of the L{ICredentialsChecker} interface.  Called by a portal with
        some credentials to check if they'll authenticate a user.  We check the
        interfaces that the credentials provide against our list of acceptable
        checkers.  If one of them matches, we ask that checker to verify the
        credentials.  If they're valid, we call our L{_cbGoodAuthentication}
        method to continue.

        @param credentials: the credentials the L{Portal} wants us to verify
        """
        ifac = providedBy(credentials)
        for i in ifac:
            c = self.checkers.get(i)
            if c is not None:
                d = defer.maybeDeferred(c.requestAvatarId, credentials)
                return d.addCallback(self._cbGoodAuthentication,
                        credentials)
        return defer.fail(UnhandledCredentials("No checker for %s" % \
            ', '.join(map(reflect.qual, ifac)))) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:checkers.py

示例5: test_classImplements_base_not_derived

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def test_classImplements_base_not_derived(self):
        from zope.interface import Interface
        from zope.interface import implementedBy
        from zope.interface import providedBy
        class IBase(Interface):
            def method():
                pass
        class IDerived(IBase):
            pass
        class Current():
            __implemented__ = IBase
            def method(self):
                raise NotImplementedError()
        current = Current()

        self.assertTrue(IBase.implementedBy(Current))
        self.assertFalse(IDerived.implementedBy(Current))
        self.assertTrue(IBase in implementedBy(Current))
        self.assertFalse(IDerived in implementedBy(Current))
        self.assertTrue(IBase in providedBy(current))
        self.assertFalse(IDerived in providedBy(current)) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_interface.py

示例6: _makeRequestProxyFactory

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def _makeRequestProxyFactory(clsToWrap):
    """
    Return a callable that proxies instances of C{clsToWrap} via
        L{_IDeprecatedHTTPChannelToRequestInterface}.

    @param clsToWrap: The class whose instances will be proxied.
    @type cls: L{_IDeprecatedHTTPChannelToRequestInterface}
        implementer.

    @return: A factory that returns
        L{_IDeprecatedHTTPChannelToRequestInterface} proxies.
    @rtype: L{callable} whose interface matches C{clsToWrap}'s constructor.
    """

    def _makeRequestProxy(*args, **kwargs):
        instance = clsToWrap(*args, **kwargs)
        return _IDeprecatedHTTPChannelToRequestInterfaceProxy(instance)

    # For INonQueuedRequestFactory
    directlyProvides(_makeRequestProxy, providedBy(clsToWrap))
    return _makeRequestProxy 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:23,代码来源:test_http.py

示例7: _applyProtocolNegotiation

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def _applyProtocolNegotiation(self, connection):
        """
        Applies ALPN/NPN protocol neogitation to the connection, if the factory
        supports it.

        @param connection: The OpenSSL connection object to have ALPN/NPN added
            to it.
        @type connection: L{OpenSSL.SSL.Connection}

        @return: Nothing
        @rtype: L{None}
        """
        if IProtocolNegotiationFactory.providedBy(self.wrappedFactory):
            protocols = self.wrappedFactory.acceptableProtocols()
            context = connection.get_context()
            _setAcceptableProtocols(context, protocols)

        return 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:20,代码来源:tls.py

示例8: testUtil

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def testUtil(self):
        from zope.interface import implementedBy
        from zope.interface import providedBy
        from zope.interface.tests.unitfixtures import A
        from zope.interface.tests.unitfixtures import B
        from zope.interface.tests.unitfixtures import C
        from zope.interface.tests.unitfixtures import I1
        from zope.interface.tests.unitfixtures import I2
        from zope.interface.tests.unitfixtures import IC
        self.assert_(IC in implementedBy(C))
        self.assert_(I1 in implementedBy(A))
        self.assert_(not I1 in implementedBy(C))
        self.assert_(I2 in implementedBy(B))
        self.assert_(not I2 in implementedBy(C))

        self.assert_(IC in providedBy(C()))
        self.assert_(I1 in providedBy(A()))
        self.assert_(not I1 in providedBy(C()))
        self.assert_(I2 in providedBy(B()))
        self.assert_(not I2 in providedBy(C())) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:test_interface.py

示例9: testObjectImplements

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def testObjectImplements(self):
        from zope.interface.tests.unitfixtures import A
        from zope.interface.tests.unitfixtures import B
        from zope.interface.tests.unitfixtures import C
        from zope.interface.tests.unitfixtures import D
        from zope.interface.tests.unitfixtures import E
        from zope.interface.tests.unitfixtures import I1
        from zope.interface.tests.unitfixtures import I2
        from zope.interface.tests.unitfixtures import IC
        self.assert_(IC.providedBy(C()))

        self.assert_(I1.providedBy(A()))
        self.assert_(I1.providedBy(B()))
        self.assert_(not I1.providedBy(C()))
        self.assert_(I1.providedBy(D()))
        self.assert_(I1.providedBy(E()))

        self.assert_(not I2.providedBy(A()))
        self.assert_(I2.providedBy(B()))
        self.assert_(not I2.providedBy(C()))

        # Not after interface geddon
        # self.assert_(not I2.providedBy(D()))

        self.assert_(not I2.providedBy(E())) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:test_interface.py

示例10: test_provided_by_with_slots

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

    This is an edge case: if the __slots__ of a class contain '__provides__',
    using providedBy() on that class should still work (this occurs, for
    example, when providing an adapter for a concrete class.)

    >>> import zope.interface
    >>> class Slotted(object):
    ...     __slots__ = ('__provides__')
    >>> class IFoo(zope.interface.Interface):
    ...     pass
    >>> IFoo.providedBy(Slotted)
    False

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

示例11: test_providedBy_miss

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def test_providedBy_miss(self):
        from zope.interface import interface
        from zope.interface.declarations import _empty
        sb = self._makeOne()
        def _providedBy(obj):
            return _empty
        with _Monkey(interface, providedBy=_providedBy):
            self.assertFalse(sb.providedBy(object())) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_interface.py

示例12: test_providedBy_hit

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def test_providedBy_hit(self):
        from zope.interface import interface
        sb = self._makeOne()
        class _Decl(object):
            _implied = {sb: {},}
        def _providedBy(obj):
            return _Decl()
        with _Monkey(interface, providedBy=_providedBy):
            self.assertTrue(sb.providedBy(object())) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_interface.py

示例13: _makeOne

# 需要导入模块: from zope import interface [as 别名]
# 或者: from zope.interface import providedBy [as 别名]
def _makeOne(self, object_should_provide):
        class IB(self._getTargetClass()):
            def _call_conform(self, conform):
                return conform(self)
            def providedBy(self, obj):
                return object_should_provide
        return IB() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_interface.py

示例14: test_classImplements_simple

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

        class ICurrent(Interface):
            def method1(a, b):
                pass
            def method2(a, b):
                pass

        class IOther(Interface):
            pass

        class Current(object):
            __implemented__ = ICurrent
            def method1(self, a, b):
                return 1
            def method2(self, a, b):
                return 2

        current = Current()

        self.assertTrue(ICurrent.implementedBy(Current))
        self.assertFalse(IOther.implementedBy(Current))
        self.assertTrue(ICurrent in implementedBy(Current))
        self.assertFalse(IOther in implementedBy(Current))
        self.assertTrue(ICurrent in providedBy(current))
        self.assertFalse(IOther in providedBy(current)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:31,代码来源:test_interface.py

示例15: test_classImplements_multiple

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

        class ILeft(Interface):
            def method():
                pass

        class IRight(ILeft):
            pass

        class Left(object):
            __implemented__ = ILeft

            def method(self):
                pass

        class Right(object):
            __implemented__ = IRight

        class Ambi(Left, Right):
            pass

        ambi = Ambi()

        self.assertTrue(ILeft.implementedBy(Ambi))
        self.assertTrue(IRight.implementedBy(Ambi))
        self.assertTrue(ILeft in implementedBy(Ambi))
        self.assertTrue(IRight in implementedBy(Ambi))
        self.assertTrue(ILeft in providedBy(ambi))
        self.assertTrue(IRight in providedBy(ambi)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:34,代码来源:test_interface.py


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