本文整理匯總了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))
示例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()
示例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()
示例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))))
示例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))
示例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
示例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
示例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()))
示例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()))
示例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
"""
示例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()))
示例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()))
示例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()
示例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))
示例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))