[Zope-Checkins] SVN: Products.Five/branches/1.4/ Backported the traversal order changes from zope 2.10

Alec Mitchell apm13 at columbia.edu
Thu Jul 13 19:48:01 EDT 2006


Log message for revision 69121:
  Backported the traversal order changes from zope 2.10
  

Changed:
  U   Products.Five/branches/1.4/CHANGES.txt
  U   Products.Five/branches/1.4/browser/tests/test_traversable.py
  U   Products.Five/branches/1.4/traversable.py

-=-
Modified: Products.Five/branches/1.4/CHANGES.txt
===================================================================
--- Products.Five/branches/1.4/CHANGES.txt	2006-07-13 23:25:08 UTC (rev 69120)
+++ Products.Five/branches/1.4/CHANGES.txt	2006-07-13 23:48:00 UTC (rev 69121)
@@ -5,6 +5,9 @@
 Five 1.4.1 (unreleased)
 =======================
 
+* Backported the new traversal lookup order from Zope 2.10 (attribute, adapter,
+  acquired attribute).
+
 * Enabled the viewlet related directives by default.
 
 * Added acquisition wrappers to viewlets before updating or rendering.

Modified: Products.Five/branches/1.4/browser/tests/test_traversable.py
===================================================================
--- Products.Five/branches/1.4/browser/tests/test_traversable.py	2006-07-13 23:25:08 UTC (rev 69120)
+++ Products.Five/branches/1.4/browser/tests/test_traversable.py	2006-07-13 23:48:00 UTC (rev 69121)
@@ -216,6 +216,13 @@
       ...       attribute="eagle"
       ...       permission="zope2.Public"
       ...       />
+      ...   <browser:page
+      ...       name="mouse"
+      ...       for="OFS.interfaces.IObjectManager"
+      ...       class="Products.Five.browser.tests.pages.SimpleView"
+      ...       attribute="mouse"
+      ...       permission="zope2.Public"
+      ...       />
       ...   <five:traversable class="OFS.Application.Application"/>
       ... </configure>'''
       >>> import Products.Five
@@ -273,6 +280,27 @@
       ...
       The eagle has landed
 
+    However, acquired attributes *should* be shadowed. See discussion on
+    http://codespeak.net/pipermail/z3-five/2006q2/001474.html
+
+      >>> manage_addIndexSimpleContent(self.folder, 'mouse', 'Mouse')
+
+      >>> print http(r'''
+      ... GET /test_folder_1_/mouse HTTP/1.1
+      ...
+      ... ''')
+      HTTP/1.1 200 OK
+      ...
+      Default index_html called
+
+      >>> print http(r'''
+      ... GET /test_folder_1_/ftf/mouse HTTP/1.1
+      ...
+      ... ''')
+      HTTP/1.1 200 OK
+      ...
+      The mouse has been eaten by the eagle
+
     Clean up:
 
       >>> from zope.app.testing.placelesssetup import tearDown

Modified: Products.Five/branches/1.4/traversable.py
===================================================================
--- Products.Five/branches/1.4/traversable.py	2006-07-13 23:25:08 UTC (rev 69120)
+++ Products.Five/branches/1.4/traversable.py	2006-07-13 23:48:00 UTC (rev 69121)
@@ -26,10 +26,13 @@
 from zope.app.publication.browser import setDefaultSkin
 from zope.app.interface import queryType
 
+from Acquisition import aq_base
 import Products.Five.security
 from zExceptions import NotFound
 from ZPublisher import xmlrpc
 
+_marker = object()
+
 class FakeRequest(dict):
     implements(IBrowserRequest)
 
@@ -72,12 +75,12 @@
                 except AttributeError:
                     pass
         else:
-            try:
+            # See if the object itself has the attribute, try acquisition
+            # later
+            if getattr(aq_base(self), name, _marker) is not _marker:
                 return getattr(self, name)
-            except AttributeError:
-                pass
-
             try:
+                # item access should never acquire
                 return self[name]
             except (KeyError, IndexError, TypeError, AttributeError):
                 pass
@@ -112,7 +115,8 @@
                 AttributeError, KeyError, NotFound):
             pass
 
-        raise AttributeError(name)
+        # Fallback on acquisition, let it raise an AttributeError if it must
+        return getattr(self, name)
 
     __bobo_traverse__.__five_method__ = True
 



More information about the Zope-Checkins mailing list