[Erp5-report] r44027 arnaud.fontaine - /erp5/trunk/products/ERP5Type/Utils.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Mar 8 04:38:48 CET 2011


Author: arnaud.fontaine
Date: Tue Mar  8 04:38:48 2011
New Revision: 44027

URL: http://svn.erp5.org?rev=44027&view=rev
Log:
Get properly the TALES Expression engine and CompilerError exception
for isValidTALESExpression. This fixes testDynamicClassGeneration
errors and failure for Zope 2.8.

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

Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=44027&r1=44026&r2=44027&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Tue Mar  8 04:38:48 2011
@@ -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, port
       # 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(express
     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



More information about the Erp5-report mailing list