[Zope] Interpreting dynamically generated TAL
tomas@fabula.de
tomas@fabula.de
Wed, 4 Sep 2002 19:03:59 +0200
Hi,
it's me again, this time trying to interpret dynamically generated
TAL (yes, we convinced our customer to go TAL, at least in this
point.
The setting: we generate TAL from a source XML via XSLT. Now
we want to render it. I had a look into PageTemplates.py, and
that's what I've come up with:
| def edit_zpt(self, REQUEST = None, RESPONSE = None,
| extra_bindings={},
| ishtml=1,
| ):
| """
| Whack Art.
| """
|
| # Snarfgled from $(ZOPEDIR)/lib/python/Products/PageTemplates/PageTemplate.py
| text = self.edit(REQUEST, RESPONSE)
|
| # ---------------------------- compile template:
| gen = TALGenerator(getEngine(), not ishtml)
| if ishtml: parser = HTMLTALParser(gen)
| else: parser = TALParser(gen)
| errors = ()
| try:
| parser.parseString(text)
| program, macros = parser.getCode()
| except:
| raise PTRuntimeError, 'Page Template %s has errors: [%s: %s]' \
| % ((self, ) + sys.exc_info()[:2])
| warnings = parser.getWarnings()
| # ---------------------------- get Zope context:
| c = {'template': self,
| 'options': {},
| 'nothing': None,
| 'request': None,
| 'modules': ModuleImporter,
| }
| parent = getattr(self, 'aq_parent', None)
| if parent is not None:
| c['here'] = parent
| c['container'] = self.aq_inner.aq_parent
| while parent is not None:
| self = parent
| parent = getattr(self, 'aq_parent', None)
| c['root'] = self
| c.update(extra_bindings)
| output = StringIO()
| TALInterpreter(program, macros,
| getEngine().getContext(c),
| output,
|# debug=1,
| )()
|#### FIXME: what do we do with those? ## tal=not source, strictinsert=0 ##
| return output.getvalue()
The compiler seems happy, the interpreter doesn't barf either, but it doesn't
replace a thing. It passes input verbatim to output. Am I missing anything
obvious? Am I trying --again-- the impossible?
Thanks for any pointers
-- tomas