[Zope3-checkins] CVS: Zope3/src/zope/app/pagetemplate - engine.py:1.17

Barry Warsaw barry@zope.com
Mon, 30 Jun 2003 18:47:37 -0400


Update of /cvs-repository/Zope3/src/zope/app/pagetemplate
In directory cvs.zope.org:/tmp/cvs-serv16154

Modified Files:
	engine.py 
Log Message:
Override the base class's evaluateText() method so that it knows how
to unwrap proxied text objects, such as MessageIDs.  Better to put
this here than in zope.tales so we can remove dependencies there on
the zope.proxy and zope.context packages.


=== Zope3/src/zope/app/pagetemplate/engine.py 1.16 => 1.17 ===
--- Zope3/src/zope/app/pagetemplate/engine.py:1.16	Fri Jun 20 02:43:05 2003
+++ Zope3/src/zope/app/pagetemplate/engine.py	Mon Jun 30 18:47:37 2003
@@ -20,6 +20,7 @@
 __metaclass__ = type # All classes are new style when run with Python 2.2+
 
 import sys
+from types import StringTypes
 
 from zope.tales.expressions import PathExpr
 from zope.tales.expressions import StringExpr
@@ -29,12 +30,18 @@
 from zope.tales.tales import ExpressionEngine
 from zope.tales.tales import Context
 
-from zope.app.traversing.adapters import Traverser
+from zope.context.wrapper import getbaseobject
+from zope.proxy import proxy_compatible_isinstance as isinstance_ex
 from zope.proxy import removeAllProxies
 from zope.security.proxy import ProxyFactory
 from zope.security.builtins import RestrictedBuiltins
 from zope.i18n.translate import Translator
 
+from zope.app.traversing.adapters import Traverser
+
+_default = object()
+
+
 def zopeTraverser(object, path_items, econtext):
     """Traverses a sequence of names, first trying attributes then items.
     """
@@ -60,6 +67,15 @@
     def setContext(self, name, value):
         # Hook to allow subclasses to do things like adding security proxies
         Context.setContext(self, name, ProxyFactory(value))
+
+    def evaluateText(self, expr):
+        text = self.evaluate(expr)
+        if text is _default or text is None:
+            return text
+        if isinstance_ex(text, StringTypes):
+            # text could be a proxied/wrapped object
+            return getbaseobject(text)
+        return unicode(text)
 
     def evaluateMacro(self, expr):
         macro = Context.evaluateMacro(self, expr)