[PEAK] pyprotocols
darryl
developer at csrules.dyndns.org
Thu Nov 13 20:21:21 EST 2003
Here's an example from twisted [twisted components] :
from twisted.python import components
class IAmericanSocket(components.Interface):
def voltage(self):
"""Return the voltage produced by this socket object, as an integer.
"""
class AmericanSocket:
__implements__ = (IAmericanSocket, )
def voltage(self):
return 110
class ForeignSocket:
def voltage(self):
return 220
class AdaptToAmericanSocket(components.Adapter):
__implements__ = (IAmericanSocket, )
def voltage(self):
return self.original.voltage() / 2
components.registerAdapter(
AdaptToAmericanSocket,
ForeignSocket,
IAmericanSocket)
>>> as = AmericanSocket()
>>> fs = ForeignSocket()
>>> components.implements(as, IAmericanSocket)
1
>>> components.implements(fs, IAmericanSocket)
0
----------------------------------------------------------------------------
What is the peak/pyprotocol way to do this?
More information about the PEAK
mailing list