Element/LiveElement do not allow genshifile templates

Bug #506147 reported by Cory Dodt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
txGenshi
Fix Released
High
Unassigned

Bug Description

Using docFactory = genshifile(..) in an Element or LiveElement doesn't work. txGenshi currently expects to be able to get a reference to the renderable by adapting the Nevow context object. Element and LiveElement don't use the context--that is pretty much the reason they exist.

Typical traceback that occurs when the rendering machinery finds an Element with a genshifile loader:

Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/Nevow-0.10.0-py2.6.egg/nevow/_flat.py", line 462, in _flattensome
    element = state.next()
  File "/usr/local/lib/python2.6/dist-packages/Nevow-0.10.0-py2.6.egg/nevow/_flat.py", line 424, in flatten
    raise FlattenerError(e, roots, extract_tb(exc_info()[2]))
nevow._flat.FlattenerError: Exception while flattening:
  <chichimec.example.RandomNumber object at 0x1baa850>
  File "/usr/local/lib/python2.6/dist-packages/Nevow-0.10.0-py2.6.egg/nevow/_flat.py", line 415, in flatten
    element = stack[-1].next()
  File "/usr/local/lib/python2.6/dist-packages/Nevow-0.10.0-py2.6.egg/nevow/_flat.py", line 334, in _flatten
    yield _flatten(request, renderable.render(request), [], renderable,
  File "/usr/local/lib/python2.6/dist-packages/Nevow-0.10.0-py2.6.egg/nevow/athena.py", line 1868, in render
    document = tags.invisible[Element.render(self, request)]
  File "/usr/local/lib/python2.6/dist-packages/Nevow-0.10.0-py2.6.egg/nevow/page.py", line 107, in render
    return docFactory.load(None, _getPreprocessors(self))
  File "/usr/local/lib/python2.6/dist-packages/txGenshi-0.0.1.0cdd1-py2.6.egg/txgenshi/loader.py", line 140, in load
    renderer = inevow.IRenderer(ctx)
TypeError: ('Could not adapt', None, <InterfaceClass nevow.inevow.IRenderer>)

Related branches

Cory Dodt (corydodt)
Changed in txgenshi:
importance: Undecided → High
status: New → Confirmed
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.

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

Merged with approval - using descriptor-based approach.

Changed in txgenshi:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.