Commit a4db5e0e authored by Nicolas Delaby's avatar Nicolas Delaby

Add new utility isValidTALESExpression which return if source text of TALES Expression

is compilable or not.
It will be useful For StringField's ExternalValidator who are trying to
validate TALES Expression as input.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43239 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c682f9d1
......@@ -3367,3 +3367,22 @@ 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
......@@ -165,7 +165,8 @@ ModuleSecurityInfo('Products.ERP5Type.Utils').declarePublic(
'sortValueList', 'convertToUpperCase', 'UpperCase',
'convertToMixedCase', 'cartesianProduct', 'sleep', 'getCommonTimeZoneList',
'int2letter', 'getMessageIdWithContext', 'getTranslationStringWithContext',
'Email_parseAddressHeader', 'guessEncodingFromText')
'Email_parseAddressHeader', 'guessEncodingFromText',
'isValidTALESExpression')
allow_module('Products.ERP5Type.Message')
ModuleSecurityInfo('Products.ERP5Type.Message').declarePublic('translateString')
......
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