Comment 1 for bug 502823

Revision history for this message
Cory Dodt (corydodt) wrote :

Yipes, really ugly one here. I'd like a code review on this please, when done.

There's a bit of a wtf for me in the original code:

rendPageAttrs = [x[0] for x in getmembers(rend.Page)]

def getObjectData(obj):
...
        if callable(member):
            val = member()
...
    return data

Wow, really? We call every callable member of the class during rendering, regardless of whether the template refers to it? To fix it for athena I had to do this, for starters:

class MyLivePage(athena.LivePage):
    """
    this evil hack is needed to work around a bug in getmembers+z.i
    __provides__

    Using zope.interface, you use __provides__ to discuss interfaces provided
    by a class. However, see bug mentioned here: http://old.nabble.com/Problem-with-zope.interface-leaking-attributes-td25824576.html

    This causes getmembers to blow up on LivePage. So this class exists so
    that there is a class with the same members as LivePage, but which does
    *not* have a broken __provides__ attribute, and now we can (ta-DA) use
    getmembers on the subclass.
    """
    __provides__ = None

livePageAttrs = [x[0] for x in getmembers(MyLivePage)]

Then I'll also have to hide @renderer and @expose methods. But what about just.. application methods? They could do something with nasty side effects. Am I missing something here about how completely evil this isn't?