[PEAK] Circular class adapters..

Bob Ippolito bob at redivi.com
Thu Feb 19 22:31:08 EST 2004


On Feb 19, 2004, at 7:49 PM, Phillip J. Eby wrote:

> At 06:39 PM 2/19/04 -0500, Phillip J. Eby wrote:
>> At 06:34 PM 2/19/04 -0500, Bob Ippolito wrote:
>>>
>>> How do I make this work?  Is it not possible, or is this a bug in
>>> PyProtocols?  With 0.9.2, I get this nasty traceback:
>>
>> Ugh.  It looks like advising an object (the object itself, as opposed 
>> to its class) with a circular adapter path doesn't work right.  I 
>> have no idea why, I'll have to investigate further (and add your 
>> example to the tests.
>
> Ugh, ugh, ugh!  It looks like there is a nasty misdesign of the 
> 'declareProvides()' and 'registerObject()' methods.  
> 'registerObject()' is unconditionally recursive with respect to 
> implied protocols.  It should be checking a return value from 
> 'declareProvides()', but 'declareProvides()' isn't required to even 
> have a return value, nor is one implemented.
>
> Yuck.  This ought to teach me to write the tests *first*, dammit.  
> Although, you'd think I'd have learned by now from the last dozen or 
> so bugs...
>
> (Unfortunately, I'll be doing penance for my sins for some time to 
> come, since *most* of PEAK was written with the tests second instead 
> of first.)
>
> Anyway, I've checked in a fix now, but I don't plan to make an 
> immediate release in case you find any more bugs.  :)  Feel free to 
> download a .tgz from either the PEAK or PyProtocols CVS distro in the 
> meantime.

Thanks!  This works perfectly.

If you want to take a look at what I am using circular class adaption 
for, I have made a snapshot of ptypes at 
http://undefined.org/python/ptypes-20040219.tgz -- you will need to 
install a VERY RECENT (as in hours ago) CVS version of PyProtocols if 
you want to play with it.

It's basically a toolkit for reading/writing binary formats with an API 
sort of like ctypes.  It includes support for an "iterfunc" reading 
style (generator abuse), so it can be hooked into Twisted and read off 
the wire incrementally without needing Stackless.  The goal is to be 
able to define these data structures in such a way that it does as much 
of the boilerplate reading and writing as possible.  I can imagine an 
"IDE" for reverse engineering data formats or protocols based on 
something like this.. possibly even using heuristics to help you figure 
it out ;)  I also want to write a Macromedia SWF file format 
reader/writer at some point, which is the reason for the 
variable-bit-integer reading/writing code and tests, though it is not 
currently utilized anywhere in the framework.

-bob




More information about the PEAK mailing list