Skip to content

Commit

Permalink
explain why the Token casting is safe
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Jul 23, 2020
1 parent f7118c2 commit 288da20
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Products/PageTemplates/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,13 @@ class MappedExpr(object):
"""map expression: ``zope.tales`` --> ``chameleon.tales``."""
def __init__(self, type, expression, zt_engine):
self.type = type
# at this place, *expression* is a `chameleon.tokenize.Token`
# the ``_compile_zt_expr`` below causes this to be cached
# At this place, *expression* is a `chameleon.tokenize.Token`
# (a subtype of `str` for PY3 and of `unicode` for PY2).
# The ``_compile_zt_expr`` below causes this to be cached
# which can lead under Python 3 to unsolicited translations
# (details "https://github.com/zopefoundation/Zope/issues/876")
# call ``_compile_zt_expr`` with a "plain" string
# To avoid this, call ``_compile_zt_expr`` with
# *expression* cast to the `Token` base type.
expr = str(expression) if six.PY3 else unicode(expression)
self.expression = expression
# compile to be able to report errors
Expand Down

0 comments on commit 288da20

Please sign in to comment.