[z3-checkins] r5845 - in z3/Five/branch/dc-experiments: . tests

dreamcatcher at codespeak.net dreamcatcher at codespeak.net
Mon Aug 2 19:53:23 MEST 2004


Author: dreamcatcher
Date: Mon Aug  2 19:53:22 2004
New Revision: 5845

Modified:
   z3/Five/branch/dc-experiments/fiveconfigure.py
   z3/Five/branch/dc-experiments/tests/test_five.py
Log:
Simplify a bit. Seems like __browser_default__ has precedence over index_html.

Modified: z3/Five/branch/dc-experiments/fiveconfigure.py
==============================================================================
--- z3/Five/branch/dc-experiments/fiveconfigure.py	(original)
+++ z3/Five/branch/dc-experiments/fiveconfigure.py	Mon Aug  2 19:53:22 2004
@@ -117,6 +117,10 @@
         args = (class_,)
         )
 
+def isFiveMethod(m):
+    marker = '__five_method__'
+    return getattr(m, marker, None)
+
 def classViewable(class_):
     # If a class already has this attribute, it means it is either a
     # subclass of api.Viewable or was already processed with this
@@ -125,11 +129,10 @@
     # a base class. In this case, we suppose that the class probably
     # didn't bother with the base classes attribute anyway.
     if (hasattr(class_, '__five_viewable__') and
-        hasattr(class_, '__dict__') and
-        (not class_.__dict__.has_key('__browser_default__') and
-         not class_.__dict__.has_key('__call__') and
-         not class_.__dict__.has_key('index_html'))):
-        return
+        hasattr(class_, '__dict__')):
+        if (hasattr(class_, '__browser_default__') and
+            isFiveMethod(class_.__browser_default__)):
+            return
 
     if not hasattr(class_, '__dict__'):
         # XXX Should raise an error maybe?
@@ -144,27 +147,19 @@
         setattr(class_, "__fallback_default__",
                 Viewable.__fallback_default__)
 
-    if class_.__dict__.has_key('index_html'):
-        # if there's an existing index_html already, use that
-        # as the fallback
-        setattr(class_, "fallback_index_html__",
-                class_.index_html)
-    else:
-        setattr(class_, "fallback_index_html__",
-                Viewable.fallback_index_html__)
-
-    if class_.__dict__.has_key('__call__'):
-        # if there's an existing __call__ already, use that
-        # as the fallback
-        setattr(class_, "fallback_call__",
-                class_.__call__)
-    else:
-        setattr(class_, "fallback_call__",
-                Viewable.fallback_call__)
+    if hasattr(class_, '__call__'):
+        # Only touch __call__ if the class is already callable.
+        if class_.__dict__.has_key('__call__'):
+            # if there's an existing __call__ already, use that
+            # as the fallback
+            setattr(class_, "fallback_call__",
+                    class_.__call__)
+        else:
+            setattr(class_, "fallback_call__",
+                    Viewable.fallback_call__)
+        setattr(class_, '__call__', Viewable.__call__)
 
 
     setattr(class_, '__browser_default__', Viewable.__browser_default__)
-    setattr(class_, '__call__', Viewable.__call__)
-    setattr(class_, 'index_html', Viewable.index_html)
     setattr(class_, '__five_viewable__', True)
 

Modified: z3/Five/branch/dc-experiments/tests/test_five.py
==============================================================================
--- z3/Five/branch/dc-experiments/tests/test_five.py	(original)
+++ z3/Five/branch/dc-experiments/tests/test_five.py	Mon Aug  2 19:53:22 2004
@@ -225,11 +225,6 @@
         view = self.folder.unrestrictedTraverse('testcall')
         self.assertEquals("Default __call__ called", view())
 
-    def test_existing_index(self):
-        view = self.folder.unrestrictedTraverse('testindex')
-        self.assertEquals("Default index_html called", view())
-
-
 class PublishTestCase(Functional, ZopeTestCase.ZopeTestCase):
     """Test a few publishing features"""
 


More information about the z3-checkins mailing list