[z3-checkins] r23625 - in z3/Five/branch/Five-1.2: . browser/tests
tests/testing
alecm at codespeak.net
alecm at codespeak.net
Thu Feb 23 18:50:28 CET 2006
Author: alecm
Date: Thu Feb 23 18:49:25 2006
New Revision: 23625
Modified:
z3/Five/branch/Five-1.2/browser/tests/test_traversable.py
z3/Five/branch/Five-1.2/tests/testing/fancycontent.py
z3/Five/branch/Five-1.2/traversable.py
Log:
Clarify the Unit test for the __bobo_traverse__ order issue.
Modified: z3/Five/branch/Five-1.2/browser/tests/test_traversable.py
==============================================================================
--- z3/Five/branch/Five-1.2/browser/tests/test_traversable.py (original)
+++ z3/Five/branch/Five-1.2/browser/tests/test_traversable.py Thu Feb 23 18:49:25 2006
@@ -101,10 +101,27 @@
HTTP/1.1 200 OK
...
Fancy, fancy
-
- Without five traversable, if there had been an attrubute something-else,
- the __bobo_traverse__ method would have still been used instead of the
- atribute, let's make sure we preserve that behavior.
+
+ Five's traversable monkeypatches the __bobo_traverse__ method to do view
+ lookup and then delegates back to the original __bobo_traverse__ or direct
+ attribute/item lookup to do normal lookup. In the Zope 2 ZPublisher, an
+ object with a __bobo_traverse__ will not do attribute lookup unless the
+ __bobo_traverse__ method itself does it (i.e. the __bobo_traverse__ is the
+ only element used for traversal lookup). Let's demonstrate:
+
+ >>> from Products.Five.tests.testing.fancycontent import manage_addNonTraversableFancyContent
+ >>> info = manage_addNonTraversableFancyContent(self.folder, 'fancy_zope2', '')
+ >>> self.folder.fancy_zope2.an_attribute = 'This is an attribute'
+ >>> print http(r'''
+ ... GET /test_folder_1_/fancy_zope2/an_attribute HTTP/1.1
+ ... ''')
+ HTTP/1.1 200 OK
+ ...
+ an_attribute
+
+ Without a __bobo_traverse__ method this would have returned the attribute
+ value 'This is an attribute'. Let's make sure the same thing happens for
+ an object that has been marked traversable by Five:
>>> self.folder.fancy.an_attribute = 'This is an attribute'
>>> print http(r'''
Modified: z3/Five/branch/Five-1.2/tests/testing/fancycontent.py
==============================================================================
--- z3/Five/branch/Five-1.2/tests/testing/fancycontent.py (original)
+++ z3/Five/branch/Five-1.2/tests/testing/fancycontent.py Thu Feb 23 18:49:25 2006
@@ -57,9 +57,32 @@
def get_size(self):
return 43
+# A copy of the above class used to demonstrate some baseline behavior
+class NonTraversableFancyContent(SimpleItem):
+ """A class that already comes with its own __bobo_traverse__ handler.
+ Quite fancy indeed.
+
+ It also comes with its own get_size method.
+ """
+ implements(IFancyContent)
+
+ meta_type = "Fancy Content"
+ security = ClassSecurityInfo()
+
+ def __bobo_traverse__(self, REQUEST, name):
+ return FancyAttribute(name).__of__(self)
+
+ def get_size(self):
+ return 43
+
InitializeClass(FancyContent)
def manage_addFancyContent(self, id, REQUEST=None):
"""Add the fancy fancy content."""
id = self._setObject(id, FancyContent(id))
return ''
+
+def manage_addNonTraversableFancyContent(self, id, REQUEST=None):
+ """Add the fancy fancy content."""
+ id = self._setObject(id, NonTraversableFancyContent(id))
+ return ''
Modified: z3/Five/branch/Five-1.2/traversable.py
==============================================================================
--- z3/Five/branch/Five-1.2/traversable.py (original)
+++ z3/Five/branch/Five-1.2/traversable.py Thu Feb 23 18:49:25 2006
@@ -85,10 +85,10 @@
return self.__fallback_traverse__(REQUEST, name)
except NotImplementedError:
pass
- # This should at least make a half hearted attempt to care for
+ # TODO: This should at least make an attempt to deal with
# potential WebDAV issues, in particular we should not perform
- # acquisition for webdav requests, and should return a NullResource
- # when appropriate.
+ # acquisition for webdav requests. See BaseRequest.traverse for
+ # details.
try:
return getattr(self, name)
except AttributeError:
More information about the z3-checkins
mailing list