[Twisted-web] Different behaviour of Nevow loaders xmlstr and stan
when used in macro methods.
Richard Wall
m-lists at the-moon.net
Wed Jan 11 10:20:47 MST 2006
A few hours ago I posted a unit test to #twisted.web that I thought
demonstrated a problem I'm having with Nevow. It was wrong though, and
this is an updated version:
http://rafb.net/paste/results/sf5B5s57.html
What the test is supposed to demonstrate, is a difference in the
behaviour of loaders.stan and loaders.xmlstr (or xmlfile).
The test contains a rend.Page class with a macro_pattern(ctx, name)
method. The purpose of the macro is to lookup patterns called "name"
from a nevow.loaders.* instance at self.patternFactory.
If a matching pattern is found in patternFactory, it's children are
inserted into the tag that called the macro otherwise the original
contents are returned instead. So given a patternFactory:
<div n:pattern="body">
<p>Page specific Text</p>
</div>
...and docFactory:...
<div n:macro="pattern body">
<p>Default text</p>
</div>
You'd get:
<div>
<p>Default text</p>
</div>
That works fine with both loaders.stan and loaders.xmlstr. If however
the pattern its self uses the same macro, I get a recursion error in
loaders.xmlstr only. eg
<div n:pattern="body">
<div n:macro="pattern menu">
<ul>
<li>Default menu</li>
</ul>
</div>
<p>Page specific Text</p>
</div>
I can understand why this might cause recursion, and i have managed to
fix it in my app by adding checks to the macro method. I just don't
understand why the xml and stan loaders don't behave the same. I have
tried to isolate where the recursion starts and it seems to be in
loaders.xmlstr.load (~L200):
doc = flatsax.parseString(self.template, self.ignoreDocType,
self.ignoreComment)
# recursion seems to start here.
doc = flat.precompile(doc, ctx)
...I can't work out how the stan version prevents the recursion though.
Has anyone come across this before? Is it a bug or just an unsupported
use of macros? If anyone has any ideas, I'd be grateful.
I hope to post a fuller example of what I'm trying to achieve with this
later. Something like what I remember of Zope, where child pages can
inherit page patterns from parent pages.
--
Richard Wall
More information about the Twisted-web
mailing list