[ZPT] CVS: Zope/lib/python/Products/PageTemplates - Expressions.py:1.35.18.1

Fred L. Drake, Jr. fdrake@acm.org
Tue, 30 Jul 2002 16:14:32 -0400


Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv12500

Modified Files:
      Tag: Zope-2_7-development-branch
	Expressions.py 
Log Message:
Make sure not: expressions do not change representation with Python 2.3,
where the "not" operator returns a bool types with a changed str().


=== Zope/lib/python/Products/PageTemplates/Expressions.py 1.35 => 1.35.18.1 ===
         self._c = compiler.compile(expr)
         
     def __call__(self, econtext):
-        return not econtext.evaluateBoolean(self._c)
+        # We use the (not x) and 1 or 0 formulation to avoid changing
+        # the representation of the result in Python 2.3, where the
+        # result of "not" becomes an instance of bool.
+        return (not econtext.evaluateBoolean(self._c)) and 1 or 0
 
     def __repr__(self):
         return 'not:%s' % `self._s`