[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate - Expressions.py:1.1.2.3 PageTemplate.py:1.1.2.3 PageTemplateFile.py:1.1.2.4 TALES.py:1.1.2.3

Fred Drake Jr fdrake@acm.org
Tue, 20 Nov 2001 13:02:17 -0500


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

Modified Files:
      Tag: Zope-3x-branch
	Expressions.py PageTemplate.py PageTemplateFile.py TALES.py 
Log Message:
Finish making the tests run for page templates in Zope 3.

=== Zope3/lib/python/Zope/PageTemplate/Expressions.py 1.1.2.2 => 1.1.2.3 ===
                     ob = ob()
                 if path:
-                    ob = restrictedTraverse(ob, path, securityManager)
+                    import pdb
+                    try:
+                        ob = restrictedTraverse(ob, path, securityManager)
+                    except:
+                        pdb.set_trace()
+                        raise
                 exists = 1
                 break
             except Undefined, e:


=== Zope3/lib/python/Zope/PageTemplate/PageTemplate.py 1.1.2.2 => 1.1.2.3 ===
         self.write(text)
 
-    def pt_getContext(self, inst=None):
+    def pt_getContext(self):
         c = {'template': self,
              'options': {},
              'nothing': None,
              'modules': ModuleImporter,
              }
-        if inst is not None:
-            c['presentation'] = PresentationMapper(inst.getContext())
-        parent = getattr(self, 'aq_parent', None)
-        if parent is not None:
-            c['here'] = parent
-            c['container'] = self.aq_inner.aq_parent
-            while parent is not None:
-                self = parent
-                parent = getattr(self, 'aq_parent', None)
-            c['root'] = self
+##         if inst is not None:
+##             c['presentation'] = PresentationMapper(inst.getContext())
+##             c['here'] = inst.getContext()
+##             c['container'] = inst
+        # XXX this needs to be changed when we have context
+        c['root'] = None
         return c
-    
+
     def pt_render(self, source=0, extra_context={}):
         """Render this Page Template"""
         if self._v_errors:
@@ -83,10 +79,15 @@
                        tal=not source, strictinsert=0)()
         return output.getvalue()
 
-    def __call__(self, *args, **kwargs):
+    def __call__(self, inst=None, *args, **kwargs):
         if not kwargs.has_key('args'):
             kwargs['args'] = args
-        return self.pt_render(extra_context={'options': kwargs})
+        extra_context = {'options': kwargs}
+        if inst is not None:
+            extra_context['here'] = inst.getContext()
+            extra_context['presentation'] = PresentationMapper(inst.getContext())
+            extra_context['container'] = inst
+        return self.pt_render(extra_context=extra_context)
 
     def pt_errors(self):
         err = self._v_errors
@@ -153,6 +154,25 @@
             return self.content_type == 'text/html'
         return self.is_html
 
+    def __get__(self, instance, type=None):
+        return BoundPageTemplate(self, instance)
+
+
+class BoundPageTemplate:
+    def __init__(self, pt, ob):
+        self.im_func = pt
+        self.im_self = ob
+
+    def __call__(self, REQUEST=None, **kw):
+        return self.im_func(self.im_self, REQUEST=REQUEST, **kw)
+
+    def __getattr__(self, name):
+        return getattr(self.im_func, name)
+
+    def __repr__(self):
+        return "<BoundPageTemplateFile of %r>" % self.im_self
+
+
 class PresentationMapper:
     def __init__(self, ob):
         self.ob = ob
@@ -160,6 +180,7 @@
     def __getitem__(self, name):
         return getPresentation(self.ob, name, IBrowserPublish)
 
+
 class _ModuleImporter:
     def __getitem__(self, module):
         mod = __import__(module)
@@ -167,6 +188,7 @@
         for name in path[1:]:
             mod = getattr(mod, name)
         return mod
+
 
 ModuleImporter = _ModuleImporter()
 


=== Zope3/lib/python/Zope/PageTemplate/PageTemplateFile.py 1.1.2.3 => 1.1.2.4 ===
         raise StorageError, ("Instance of AntiPersistent class %s "
                              "cannot be stored." % self.__class__.__name__)
-
-    def __get__(self, instance, type=None):
-        return BoundPageTemplateFile(self, instance)
-
-
-class BoundPageTemplateFile:
-    def __init__(self, pt, ob):
-        self.im_func = pt
-        self.im_self = ob
-
-    def __call__(self, REQUEST=None, **kw):
-        return self.im_func(self.im_self, REQUEST=REQUEST, **kw)
-
-    def __getattr__(self, name):
-        return getattr(self.im_func, name)
-
-    def __repr__(self):
-        return "<BoundPageTemplateFile of %r>" % self.im_self


=== Zope3/lib/python/Zope/PageTemplate/TALES.py 1.1.2.2 => 1.1.2.3 ===
 
 import re, sys
+import ZTUtils
 
 StringType = type('')
 
@@ -78,29 +79,18 @@
 
 from SafeMapping import SafeMapping
 
-class Iterator:
+class Iterator(ZTUtils.Iterator):
     def __init__(self, name, seq, context):
-        self.seq = seq
-        self.nextIndex = 0
+        ZTUtils.Iterator.__init__(self, seq):
         self.name = name
         self._context = context
 
     def __iter__(self):
         return self
 
-    def _next(self):
-        i = self.nextIndex
-        try:
-            self.seq[i]
-        except IndexError:
-            return 0
-        self.index = i
-        self.nextIndex = i+1
-        return 1
-
     def next(self):
         try:
-            if self._next():
+            if ZTUtils.Iterator.next(self):
                 self._context.setLocal(self.name, self.seq[self.index])
                 return 1
         except TALESError: