Comment 1 for bug 506147

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

I think I can implement this with PEP 252(?) descriptors:

class NiftyDateWidget(LiveElement):
    docFactory = loader.genshifile('blah.xhtml') # as usual

...

class genshifile(object):
    def __init__(self, filename):
        self.filename = filename
        self._cache = NOCACHE

    def __get__(self, instance, cls):
        if self._cache is NOCACHE:
            gf = _GenshiFile(filename)
            gf.object = instance
            self._cache = gf
        else:
            gf = self._cache
        return gf

Then, the class _GenshiFile is what genshifile used to be; but load is modified
to use self.object instead of the context.