PEP 245
Clark C. Evans
cce at clarkevans.com
Thu Apr 5 00:12:04 EDT 2001
> This is my own experiment with adapters and interfaces. I could not join
> the SourceForge project, and I dont know how things are being implemented
> right now. Use as you wish (even as a example of don't-do-this <wink>).
The current source code is at http://adapt.sourceforge.net/adapt.py
you shouldn't need a IE browser to access this. Also, the PEP is
at http://python.sourceforge.net/peps/pep-0246.html
> >>> for i in f.__adapt__(I1_Sequence): print i
> ...
> 1
> 2
> 3
> 4
Ok. According to the PEP, you could write this as:
import adapt from adapt
for i in adapt(f,I1_Sequence): print i
And then, in your FakeSequence, you should use __conform__
instead of __adapt__ (__adapt__ is used in the protocol)
> def __adapt__(self, protocol):
> if protocol == I1_Sequence:
> return MakeInterfaceAdapter_V1(protocol, self, self.ir_sequence)
> elif protocol == I2_Sequence:
> return MakeInterfaceAdapter_V2(protocol, self, self.ir_sequence)
> else:
> return None
Let's say you are now introducing an I3_Sequence, and
FakeSequence is already fixed and distributed to too many
clients to be resonably changeable. You can give the
I3_Sequence class an __adapt__ method which knows
about FakeSequence and returns the appropriate adapter.
This is the bi-directional part...
;) Clark
More information about the Python-list
mailing list