Movatterモバイル変換
[0]ホーム
PEP 245
Clark C. Evanscce 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 athttp://adapt.sourceforge.net/adapt.pyyou shouldn't need a IE browser to access this. Also, the PEP isathttp://python.sourceforge.net/peps/pep-0246.html> >>> for i in f.__adapt__(I1_Sequence): print i> ...> 1> 2> 3> 4Ok. According to the PEP, you could write this as: import adapt from adapt for i in adapt(f,I1_Sequence): print iAnd 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 NoneLet's say you are now introducing an I3_Sequence, and FakeSequence is already fixed and distributed to too manyclients to be resonably changeable. You can give theI3_Sequence class an __adapt__ method which knowsabout FakeSequence and returns the appropriate adapter.This is the bi-directional part...;) Clark
More information about the Python-listmailing list
[8]ページ先頭