Commit b3ccc1ca authored by Arnaud Fontaine's avatar Arnaud Fontaine

Get properly the TALES Expression engine and CompilerError exception

for isValidTALESExpression. This fixes testDynamicClassGeneration
errors and failure for Zope 2.8.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44027 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0680d221
......@@ -1207,9 +1207,15 @@ def initializeProduct( context,
icon = icon)
#####################################################
# Constructor initialization
# TALES Expression
#####################################################
# This gets the Engine and CompilerError classes for TALES Expression
# wherever it is defined (which is different depending on the Zope
# version)
ExpressionEngine = getEngine()
CompilerError = ExpressionEngine.getCompilerError()
def createExpressionContext(object, portal=None):
"""
Return a context used for evaluating a TALES expression.
......@@ -1276,14 +1282,10 @@ def createExpressionContext(object, portal=None):
# the proper name these days
'context': object,
}
ec = getEngine().getContext(data)
ec = ExpressionEngine.getContext(data)
tv[cache_key] = ec
return ec
# This gets the CompilerError class wherever it is defined (which is
# different depending on the Zope version)
CompilerError = getEngine().getCompilerError()
def evaluateExpressionFromString(expression_context, expression_string):
"""
Evaluate a TALES Expression from the given string with the given
......@@ -1310,6 +1312,22 @@ def evaluateExpressionFromString(expression_context, expression_string):
raise ValueError("Error in TALES expression: '%s': %s" % (expression_string,
str(e)))
def isValidTALESExpression(value):
"""return if given value is valid TALES Expression.
This validator only validates Syntax of TALES Expression,
it does not tell that Expression is callable on given context
- value: string we try to compile
return tuple: (boolean result, error_message or None)
"""
try:
ExpressionEngine.compile(value)
except CompilerError, message:
return False, message
else:
return True, None
#####################################################
# More Useful methods which require Base
#####################################################
......@@ -1724,22 +1742,3 @@ def reencodeUrlEscapes(url):
url += [_reencodeUrlEscapes_map[c] for c in part]
except StopIteration:
return ''.join(url)
from zope.tales.engine import Engine
from zope.tales.tales import CompilerError
def isValidTALESExpression(value):
"""return if given value is valid TALES Expression.
This validator only validates Syntax of TALES Expression,
it does not tell that Expression is callable on given context
- value: string we try to compile
return tuple: (boolean result, error_message or None)
"""
try:
Engine.compile(value)
except CompilerError, message:
return False, message
else:
return True, None
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment