[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/PageTemplate - Engine.py:1.1.2.1.4.1

Jim Fulton jim@zope.com
Wed, 5 Jun 2002 11:18:31 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/PageTemplate
In directory cvs.zope.org:/tmp/cvs-serv20512/lib/python/Zope/App/PageTemplate

Modified Files:
      Tag: Zope3InWonderland-branch
	Engine.py 
Log Message:
Fixed up zcml and pt to reflect new way of defining views.
This changed lots of urls. Also made sure that relative urls
starting with names with :: had a preceeding "./".  :-/

Had to modify some py files to accomidate these changes, including
createing some interfaces to use in security assertions.



=== Zope3/lib/python/Zope/App/PageTemplate/Engine.py 1.1.2.1 => 1.1.2.1.4.1 ===
 __metaclass__ = type # All classes are new style when run with Python 2.2+
 
-from Zope.PageTemplate.TALES import ExpressionEngine, RegistrationError
+from Zope.PageTemplate.TALES \
+     import ExpressionEngine, RegistrationError, Context
 from Zope.PageTemplate.Expressions \
      import PathExpr, StringExpr, NotExpr, DeferExpr
 from Zope.PageTemplate.PythonExpr import PythonExpr
@@ -27,6 +28,7 @@
 from Zope.ComponentArchitecture import getAdapter
 from Zope.App.Traversing.ITraverser import ITraverser
 from Zope.Security.RestrictedBuiltins import RestrictedBuiltins
+from Zope.Proxy.ProxyIntrospection import removeAllProxies
 import sys
 
 def zopeTraverser(object, path_items, econtext):
@@ -49,6 +51,13 @@
         vars = self._bind_used_names(econtext, RestrictedBuiltins)
         return eval(self._code, vars)
 
+class ZopeContext(Context):
+
+    def evaluateMacro(self, expr):
+        macro = Context.evaluateMacro(self, expr)
+        macro = removeAllProxies(macro)
+        return macro
+
 class ZopeEngine(ExpressionEngine):
 
     def getContext(self, __namespace=None, **namespace):
@@ -58,7 +67,7 @@
             else:
                 namespace = __namespace
                 
-        context = super(ZopeEngine, self).getContext(namespace)
+        context = ZopeContext(self, namespace)
 
         # Put request into context so path traversal can find it
         if 'request' in namespace:
@@ -68,13 +77,12 @@
 
 def Engine():
     e = ZopeEngine()
-    reg = e.registerType
     for pt in ZopePathExpr._default_type_names:
-        reg(pt, ZopePathExpr)
-    reg('string', StringExpr)
-    reg('python', ZopePythonExpr)
-    reg('not', NotExpr)
-    reg('defer', DeferExpr)
+        e.registerType(pt, ZopePathExpr)
+    e.registerType('string', StringExpr)
+    e.registerType('python', ZopePythonExpr)
+    e.registerType('not', NotExpr)
+    e.registerType('defer', DeferExpr)
     e.registerBaseName('modules', ProxyFactory(sys.modules))
     return e