Reading https://pypi.python.org/pypi/five.pt/2.2.1

  To enable Chameleon, configure the package using ZCML:

   <include package="five.pt" />

Are Chameleon templates enabled per-package or globally? Instructions are little sparse.

If I want to enable Chameleon for a particular package only is it possible? (making migrating to Chameleon easier)

有帮助吗?

解决方案

To quote directly from the PyPI page for the package:

It works using monkey-patching onto the existing API (specifically, the TALInterpreter and PageTemplate classes). In simple terms, what the patching does is to replace the TAL interpreter class and make sure that the so-called "cooking" routine uses the Chameleon parser and compiler instead of the zope.* reference implementation.

So, when you load the five.pt package, the regular page templates code is patched to use Chameleon templates instead when templates are cooked (compiled).

That really precludes enabling Chameleon and disabling Chameleon on a package-by-package basis. Once any packages uses the <include package="five.pt" /> directive, the five.pt configure.zcml file is loaded and the patch is applied.

That said, theoretically it should be possible to add per-package enabling or disabling back into the patch; the __call__ and cook methods of the five.pt Program utility would have to be taught how to detect what package the template applies to and make a decision on what RepeatDict class and page template object to use.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top