[pod,px] An expression that begins with char ':' is considered XML code that will come into the result unescaped.

This commit is contained in:
Gaetan Delannay 2013-05-24 10:16:16 +02:00
parent fd33e73efa
commit 540a9947d8

View file

@ -78,6 +78,13 @@ class Expression(PodElement):
def __init__(self, pyExpr): def __init__(self, pyExpr):
# The Python expression # The Python expression
self.expr = pyExpr.strip() self.expr = pyExpr.strip()
# Must we, when evaluating the expression, escape XML special chars
# or not?
if self.expr.startswith(':'):
self.expr = self.expr[1:]
self.escapeXml = False
else:
self.escapeXml = True
# We will store here the expression's true result (before being # We will store here the expression's true result (before being
# converted to a string) # converted to a string)
self.result = None self.result = None
@ -91,11 +98,8 @@ class Expression(PodElement):
'''Evaluates the Python expression (self.expr) with a given '''Evaluates the Python expression (self.expr) with a given
p_context, and returns the result. More precisely, it returns a p_context, and returns the result. More precisely, it returns a
tuple (result, escapeXml). Boolean escapeXml indicates if XML chars tuple (result, escapeXml). Boolean escapeXml indicates if XML chars
must be escaped or not. For example, if the expression's result is a must be escaped or not.'''
PX, the result of evaluating it (a chunk of XHTML) must be inserted escapeXml = self.escapeXml
as is, unescaped, into the buffer. In most situations, XML escaping
will be enabled.'''
escapeXml = True
# Evaluate the expression, or get it from self.result if it has already # Evaluate the expression, or get it from self.result if it has already
# been computed. # been computed.
if self.evaluated: if self.evaluated:
@ -121,6 +125,7 @@ class Expression(PodElement):
# A PX that must be called within the current PX. Call it with the # A PX that must be called within the current PX. Call it with the
# current context. # current context.
res = res(context) res = res(context)
# Force escapeXml to False.
escapeXml = False escapeXml = False
else: else:
res = unicode(res) res = unicode(res)