[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pagetemplate/ Fixed bug publishing bound page templates

Jim Fulton jim at zope.com
Fri Jun 25 12:26:30 EDT 2004


Log message for revision 25984:
Fixed bug publishing bound page templates

When Fred and I added an interface declaration to
zope.pagetemplate.pagetemplate.PageTemplate, we unwittingly broke
BoundPageTemplates. This was due to the fact that BoundPageTemplates
were overagressive about exposing underlying template attributes, 
including interface declarations.  

Changed BoundPageTemplates to only expose needed attributes, macros
amd filename.

Added a test for the view that exposed the error.



-=-
Modified: Zope3/trunk/src/zope/app/pagetemplate/engine.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/engine.py	2004-06-25 15:45:44 UTC (rev 25983)
+++ Zope3/trunk/src/zope/app/pagetemplate/engine.py	2004-06-25 16:26:30 UTC (rev 25984)
@@ -182,7 +182,6 @@
             context.request = namespace['request']
 
         # Put context into context so path traversal can find it
-        # XXX: Change to container once the renaming has been done!
         if 'context' in namespace:
             context.context = namespace['context']
 
@@ -205,8 +204,5 @@
 
 class AppPT(object):
 
-    # Use our special engine
-    pt_getEngineContext = Engine.getContext
-
     def pt_getEngine(self):
         return Engine

Modified: Zope3/trunk/src/zope/app/pagetemplate/tests/test_boundpagetemplate.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/tests/test_boundpagetemplate.py	2004-06-25 15:45:44 UTC (rev 25983)
+++ Zope3/trunk/src/zope/app/pagetemplate/tests/test_boundpagetemplate.py	2004-06-25 16:26:30 UTC (rev 25984)
@@ -23,11 +23,9 @@
 
         from zope.app.pagetemplate.tests.sample import C
 
-        self.assertRaises(AttributeError, setattr, C.index, 'foo', 1)
-        self.assertRaises(AttributeError, setattr, C().index, 'foo', 1)
-
         C.index.im_func.foo = 1
-        self.assertEqual(C.index.foo, 1)
+        self.assertEqual(C.index.macros, C.index.im_func.macros)
+        self.assertEqual(C.index.filename, C.index.im_func.filename)
 
 
 

Modified: Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py
===================================================================
--- Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py	2004-06-25 15:45:44 UTC (rev 25983)
+++ Zope3/trunk/src/zope/app/pagetemplate/viewpagetemplatefile.py	2004-06-25 16:26:30 UTC (rev 25984)
@@ -49,7 +49,7 @@
         return self.pt_render(namespace, showtal=debug_flags.showTAL,
                               sourceAnnotations=debug_flags.sourceAnnotations)
 
-    def __get__(self, instance, type=None):
+    def __get__(self, instance, type):
         return BoundPageTemplate(self, instance)
 
 class ViewMapper:
@@ -66,14 +66,19 @@
         object.__setattr__(self, 'im_func', pt)
         object.__setattr__(self, 'im_self', ob)
 
-    def __call__(self, **kw):
-        return self.im_func(self.im_self, **kw)
+    macros = property(lambda self: self.im_func.macros)
+    filename = property(lambda self: self.im_func.filename)
 
-    def __getattr__(self, name):
-        return getattr(self.im_func, name)
+    def __call__(self, *args, **kw):
+        if self.im_self is None:
+            im_self, args = args[0], args[1:]
+        else:
+            im_self = self.im_self
+        return self.im_func(im_self, *args, **kw)
 
     def __setattr__(self, name, v):
         raise AttributeError("Can't set attribute", name)
 
     def __repr__(self):
         return "<BoundPageTemplateFile of %r>" % self.im_self
+



More information about the Zope3-Checkins mailing list