Skip to content

Commit

Permalink
clearly state in the comments related to chameleon work arounds tha…
Browse files Browse the repository at this point in the history
…t those might go away with ``chameleon > 3.8.0``;

add a not to the Zope Book that ``chameleon`` implements `attrs` and `default` in a special way and that their value should not be changed
  • Loading branch information
d-maurer committed Jul 5, 2020
1 parent a4a5806 commit 1e7b380
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/zopebook/AppendixC.rst
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,11 @@ Note the names `root`, `context`, `container`, `template`, `request`, `user`, an
`modules` are optional names supported by Zope, but are not required by the
TALES standard.

Note that the (popular) ``chameleon`` template engine implements ``attrs``
and ``default`` not as standard variables but in a special way.
Trying to change their value may have undefined effects.


TALES Exists expressions
========================

Expand Down
9 changes: 6 additions & 3 deletions src/Products/PageTemplates/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,13 @@ def __init__(self, type, expression, zt_engine):
raise ExpressionError("$ unsupported", spe)

def __call__(self, target, c_engine):
# the convoluted handling of attrs is necessary to work around
# "https://github.com/malthe/chameleon/issues/323"
# The convoluted handling of ``attrs`` below was necessary
# for some ``chameleon`` versions to work around
# "https://github.com/malthe/chameleon/issues/323".
# The work round is partial only: until the ``chameleon``
# problem is fixed, `attrs` cannot be used inside ``tal:define``
# problem is fixed, `attrs` cannot be used inside ``tal:define``.
# Potentially, ``attrs`` handling could be simplified
# for ``chameleon > 3.8.0``.
return template(
"try: __zt_tmp = attrs\n"
"except NameError: __zt_tmp = None\n"
Expand Down
3 changes: 2 additions & 1 deletion src/Products/PageTemplates/tests/testVariables.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ def test_attrs(self):

# ``test_attrs`` should have the previous definition
# Unfortunately, "https://github.com/malthe/chameleon/issues/323"
# (``attrs`` cannot be used in ``tal:define`` nor in ``tal:replace``)
# (``attrs`` cannot be used in ``tal:define``)
# lets it fail.
# We must therefore test (what works with the current
# ``chameleon``) in a different way.
# Note ``chameleon > 3.8.0`` likely will allow the previous definition
def test_attrs(self): # noqa: F811
t = self.g.t
t.write("<div attr='attr' tal:content='python: attrs[\"attr\"]'/>")
Expand Down

0 comments on commit 1e7b380

Please sign in to comment.