[Erp5-report] r43239 nicolas - in /erp5/trunk/products/ERP5Type: Utils.py __init__.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Feb 9 17:36:11 CET 2011


Author: nicolas
Date: Wed Feb  9 17:36:11 2011
New Revision: 43239

URL: http://svn.erp5.org?rev=43239&view=rev
Log:
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.


Modified:
    erp5/trunk/products/ERP5Type/Utils.py
    erp5/trunk/products/ERP5Type/__init__.py

Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=43239&r1=43238&r2=43239&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Wed Feb  9 17:36:11 2011
@@ -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

Modified: erp5/trunk/products/ERP5Type/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/__init__.py?rev=43239&r1=43238&r2=43239&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/__init__.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/__init__.py [utf8] Wed Feb  9 17:36:11 2011
@@ -165,7 +165,8 @@ ModuleSecurityInfo('Products.ERP5Type.Ut
     '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')



More information about the Erp5-report mailing list