[Zope-dev] two hard questions

Tim McLaughlin tim@iterationzero.com
Wed, 06 Mar 2002 07:27:51 -0500


Firstly, I'm trying to return a lazy list to a dtml-in, but it seems 
that the __getitems__ are all called up front....  This is the class and 
the print statement shows up in debugging before any debugging output 
from within the dtml-in:

class LazyList:
    def __init__(self, root, selections):
        self._root = root
        self._selections = selections
    def __getitem__(self, index):
        s = self._selections[index]
        print s.getPath()   #####  this is executed for all items before 
anythingwithin the dtml-in
        o = self._root.restrictedTraverse(s.getPath())
        o.setSelection(s)
        return o
    def __len__(self):
        return len(self._selections)

Does this mean that dmtl-in touches all of the objects first for some 
reason?  Or am I missing something?

Second hard ?.....  Is there any way to wrap a Folder subclassed 
instance within another class so that I can override some methods on an 
instance by instance basis?  I tried doing a .__class__ replacement, but 
for whatever reason, Zope machinery seems to keep it from taking effect. 
 Any ideas?  I've tried about 5 different approaches to no avail :(

Sincerely,
Tim McLaughlin

-- 
Tim McLaughlin
Iteration ZERO, Inc. - www.iterationzero.com
703.481.3983