Malthe Borch wrote:
> 2009/5/4 Carlos de la Guardia <>:
>> If Malthe or anyone else has a good idea about how to do this and will give
>> me some pointers, I'm willing to use my limited abilities to make this work.
>> Otherwise, I might try to bring in old zpt.
> It can be done, but it requires the introduction of a new compilation
> mode, which will essentially produce a source-file which will "fit
> all"; currently, the compiler produces one source-file per
> keyword-argument signature. That's obviously not something you can
> reasonably determine at compile-time.
> The way to go about this is probably to have the render-method do
> something like this:
> def render(**kwargs):
>    kwargs['econtext'].update(kwargs)
>    return render_template(econtext=kwargs['econtext'])
> Such that all variables will be pulled from the dynamic variable
> scope; this should work, but otoh, there's always some trickery with
> that 'econtext'.

This might also slowdown the lookup of the argument values. Especially
whatever regular "context" is often passed in as an argument. But it may
not be dramatic.

In general I'd like the idea of this. I'd assume that there's gonna be
some nice subtle problems with it, but nothing the excellent test
coverage shouldn't find.

> Chameleon has a mode of operation triggered by the CHAMELEON_EAGER
> flag; this basically parses all templates at initialization; I think
> we can hijack this mode to force the above-mentioned "fallback"
> compilation. The render-logic would then be something like this:
> 1) Do we have ``ast`` and ``compiler`` available?
> 2) If not, is a fallback source-file available?

If we'd get this, I'd like to expose the "compile" step in an additional
way. It should be possible to do this as a distutils build_templates
command in the That'd make it similar in concept to building
extensions (or for example gettext .mo files). It's something you can do
as part of your build before releasing a package. The underlying
compiled templates format is just a pickle protocol 2 dump and thus
doesn't vary on any platform or Python build settings. So putting those
files into a source distribution should be fine in general.


Repoze-dev mailing list

Reply via email to